mirror of
https://github.com/discountry/ritmex-bot.git
synced 2026-09-10 00:38:07 +00:00
49 lines
1.5 KiB
Markdown
49 lines
1.5 KiB
Markdown
- [Async Binance Fetch Ticker Continuously](./examples/py/)
|
|
|
|
|
|
```python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import asyncio
|
|
import os
|
|
import sys
|
|
|
|
|
|
import ccxt.async_support as ccxt # noqa: E402
|
|
|
|
|
|
async def main(symbol):
|
|
# you can set enableRateLimit = True to enable the built-in rate limiter
|
|
# this way you request rate will never hit the limit of an exchange
|
|
# the library will throttle your requests to avoid that
|
|
|
|
exchange = ccxt.binance()
|
|
while True:
|
|
print('--------------------------------------------------------------')
|
|
print(exchange.iso8601(exchange.milliseconds()), 'fetching', symbol, 'ticker from', exchange.name)
|
|
# this can be any call instead of fetch_ticker, really
|
|
try:
|
|
ticker = await exchange.fetch_ticker(symbol)
|
|
print(exchange.iso8601(exchange.milliseconds()), 'fetched', symbol, 'ticker from', exchange.name)
|
|
print(ticker)
|
|
except ccxt.RequestTimeout as e:
|
|
print('[' + type(e).__name__ + ']')
|
|
print(str(e)[0:200])
|
|
# will retry
|
|
except ccxt.DDoSProtection as e:
|
|
print('[' + type(e).__name__ + ']')
|
|
print(str(e.args)[0:200])
|
|
# will retry
|
|
except ccxt.ExchangeNotAvailable as e:
|
|
print('[' + type(e).__name__ + ']')
|
|
print(str(e.args)[0:200])
|
|
# will retry
|
|
except ccxt.ExchangeError as e:
|
|
print('[' + type(e).__name__ + ']')
|
|
print(str(e)[0:200])
|
|
break # won't retry
|
|
|
|
|
|
asyncio.run(main('BTC/USDT'))
|
|
|
|
``` |