-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatacapture.py
74 lines (55 loc) · 2.2 KB
/
datacapture.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
"""
Collecting all data from poloniex for future use in back testing.
"""
import asyncio
from autobahn.asyncio.wamp import ApplicationSession
from autobahn.asyncio.wamp import ApplicationRunner
from asyncio import coroutine
import time, datetime
class PoloniexComponent(ApplicationSession):
def onConnect(self):
self.join(self.config.realm)
async def onJoin(self, details):
def on_event(*i):
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S.%f')
print(st, i)
file = open("logs/ticks.log", "a")
file.write(st + " " + str(i) + "\n")
file.close()
def on_usdt_btc(*i, seq):
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S.%f')
print(st, seq, i)
file = open("logs/usdt_eth.log", "a")
file.write(st + " " + str(seq) + " " + str(i) + "\n")
file.close()
def on_usdt_eth(*i, seq):
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S.%f')
print(st, seq, i)
file = open("logs/usdt_btc.log", "a")
file.write(st + " " + str(seq) + " " + str(i) + "\n")
file.close()
def on_btc_eth(*i, seq):
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S.%f')
print(st, seq, i)
file = open("logs/btc_eth.log", "a")
file.write(st + " " + str(seq) + " " + str(i) + "\n")
file.close()
try:
await self.subscribe(on_event, 'trollbox')
await self.subscribe(on_event, 'ticker')
await self.subscribe(on_usdt_btc, 'USDT_BTC')
await self.subscribe(on_usdt_eth, 'USDT_ETH')
await self.subscribe(on_btc_eth, 'BTC_ETH')
except Exception as e:
print("Could not subscribe to topic:", e)
def onDisconnect(self):
asyncio.get_event_loop().stop()
def main():
runner = ApplicationRunner("wss://api.poloniex.com:443", "realm1")
runner.run(PoloniexComponent)
if __name__ == "__main__":
main()