-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOkCoinTest.py
More file actions
executable file
·86 lines (68 loc) · 1.98 KB
/
OkCoinTest.py
File metadata and controls
executable file
·86 lines (68 loc) · 1.98 KB
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
import OkCoin
import math
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from timeit import default_timer as timer
from numpy import *
from numpy import save
from numpy import load
import datetime
def Unix(x):
return( datetime.datetime.fromtimestamp(int(x)).strftime('%Y-%m-%d %H:%M:%S'))
def OHLC(x,begin_time,interval,count_interval):
Time = begin_time+interval*count_interval
price = x[:,1]
Open = x[0,1]
High = max(price)
Low = min(price)
Close = x[len(x)-1,1]
return Time,Open,High,Low,Close
def Load():
File = "okcoin.txt"
Data = np.loadtxt(File,delimiter=',')
#Data = [timestamp, price, volume]
begin_time = Data[0,0]
count=0
count_interval=0
count_data=0
hour = 60*60
day = hour*24
week = day*7
year = week*52
interval = hour
Intervals = math.floor((Data[len(Data)-1,0]-Data[0,0])/interval)
#Time, Open, High, Low, Close
Data_Array = zeros((Intervals,5))
file_name = "smalldata/Data.csv"
while(count_interval<Intervals):
while(Data[count+count_data,0]<=begin_time+interval*count_interval):
count+=1
if(count>0):
Data_Temp = zeros((count,3))
count=0
while(Data[count_data,0]<=begin_time+interval*count_interval):
Data_Temp[count] = Data[count_data]
count_data+=1
count+=1
Data_Array[count_interval] = OHLC(Data_Temp,begin_time,interval,count_interval)
Time = begin_time+interval*count_interval
np.savetxt(file_name, (Data_Array), delimiter=",")
count=0
count_interval+=1
else:
Data_Array[count_interval,0]=begin_time+interval*count_interval
Data_Array[count_interval,1:4] = Data_Array[count_interval-1,1]
Time = begin_time+interval*count_interval
np.savetxt(file_name, (Data_Array), delimiter=",")
count=0
count_interval+=1
print Unix((begin_time+interval*count_interval))
def Update():
return
def Live_Update():
return
def Get_Info():
return
Load()