-
Notifications
You must be signed in to change notification settings - Fork 0
/
symbol.php
133 lines (86 loc) · 3.24 KB
/
symbol.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
/*
- create "connect.php" as include to connect to db
- create "index.php" script (?)
- from url "domainname.com/symbol/" (ie, http://example.com/EURUSD ?), get :
- currency price (1 minute ago)
- last hour OHLC prices
- last day's OHLC prices
- yesterday’s range (?) OHLC prices
- display on provided template the data obtained
*/
require_once('include/config.php');
require_once('include/db.php');
//==============================
//here ,$symbol will be the currency identifier, eg, eurusd
$symbol = $_GET['symbol'];
//using symbols limited to the 20 specified symbols
if(!in_array(strtoupper($symbol), $config['symbols'])){
echo 'Invalid symbol';
die;
}
$db = new Database($config);
//-------------------------------------
// test the symbol called
// _print_r($_GET);
//-------------------------------------
//-------------------------------------
// execute the range script
// include('range_script.php');
//-------------------------------------
//-------------------------------------
// get the current prices of the selected symbol
//uppercase coz. it is used a lot.
$symbol_upper = strtoupper($symbol);
// current minute data
$last_minute = $db->get($config['db']['minute_table'],'latest_minute',$symbol);
// echo 'Current minute data';
// _print_r($last_minute,false);
// current hour detail data
$current_hour_detail = $db->get($config['db']['minute_table'],'1_hour_earlier',$symbol);
//_print_r($current_hour_detail,false);
$tmp = array();
for($i=0;$i<count($current_hour_detail);$i+=3){
$tmp[] = $current_hour_detail[$i];
}
$current_hour_detail = $tmp;
//echo 'Current hour data';
//_print_r($current_hour_detail);
// last hour data
$last_hour = $db->get($config['db']['hour_table'],'latest_hour',$symbol);
// echo 'Last hour data';
// _print_r($last_hour,false);
// last day's prices
$last_day = $db->get($config['db']['day_table'],'latest_day',$symbol);
// echo 'Last day data';
// _print_r($last_day,false);
// last days' ohlc prices
$last_day_ohlc = $db->get($config['db']['range_table'],'range_data',$symbol,$config['range_start'],$config['range_end']);
// _print_r($last_day_ohlc,false);
//-------------------------------------
//-------------------------------------
// find the open, heigh, low, & closing of the day
$data_range = array();
$heigh_array = array();
$low_array = array();
foreach($last_day_ohlc as $kk=>$vv){
$heigh_array[] = $vv['Heigh'];
$low_array[] = $vv['Low'];
}
// _print_r($heigh_array,false);
// _print_r($low_array,false);
$date = explode(' ',$last_day_ohlc[0]['Datetime']);
$data_range[] = array( 'Symbol' => $last_day_ohlc[0]['Symbol'],
'Open' => $last_day_ohlc[0]['Open'],
'Heigh' => count($heigh_array)?max($heigh_array):'',
'Low' => count($low_array)?min($low_array):'',
'Closing' => $last_day_ohlc[count($last_day_ohlc)-1]['Closing'],
'Datetime' => $last_day_ohlc[0]['Datetime'],
'Range_start' => $date[0].' '.$config['range_start'],
'Range_end' => $date[0].' '.$config['range_end'],
);
// _print_r($data_range);
//----------------------------------
$t=time();
// Include the template for display
include($config['template']['path'].'rates.tpl.php');