-
Notifications
You must be signed in to change notification settings - Fork 3
/
Util.py
43 lines (32 loc) · 1.54 KB
/
Util.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
import pandas as pd
import numpy as np
import math
import pickle
def binanceToPandas(klines):
klines = np.array(klines)
df = pd.DataFrame(klines.reshape(-1, 12), dtype=float, columns=('Open Time',
'Open',
'High',
'Low',
'Close',
'Volume',
'Close time',
'Quote asset volume',
'Number of trades',
'Taker buy base asset volume',
'Taker buy quote asset volume',
'Ignore'))
df['Open Time'] = pd.to_datetime(df['Open Time'], unit='ms')
return df
def truncate(number, digits) -> float:
stepper = 10.0 ** digits
return math.trunc(stepper * number) / stepper
def savePickle(var, file_name):
outfile = open(file_name, 'wb')
pickle.dump(var, outfile)
outfile.close()
def openPickle(file_name):
outfile = open(file_name, 'rb')
df = pickle.load(outfile)
outfile.close()
return df