forked from jesse-ai/jesse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_import_candles.py
78 lines (62 loc) · 2.61 KB
/
test_import_candles.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import jesse.helpers as jh
import jesse.modes.import_candles_mode as importer
from tests.data import test_candles_0
test_object_candles = []
for c in test_candles_0:
test_object_candles.append({
'id': jh.generate_unique_id(),
'symbol': 'BTC-USD',
'exchange': 'Sandbox',
'timestamp': c[0],
'open': c[1],
'high': c[2],
'low': c[3],
'close': c[4],
'volume': c[5]
})
smaller_data_set = test_object_candles[0:7].copy()
def test_fill_absent_candles():
assert len(test_object_candles) == 1382
start = 1553817600000
end = 1553817600000 + (1440 - 1) * 60000
fixed_candles = importer._fill_absent_candles(test_object_candles, start, end)
assert len(fixed_candles) == 1440
assert fixed_candles[0]['timestamp'] == start
assert fixed_candles[-1]['timestamp'] == end
def test_fill_absent_candles_beginning_middle_end():
# Should fill if candles in the beginning are absent
candles = smaller_data_set[2:7]
assert len(smaller_data_set) == 7
assert len(candles) == 5
start = smaller_data_set[0]['timestamp']
end = smaller_data_set[-1]['timestamp']
candles = importer._fill_absent_candles(candles, start, end)
assert len(candles) == 7
assert candles[0]['timestamp'] == smaller_data_set[0]['timestamp']
assert candles[-1]['timestamp'] == smaller_data_set[-1]['timestamp']
# Should fill if candles in the middle are absent
candles = smaller_data_set[0:3] + smaller_data_set[5:7]
assert len(candles) == 5
candles = importer._fill_absent_candles(candles, start, end)
assert len(candles) == 7
assert candles[0]['timestamp'] == smaller_data_set[0]['timestamp']
assert candles[-1]['timestamp'] == smaller_data_set[-1]['timestamp']
# Should fill if candles in the ending are absent
candles = smaller_data_set[0:5]
assert len(candles) == 5
candles = importer._fill_absent_candles(candles, start, end)
assert len(candles) == 7
assert candles[0]['timestamp'] == smaller_data_set[0]['timestamp']
assert candles[-1]['timestamp'] == smaller_data_set[-1]['timestamp']
def test_more_than_one_set_of_candles_in_the_middle_are_absent():
candles = [
smaller_data_set[0],
] + smaller_data_set[2:3] + smaller_data_set[5:7]
assert len(smaller_data_set) == 7
assert len(candles) == 4
start = smaller_data_set[0]['timestamp']
end = smaller_data_set[-1]['timestamp']
candles = importer._fill_absent_candles(candles, start, end)
assert len(candles) == 7
assert candles[0]['timestamp'] == start
assert candles[-1]['timestamp'] == end