fix errors
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
# No copyright
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
class Player:
|
||||
@@ -12,7 +13,6 @@ class Player:
|
||||
"pair": f"{pair[0]}_{pair[1]}",
|
||||
"order_ids": orders
|
||||
})
|
||||
self._check(res)
|
||||
|
||||
async def orderMarketSell(self, pair, amount):
|
||||
res = await self._post("user/spot/order", data={
|
||||
@@ -21,7 +21,7 @@ class Player:
|
||||
"side": "sell",
|
||||
"type": "market",
|
||||
})
|
||||
return self._check(res)["data"]["order_id"]
|
||||
return res["data"]["order_id"]
|
||||
|
||||
async def orderMarketBuy(self, pair, amount):
|
||||
res = await self._post("user/spot/order", data={
|
||||
@@ -30,7 +30,7 @@ class Player:
|
||||
"side": "buy",
|
||||
"type": "market",
|
||||
})
|
||||
return self._check(res)["data"]["order_id"]
|
||||
return res["data"]["order_id"]
|
||||
|
||||
async def orderLimitSell(self, pair, amount, price):
|
||||
res = await self._post("user/spot/order", data={
|
||||
@@ -40,7 +40,7 @@ class Player:
|
||||
"side": "sell",
|
||||
"type": "limit",
|
||||
})
|
||||
return self._check(res)["data"]["order_id"]
|
||||
return res["data"]["order_id"]
|
||||
|
||||
async def orderLimitBuy(self, pair, amount, price):
|
||||
res = await self._post("user/spot/order", data={
|
||||
@@ -50,7 +50,7 @@ class Player:
|
||||
"side": "buy",
|
||||
"type": "limit",
|
||||
})
|
||||
return self._check(res)["data"]["order_id"]
|
||||
return res["data"]["order_id"]
|
||||
|
||||
async def update(self):
|
||||
self.assets = {}
|
||||
@@ -65,12 +65,24 @@ class Player:
|
||||
self.orders[order["order_id"]] = Order(order)
|
||||
|
||||
async def _post(self, suffix, data):
|
||||
res = await self._pb.post(f"https://api.bitbank.cc/v1/{suffix}", data=data)
|
||||
return self._check(await res.json())
|
||||
for i in range(10):
|
||||
try:
|
||||
res = await self._pb.post(f"https://api.bitbank.cc/v1/{suffix}", data=data)
|
||||
return self._check(await res.json())
|
||||
except Exception as e:
|
||||
err = e
|
||||
await asyncio.sleep(1)
|
||||
raise Exception(f"API error: {suffix} ({err})")
|
||||
|
||||
async def _get(self, suffix):
|
||||
res = await self._pb.get(f"https://api.bitbank.cc/v1/{suffix}")
|
||||
return self._check(await res.json())
|
||||
for i in range(10):
|
||||
try:
|
||||
res = await self._pb.get(f"https://api.bitbank.cc/v1/{suffix}")
|
||||
return self._check(await res.json())
|
||||
except Exception as e:
|
||||
err = e
|
||||
await asyncio.sleep(1)
|
||||
raise Exception(f"API error: {suffix} ({err})")
|
||||
|
||||
def _check(self, json):
|
||||
if "success" not in json or 1 != json["success"]:
|
||||
|
Reference in New Issue
Block a user