mirror of
https://github.com/discountry/ritmex-bot.git
synced 2026-09-09 08:18:07 +00:00
39 lines
966 B
Markdown
39 lines
966 B
Markdown
- [Fetch Gdax Ohlcv Sequentially](./examples/py/)
|
|
|
|
|
|
```python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import os
|
|
import sys
|
|
import time
|
|
|
|
|
|
import ccxt # noqa: E402
|
|
# common constants
|
|
|
|
msec = 1000
|
|
minute = 60 * msec
|
|
hold = 30
|
|
exchange = ccxt.gdax()
|
|
from_datetime = '2017-09-01 00:00:00'
|
|
from_timestamp = exchange.parse8601(from_datetime)
|
|
now = exchange.milliseconds()
|
|
data = []
|
|
|
|
while from_timestamp < now:
|
|
|
|
try:
|
|
|
|
print(exchange.milliseconds(), 'Fetching candles starting from', exchange.iso8601(from_timestamp))
|
|
ohlcvs = exchange.fetch_ohlcv('BTC/USD', '1m', from_timestamp)
|
|
print(exchange.milliseconds(), 'Fetched', len(ohlcvs), 'candles')
|
|
from_timestamp = ohlcvs[-1][0]
|
|
data += ohlcvs
|
|
|
|
except (ccxt.ExchangeError, ccxt.AuthenticationError, ccxt.ExchangeNotAvailable, ccxt.RequestTimeout) as error:
|
|
|
|
print('Got an error', type(error).__name__, error.args, ', retrying in', hold, 'seconds...')
|
|
time.sleep(hold)
|
|
|
|
``` |