-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataProcesser.py
57 lines (41 loc) · 1.15 KB
/
DataProcesser.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
from BitmexBot import BitmexBot
from datetime import datetime as dt
from time import sleep
from threading import *
import sys
class DataProcesser(Thread):
# OBV indicator(On-Balance Volume Indicator)
def OBV(self, trades):
result = 0
for trade in trades:
if trade['side'] == 'Sell':
result -= trade['size']
else:
result += trade['size']
return result
# Feedback from command line
def run(self):
sleep_time = 0
if len(sys.argv) == 2:
sleep_time = int(sys.argv[1])
print("Creating new OBV_vals.csv file...")
open('OBV_vals.csv', 'w').close()
sleep(1)
print("New file created")
else:
print("Invalid amount of arguments.")
print("Syntax: python3 bot.py <sleep time(in seconds)> ")
sys.exit()
# Init
client = BitmexBot("XBT")
start_time = dt.utcnow()
end_time = dt.utcnow()
my_obv = 0
# Infinite bubble where you see OBV values
while True:
sleep(sleep_time)
end_time = dt.utcnow()
recent_trades = client.RecentTrades(startTime=start_time, endTime=end_time)
start_time = end_time
my_obv += self.OBV(recent_trades)
client.writeToFile(fileName='OBV_vals.csv', row=[end_time, my_obv])