From e25bd176e55f2b5575179559d2a113feabbcdee4 Mon Sep 17 00:00:00 2001 From: Igor Kroitor Date: Sat, 4 Nov 2017 21:21:22 +0300 Subject: [PATCH] added tox flake8 cd .. and python bitfinex example --- examples/py/fetch-bitfinex-ohlcv-history.py | 61 +++++++++++++++++++++ python/tox.ini | 1 + setup.cfg | 17 ++++++ 3 files changed, 79 insertions(+) create mode 100644 examples/py/fetch-bitfinex-ohlcv-history.py create mode 100644 setup.cfg diff --git a/examples/py/fetch-bitfinex-ohlcv-history.py b/examples/py/fetch-bitfinex-ohlcv-history.py new file mode 100644 index 0000000000000..2a39346ea4c3f --- /dev/null +++ b/examples/py/fetch-bitfinex-ohlcv-history.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- + +import os +import sys +import time + +# ----------------------------------------------------------------------------- + +root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +sys.path.append(root + '/python') + +# ----------------------------------------------------------------------------- + +import ccxt # noqa: E402 + +# ----------------------------------------------------------------------------- +# common constants + +msec = 1000 +minute = 60 * msec +hold = 30 + +# ----------------------------------------------------------------------------- + +exchange = ccxt.bitfinex({ + 'rateLimit': 3000, + 'enableRateLimit': True, + # 'verbose': True, +}) + +# ----------------------------------------------------------------------------- + +from_datetime = '2017-01-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') + first = ohlcvs[0][0] + last = ohlcvs[-1][0] + print('First candle epoch', first, exchange.iso8601(first)) + print('Last candle epoch', last, exchange.iso8601(last)) + from_timestamp += len(ohlcvs) * minute + 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) diff --git a/python/tox.ini b/python/tox.ini index 9ae87cab6fac0..fe6e521a69c31 100644 --- a/python/tox.ini +++ b/python/tox.ini @@ -11,6 +11,7 @@ commands = [testenv:qa] basepython = python3 +changedir=.. commands = flake8 deps = .[qa] diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000000000..7966a764194f8 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,17 @@ +[flake8] +ignore = E501 +exclude = + .ropeproject, + .tox, + .eggs, + # No need to traverse our git directory + .git, + # There's no value in checking cache directories + __pycache__, + # Other special cases + node_modules, + .nyc_output, + build, + tmp, + # No need to check the basecode + ccxt.py