24 lines
617 B
Python
24 lines
617 B
Python
# No copyright
|
|
import logging
|
|
|
|
class Pair:
|
|
def __init__(self, pb, names):
|
|
self.names = names
|
|
self._pb = pb
|
|
|
|
async def update(self):
|
|
ticker = (await self._get("ticker"))["data"]
|
|
self.ticker = Ticker(ticker)
|
|
|
|
async def _get(self, suffix):
|
|
res = await self._pb.get(f"https://public.bitbank.cc/{self.names[0]}_{self.names[1]}/{suffix}")
|
|
json = await res.json()
|
|
if "success" not in json or 1 != json["success"]:
|
|
code = json["data"]["code"]
|
|
raise Exception(f"API error: {code}")
|
|
return json
|
|
|
|
class Ticker:
|
|
def __init__(self, json):
|
|
self.price = float(json["last"])
|