$curl = curl_init(); curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $config['url'], CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false)); $resp = curl_exec($curl); curl_close($curl); } //current data in array $data = json_decode($resp, true); //--------------------------------------------------- //getting the datetime & converting to to UT & setting it in the array $datetime = explode('T', $data['query']['created']); $date = $datetime[0]; $time = explode('Z', $datetime[1]); $time = $time[0]; $created = $data['query']['created']; $data = $data['query']['results']['rate']; for ($i = 0; $i < count($data); $i++) { $data[$i]['Date'] = $date; $data[$i]['Time'] = $time; $data[$i]['Datetime'] = $date . ' ' . $time; } //--------------------------------------------------- // _print_r($data); //--------------------------------------------------- // insert into db $db = new Database($config); $db->insert_minute($config['db']['minute_table'], $data); //--------------------------------------------------- //--------------------------------------------------- // delete data from the minute table according to the settings $db->del($config['db']['minute_table'], $config['minute_table_range']); //---------------------------------------------------
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 day $data_day = 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_day[] = 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_day, false); //---------------------------------- //--------------------------------------------------- // insert into day table $db->insert_day($config['db']['day_table'], $data_day); //--------------------------------------------------- //--------------------------------------------------- // delete data from the day table according to the settings $db->del($config['db']['day_table'], $config['day_table_range']); //---------------------------------------------------