Skip to content

Commit

Permalink
Fix coingecko get_rates
Browse files Browse the repository at this point in the history
  • Loading branch information
dalijolijo authored and dalijolijo committed Aug 5, 2019
1 parent 427bae9 commit f5c966a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 175 deletions.
2 changes: 1 addition & 1 deletion contrib/make_packages
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ test -n "$CONTRIB" -a -d "$CONTRIB" || exit
rm "$CONTRIB"/../packages/ -r

#Install pure python modules in electrum directory
python3 -m pip install -r "$CONTRIB"/deterministic-build/requirements.txt -t "$CONTRIB"/../packages
python3.6 -m pip install -r "$CONTRIB"/deterministic-build/requirements.txt -t "$CONTRIB"/../packages

170 changes: 1 addition & 169 deletions electrum/currencies.json
Original file line number Diff line number Diff line change
@@ -1,173 +1,4 @@
{
"BitcoinAverage": [
"AED",
"AFN",
"ALL",
"AMD",
"ANG",
"AOA",
"ARS",
"AUD",
"AWG",
"AZN",
"BAM",
"BBD",
"BDT",
"BGN",
"BHD",
"BIF",
"BMD",
"BND",
"BOB",
"BRL",
"BSD",
"BTN",
"BWP",
"BYN",
"BZD",
"CAD",
"CDF",
"CHF",
"CLF",
"CLP",
"CNH",
"CNY",
"COP",
"CRC",
"CUC",
"CUP",
"CVE",
"CZK",
"DJF",
"DKK",
"DOP",
"DZD",
"EGP",
"ERN",
"ETB",
"EUR",
"FJD",
"FKP",
"GBP",
"GEL",
"GGP",
"GHS",
"GIP",
"GMD",
"GNF",
"GTQ",
"GYD",
"HKD",
"HNL",
"HRK",
"HTG",
"HUF",
"IDR",
"ILS",
"IMP",
"INR",
"IQD",
"IRR",
"ISK",
"JEP",
"JMD",
"JOD",
"JPY",
"KES",
"KGS",
"KHR",
"KMF",
"KPW",
"KRW",
"KWD",
"KYD",
"KZT",
"LAK",
"LBP",
"LKR",
"LRD",
"LSL",
"LYD",
"MAD",
"MDL",
"MGA",
"MKD",
"MMK",
"MNT",
"MOP",
"MRO",
"MUR",
"MVR",
"MWK",
"MXN",
"MYR",
"MZN",
"NAD",
"NGN",
"NIO",
"NOK",
"NPR",
"NZD",
"OMR",
"PAB",
"PEN",
"PGK",
"PHP",
"PKR",
"PLN",
"PYG",
"QAR",
"RON",
"RSD",
"RUB",
"RWF",
"SAR",
"SBD",
"SCR",
"SDG",
"SEK",
"SGD",
"SHP",
"SLL",
"SOS",
"SRD",
"SSP",
"STD",
"SVC",
"SYP",
"SZL",
"THB",
"TJS",
"TMT",
"TND",
"TOP",
"TRY",
"TTD",
"TWD",
"TZS",
"UAH",
"UGX",
"USD",
"UYU",
"UZS",
"VES",
"VND",
"VUV",
"WST",
"XAF",
"XAG",
"XAU",
"XCD",
"XDR",
"XOF",
"XPD",
"XPF",
"XPT",
"YER",
"ZAR",
"ZMW",
"ZWL"
],
"CoinGecko": [
"AED",
"ARS",
Expand Down Expand Up @@ -214,6 +45,7 @@
"THB",
"TRY",
"TWD",
"UAH",
"USD",
"VEF",
"VND",
Expand Down
16 changes: 11 additions & 5 deletions electrum/exchange_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

DEFAULT_ENABLED = True
DEFAULT_CURRENCY = "USD"
DEFAULT_EXCHANGE = "CoinMarketCap" # default exchange should ideally provide historical rates
DEFAULT_EXCHANGE = "CoinGecko" # default exchange should ideally provide historical rates


# See https://en.wikipedia.org/wiki/ISO_4217
Expand Down Expand Up @@ -302,17 +302,23 @@ async def request_history(self, ccy):
class CoinGecko(ExchangeBase):

async def get_rates(self, ccy):
json = await self.get_json('api.coingecko.com', '/api/v3/exchange_rates')
return dict([(ccy.upper(), Decimal(d['value']))
for ccy, d in json['rates'].items()])
#json = await self.get_json('api.coingecko.com', '/api/v3/exchange_rates')
#return dict([(ccy.upper(), Decimal(d['value']))
# for ccy, d in json['rates'].items()])
ccys = ["BTC", "ETH", "LTC", "BCH", "BNB", "EOS", "XRP", "XLM", "USD", "AED", "ARS", "AUD", "BDT", "BHD", "BMD", "BRL", "CAD", "CHF", "CLP", "CNY", "CZK", "DKK", "EUR", "GBP", "HKD", "HUF", "IDR", "ILS", "INR", "JPY", "KRW", "KWD", "LKR", "MMK", "MXN", "MYR", "NOK", "NZD", "PHP", "PKR", "PLN", "RUB", "SAR", "SEK", "SGD", "THB", "TRY", "TWD", "UAH", "VEF", "VND", "ZAR", "XDR", "XAG", "XAU"]
json = await self.get_json('api.coingecko.com', '/api/v3/simple/price?ids=bitcore&vs_currencies=%s' % ccy)
result = dict.fromkeys(ccys)
if ccy in ccys:
result[ccy] = Decimal(json['bitcore'][ccy.lower()])
return result

def history_ccys(self):
# CoinGecko seems to have historical data for all ccys it supports
return CURRENCIES[self.name()]

async def request_history(self, ccy):
history = await self.get_json('api.coingecko.com',
'/api/v3/coins/bitcore/market_chart?vs_currency=%s&days=max' % ccy)
'/api/v3/coins/bitcoin/market_chart?vs_currency=%s&days=max' % ccy)

return dict([(datetime.utcfromtimestamp(h[0]/1000).strftime('%Y-%m-%d'), h[1])
for h in history['prices']])
Expand Down

0 comments on commit f5c966a

Please sign in to comment.