Skip to content

Commit c227f0d

Browse files
committed
Fixed the cryptotracker plugin
Switch to Binance API: To enhance the reliability and accuracy of cryptocurrency tracking, I have migrated the plugin to use the Binance API. Use of USDT: With the transition to the Binance API, we are kind of forced to use USDT (Tether) as the base trading pair for tracking cryptocurrencies. JSON Structure Update: As a result of switching to the Binance API, the JSON data structure received from the API has undergone some modifications. These changes have been incorporated into the code.
1 parent 09db351 commit c227f0d

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

jarviscli/plugins/cryptotracker.py

+21-16
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55

66
# List of default crypto pairs
77
FAVORITES = [
8-
'BTC/USD',
9-
'ETH/USD',
10-
'LTC/USD',
11-
'XRP/USD',
12-
'ADA/USD'
8+
'BTC/USDT',
9+
'ETH/USDT',
10+
'LTC/USDT',
11+
'XRP/USDT',
12+
'ADA/USDT',
13+
'XMR/USDT'
1314
]
1415

1516

@@ -24,15 +25,15 @@ def print_in_color(change):
2425
The price change.
2526
"""
2627
if float(change) < 0:
27-
return Fore.RED + str(change) + Fore.RESET
28+
return Fore.RED + str(change) + '%' + Fore.RESET
2829
else:
29-
return Fore.GREEN + str(change) + Fore.RESET
30+
return Fore.GREEN + '+' + str(change) + '%' + Fore.RESET
3031

3132

3233
def check_prices(base, target):
3334
""""
3435
It requires the base and target currency symbols,
35-
e.g. [BTC, XRP], to build the URL and print the price
36+
e.g. [btc, usdt], to build the URL and print the price
3637
and the price change.
3738
3839
Parameters
@@ -43,23 +44,27 @@ def check_prices(base, target):
4344
The target currency
4445
"""
4546

46-
# build the api url
47-
url = 'https://api.cryptonator.com/api/ticker/{}-{}'.format(
48-
base.lower(), target.lower())
47+
# build the api request
48+
url = 'https://api.binance.com/api/v3/ticker/24hr'
49+
params = {
50+
"symbol": (base.upper() + target.upper()),
51+
}
4952

5053
try:
5154
response = requests.get(
5255
url, headers={
53-
'User-Agent': 'Jarvis'}).json()
54-
price = response['ticker']['price']
55-
change = response['ticker']['change']
56+
'User-Agent': 'Jarvis'}, params=params).json()
57+
58+
price = response['askPrice']
59+
change = response['priceChangePercent']
5660

5761
# this error occurs if the pair is non-existent
5862
except KeyError:
5963
print(
6064
"{WARNING}Wrong pair {}/{}!{COLOR_RESET} "
6165
"\nFull list of symbols is here: "
62-
"https://coinmarketcap.com/all/views/all/"
66+
"https://api.binance.com/api/v3/ticker/price"
67+
"\nDue to API Changes please use USDT for USD Prices"
6368
"\n".format(
6469
base,
6570
target,
@@ -78,7 +83,7 @@ def main(jarvis, s):
7883
Finds the price and the change of the price, for
7984
a pair of currencies or for the default list of favorite pairs.
8085
-- Example:
81-
cryptotracker BTC/USD
86+
cryptotracker BTC/USDT
8287
"""
8388

8489
# for a specific pair of currencies

0 commit comments

Comments
 (0)