-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from fatchan/main
Add kucoin rates module
- Loading branch information
Showing
3 changed files
with
36 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import json | ||
from decimal import Decimal | ||
|
||
from shkeeper import requests | ||
|
||
from shkeeper.modules.classes.rate_source import RateSource | ||
|
||
|
||
class KuCoin(RateSource): | ||
name = "kucoin" | ||
|
||
def get_rate(self, fiat, crypto): | ||
if crypto in self.USDT_CRYPTOS: | ||
crypto = "USDT" | ||
|
||
if crypto in self.USDC_CRYPTOS: | ||
crypto = "USDC" | ||
|
||
# https://www.kucoin.com/docs/beginners/introduction | ||
url = f"https://api.kucoin.com/api/v1/prices?base={fiat}¤cies={crypto}" | ||
answer = requests.get(url) | ||
if answer.status_code == requests.codes.ok: | ||
data = json.loads(answer.text) | ||
if data.get("code") == "200000": | ||
#data will be empty dict if symbol doesnt exist even though code is 200000 | ||
price = data.get("data", {}).get(crypto) | ||
if price is not None: | ||
return Decimal(price) | ||
|
||
raise Exception(f"Can't get rate for {crypto} in {fiat}") |