/
range_script.php
105 lines (67 loc) · 2.61 KB
/
range_script.php
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
<?php
/*
- query "hour_data" table & store the following :
- open price of the day, (opening price at 24 hrs before)
- heighest price of the day, (heighest price within the last 24 hrs)
- lowest price of the day, (lowest price within the last 24 hrs)
- closing price of the day (closing price )
- store the data into "range_data" table of db
*/
if(date('H')!='0') die;
//echo 'Range Script -- '.date('Y-m-d H:i:s').' -- ';
require_once('include/config.php');
require_once('include/db.php');
// require_once('include/sort_fn.php');
$db = new Database($config);
//-------------------------------------
// get all the hourly data between the ranges
$data = $db->get($config['db']['hour_table'],'range_data',false,$config['range_start'],$config['range_end']);
// _print_r($data,false);
//-------------------------------------
//-------------------------------------
// rearrange the data according to symbols
$symbols_array = array();
foreach($data as $key=>$val){
$cur_symbol = $val['Symbol'];
$symbols_array[$cur_symbol] = array();
}
foreach($data as $key=>$val){
$cur_symbol = $val['Symbol'];
array_push($symbols_array[$cur_symbol], $val);
}
// _print_r($symbols_array,false);
//-------------------------------------
//-------------------------------------
// find the open, heigh, low, & closing of the range
$data_range = array();
foreach ($symbols_array as $key => $val) {
$heigh_array = array();
$low_array = array();
foreach($val as $kk=>$vv){
$heigh_array[] = $vv['Heigh'];
$low_array[] = $vv['Low'];
}
// _print_r($heigh_array,false);
// _print_r($low_array,false);
$date = explode(' ',$val[0]['Datetime']);
$data_range[] = array( 'Symbol' => $val[0]['Symbol'],
'Open' => $val[0]['Open'],
'Heigh' => max($heigh_array),
'Low' => min($low_array),
'Closing' => $val[count($val)-1]['Closing'],
'Datetime' => $val[0]['Datetime'],
'Range_start' => $date[0].' '.$config['range_start'],
'Range_end' => $date[0].' '.$config['range_end'],
);
}
_print_r($data_range,false);
// die;
//----------------------------------
//---------------------------------------------------
// insert into day table
$db->insert_range($config['db']['range_table'],$data_range);
//---------------------------------------------------
//---------------------------------------------------
// delete data from the range table according to the settings
$db->del($config['db']['range_table'],$config['range_table_range']);
//---------------------------------------------------