Last active
June 12, 2018 13:43
-
-
Save noda-sin/5dc635045714bde7b8102eb8f0979c03 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
position = retry(lambda: self.private_client | |
.Position.Position_get(filter=json.dumps({"symbol": "XBTUSD"})).result())[0] | |
def retry(func, count=5): | |
err = None | |
for i in range(count): | |
try: | |
ret, res = func() | |
rate_limit = int(res.headers['X-RateLimit-Limit']) | |
rate_remain = int(res.headers['X-RateLimit-Remaining']) | |
if rate_remain < 10: | |
time.sleep(5 * 60 * (1 + rate_limit - rate_remain) / rate_limit) | |
return ret | |
except HTTPError as error: | |
status_code = error.status_code | |
err = error | |
if status_code >= 500: | |
time.sleep(pow(2, i + 1)) | |
continue | |
elif status_code == 400 or \ | |
status_code == 401 or \ | |
status_code == 402 or \ | |
status_code == 403 or \ | |
status_code == 404 or \ | |
status_code == 429: | |
raise FatalError(error) | |
raise err | |
# walletの取得 | |
wallet = retry(lambda: self.private_client.User.User_getWallet(currency="XBt").result()) | |
# Position Close | |
retry(lambda: self.private_client.Order.Order_closePosition(symbol="XBTUSD").result()) | |
# Stop Limit 注文 | |
retry(lambda: self.private_client.Order.Order_amend(origClOrdID=ord_id, | |
orderQty=ord_qty, price=limit, stopPx=stop).result()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment