mirror of
https://github.com/discountry/ritmex-bot.git
synced 2026-09-11 09:18:08 +00:00
commit
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
- [Async Fetch Ohlcv Multiple Symbols Continuously](./examples/py/)
|
||||
|
||||
|
||||
```python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import sys
|
||||
from asyncio import run, gather
|
||||
|
||||
import ccxt.async_support as ccxt # noqa: E402
|
||||
|
||||
print('CCXT Version:', ccxt.__version__)
|
||||
|
||||
|
||||
async def fetch_ohlcv(exchange, symbol, timeframe, limit):
|
||||
since = None
|
||||
while True:
|
||||
try:
|
||||
ohlcv = await exchange.fetch_ohlcv(symbol, timeframe, since, limit)
|
||||
if len(ohlcv):
|
||||
first_candle = ohlcv[0]
|
||||
datetime = exchange.iso8601(first_candle[0])
|
||||
print(datetime, exchange.id, symbol, first_candle[1:])
|
||||
except Exception as e:
|
||||
print(type(e).__name__, str(e))
|
||||
|
||||
|
||||
async def main():
|
||||
exchange = ccxt.binance()
|
||||
timeframe = '1m'
|
||||
limit = 1
|
||||
symbols = [ 'BTC/USDT', 'ETH/USDT' ]
|
||||
loops = [fetch_ohlcv(exchange, symbol, timeframe, limit) for symbol in symbols]
|
||||
await gather(*loops)
|
||||
await exchange.close()
|
||||
|
||||
|
||||
run(main())
|
||||
|
||||
```
|
||||
Reference in New Issue
Block a user