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]()
|
source = sources.by_id[args.source]()
|
||||||
output = outputs.by_type[args.output]()
|
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:
|
if args.renamebase or args.renamequote:
|
||||||
prices = [
|
prices = [
|
||||||
|
|
|
@ -38,7 +38,7 @@ class CoinDesk:
|
||||||
symbols = sorted([item["currency"] for item in data])
|
symbols = sorted([item["currency"] for item in data])
|
||||||
return symbols
|
return symbols
|
||||||
|
|
||||||
def fetch(self, pair, start, end):
|
def fetch(self, pair, type, start, end):
|
||||||
base, quote = pair.split("/")
|
base, quote = pair.split("/")
|
||||||
if base not in self.bases():
|
if base not in self.bases():
|
||||||
exit(f"Invalid base {base}")
|
exit(f"Invalid base {base}")
|
||||||
|
|
|
@ -37,7 +37,7 @@ class CoinMarketCap:
|
||||||
def quotes():
|
def quotes():
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def fetch(self, pair, start, end):
|
def fetch(self, pair, type, start, end):
|
||||||
base, quote = pair.split("/")
|
base, quote = pair.split("/")
|
||||||
|
|
||||||
url = "https://web-api.coinmarketcap.com/v1/cryptocurrency/ohlcv/historical"
|
url = "https://web-api.coinmarketcap.com/v1/cryptocurrency/ohlcv/historical"
|
||||||
|
@ -56,9 +56,15 @@ class CoinMarketCap:
|
||||||
prices = []
|
prices = []
|
||||||
for item in data["data"]["quotes"]:
|
for item in data["data"]["quotes"]:
|
||||||
d = item["time_open"][0:10]
|
d = item["time_open"][0:10]
|
||||||
high = Decimal(str(item["quote"][quote]["high"]))
|
amount = self._amount(item["quote"][quote], type)
|
||||||
low = Decimal(str(item["quote"][quote]["low"]))
|
prices.append(Price(base, quote, d, amount))
|
||||||
mid = sum([high, low]) / 2
|
|
||||||
prices.append(Price(base, quote, d, mid))
|
|
||||||
|
|
||||||
return prices
|
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",
|
"ZAR",
|
||||||
]
|
]
|
||||||
|
|
||||||
def fetch(self, pair, start, end):
|
def fetch(self, pair, type, start, end):
|
||||||
base, quote = pair.split("/")
|
base, quote = pair.split("/")
|
||||||
if base not in self.bases():
|
if base not in self.bases():
|
||||||
exit(f"Invalid base {base}")
|
exit(f"Invalid base {base}")
|
||||||
|
|
Loading…
Add table
Reference in a new issue