Implement types.
This commit is contained in:
parent
4c8b739c0c
commit
02ab5212b9
4 changed files with 14 additions and 8 deletions
|
@ -46,7 +46,7 @@ def cmd_fetch(args):
|
|||
source = sources.by_id[args.source]()
|
||||
output = outputs.by_type[args.output]()
|
||||
|
||||
prices = source.fetch(args.pair, args.start, args.end)
|
||||
prices = source.fetch(args.pair, args.type, args.start, args.end)
|
||||
|
||||
if args.renamebase or args.renamequote:
|
||||
prices = [
|
||||
|
|
|
@ -38,7 +38,7 @@ class CoinDesk:
|
|||
symbols = sorted([item["currency"] for item in data])
|
||||
return symbols
|
||||
|
||||
def fetch(self, pair, start, end):
|
||||
def fetch(self, pair, type, start, end):
|
||||
base, quote = pair.split("/")
|
||||
if base not in self.bases():
|
||||
exit(f"Invalid base {base}")
|
||||
|
|
|
@ -37,7 +37,7 @@ class CoinMarketCap:
|
|||
def quotes():
|
||||
return []
|
||||
|
||||
def fetch(self, pair, start, end):
|
||||
def fetch(self, pair, type, start, end):
|
||||
base, quote = pair.split("/")
|
||||
|
||||
url = "https://web-api.coinmarketcap.com/v1/cryptocurrency/ohlcv/historical"
|
||||
|
@ -56,9 +56,15 @@ class CoinMarketCap:
|
|||
prices = []
|
||||
for item in data["data"]["quotes"]:
|
||||
d = item["time_open"][0:10]
|
||||
high = Decimal(str(item["quote"][quote]["high"]))
|
||||
low = Decimal(str(item["quote"][quote]["low"]))
|
||||
mid = sum([high, low]) / 2
|
||||
prices.append(Price(base, quote, d, mid))
|
||||
amount = self._amount(item["quote"][quote], type)
|
||||
prices.append(Price(base, quote, d, amount))
|
||||
|
||||
return prices
|
||||
|
||||
def _amount(self, data, type):
|
||||
if type == "mid":
|
||||
high = Decimal(str(data["high"]))
|
||||
low = Decimal(str(data["low"]))
|
||||
return sum([high, low]) / 2
|
||||
else:
|
||||
return Decimal(str(data[type]))
|
||||
|
|
|
@ -65,7 +65,7 @@ class ECB:
|
|||
"ZAR",
|
||||
]
|
||||
|
||||
def fetch(self, pair, start, end):
|
||||
def fetch(self, pair, type, start, end):
|
||||
base, quote = pair.split("/")
|
||||
if base not in self.bases():
|
||||
exit(f"Invalid base {base}")
|
||||
|
|
Loading…
Add table
Reference in a new issue