forked from 51bitquant/howtrader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdownload_data_demo1.py
111 lines (85 loc) · 2.74 KB
/
download_data_demo1.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import sys
from time import sleep
from datetime import datetime, time
from logging import INFO
from howtrader.event import EventEngine
from howtrader.trader.setting import SETTINGS
from howtrader.trader.engine import MainEngine
from howtrader.gateway.binances import BinancesGateway
from howtrader.gateway.binance import BinanceGateway
from howtrader.gateway.binances.binances_gateway import BinancesRestApi
from howtrader.trader.object import Exchange, Interval
from tzlocal import get_localzone
from howtrader.trader.object import HistoryRequest
from howtrader.trader.database import database_manager
from threading import Thread
SETTINGS["log.active"] = True
SETTINGS["log.level"] = INFO
SETTINGS["log.console"] = True
binances_setting = {
"key": "",
"secret": "",
"会话数": 3,
"服务器": "REAL",
"合约模式": "正向",
"代理地址": "",
"代理端口": 0,
}
binance_setting = {
"key": "",
"secret": "",
"session_number": 3,
"proxy_host": "",
"proxy_port": 0
}
def request1():
start = datetime(2020, 10, 1, tzinfo=get_localzone())
end = datetime(2020, 10, 2, tzinfo=get_localzone())
req = HistoryRequest(
symbol=symbol,
exchange=exchange,
interval=Interval(interval),
start=start,
end=end
)
data = gate_way.query_history(req)
print(data)
if data:
database_manager.save_bar_data(data)
def request2():
print("start2")
start = datetime(2020, 11, 12, tzinfo=get_localzone())
end = datetime(2020, 11, 13, tzinfo=get_localzone())
req = HistoryRequest(
symbol=symbol,
exchange=exchange,
interval=Interval(interval),
start=start,
end=end
)
data = gate_way.query_history(req)
print("start12_end13", data)
if __name__ == "__main__":
"""
for crawling data from Binance exchange.
"""
SETTINGS["log.file"] = True
event_engine = EventEngine()
main_engine = MainEngine(event_engine)
main_engine.add_gateway(BinanceGateway) # spot
# main_engine.add_gateway(BinancesGateway) # future
main_engine.connect(binance_setting, "BINANCE") # spot
# main_engine.connect(binances_setting, "BINANCES") # future
sleep(3)
main_engine.write_log("连接BINANCE接口") # spot
# main_engine.write_log("连接BINANCES接口") # future
gate_way = main_engine.get_gateway("BINANCE") # spot
# gate_way = main_engine.get_gateway("BINANCES") # future
print(gate_way)
symbol = "btcusdt" # spot for lower case while the future will be upper case.
exchange = Exchange.BINANCE # binance.
interval = Interval.MINUTE # minute
t1 = Thread(target=request1)
# t2 = Thread(target=request2)
t1.start()
# t2.start()