Skip to content

Commit e25bd17

Browse files
committed
added tox flake8 cd .. and python bitfinex example
1 parent aa201fa commit e25bd17

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import os
4+
import sys
5+
import time
6+
7+
# -----------------------------------------------------------------------------
8+
9+
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
10+
sys.path.append(root + '/python')
11+
12+
# -----------------------------------------------------------------------------
13+
14+
import ccxt # noqa: E402
15+
16+
# -----------------------------------------------------------------------------
17+
# common constants
18+
19+
msec = 1000
20+
minute = 60 * msec
21+
hold = 30
22+
23+
# -----------------------------------------------------------------------------
24+
25+
exchange = ccxt.bitfinex({
26+
'rateLimit': 3000,
27+
'enableRateLimit': True,
28+
# 'verbose': True,
29+
})
30+
31+
# -----------------------------------------------------------------------------
32+
33+
from_datetime = '2017-01-01 00:00:00'
34+
from_timestamp = exchange.parse8601(from_datetime)
35+
36+
# -----------------------------------------------------------------------------
37+
38+
now = exchange.milliseconds()
39+
40+
# -----------------------------------------------------------------------------
41+
42+
data = []
43+
44+
while from_timestamp < now:
45+
46+
try:
47+
48+
print(exchange.milliseconds(), 'Fetching candles starting from', exchange.iso8601(from_timestamp))
49+
ohlcvs = exchange.fetch_ohlcv('BTC/USD', '1m', from_timestamp)
50+
print(exchange.milliseconds(), 'Fetched', len(ohlcvs), 'candles')
51+
first = ohlcvs[0][0]
52+
last = ohlcvs[-1][0]
53+
print('First candle epoch', first, exchange.iso8601(first))
54+
print('Last candle epoch', last, exchange.iso8601(last))
55+
from_timestamp += len(ohlcvs) * minute
56+
data += ohlcvs
57+
58+
except (ccxt.ExchangeError, ccxt.AuthenticationError, ccxt.ExchangeNotAvailable, ccxt.RequestTimeout) as error:
59+
60+
print('Got an error', type(error).__name__, error.args, ', retrying in', hold, 'seconds...')
61+
time.sleep(hold)

python/tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ commands =
1111

1212
[testenv:qa]
1313
basepython = python3
14+
changedir=..
1415
commands = flake8
1516
deps = .[qa]
1617

setup.cfg

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[flake8]
2+
ignore = E501
3+
exclude =
4+
.ropeproject,
5+
.tox,
6+
.eggs,
7+
# No need to traverse our git directory
8+
.git,
9+
# There's no value in checking cache directories
10+
__pycache__,
11+
# Other special cases
12+
node_modules,
13+
.nyc_output,
14+
build,
15+
tmp,
16+
# No need to check the basecode
17+
ccxt.py

0 commit comments

Comments
 (0)