สรุป PHP Forex class จากบทความที่แล้ว
การเรียกดูข้อมูล Real Time ปัจจุบันใน chart E/U
class forex {
public function connect() {
$this->api = new SoapClient ("http://127.0.0.1:8018/service.wsdl",
array('features' => SOAP_SINGLE_ELEMENT_ARRAYS));
}
public function chartdata($chart) {
$quote = $this->api->GetQuote($chart);
return $quote;
}
}
ผลลัพธ์ที่ได้จากการเรียก
$forex = new forex;
$forex->connect();
$quote = $forex->chartdata('EUR/USD');
echo $quote -> Last;
ผลลัพธ์
[Last] => 1.3633
[Bid] => 1.3632
[Offer] => 1.3634
[Change] => +0.0006
[High] => 1.3636
[Low] => 1.3627
[Time] => 12:06:27
การเรียกดูข้อมูลย้อนหลัง เพื่อนำมาวิเคราะห์
$data_array = $forex->getBars('EUR/USD','5','f');
class getBars มีรายละเอียดดังนี้
public function getBars($viewchart='EUR/USD', $period='5', $ordertype=NULL) {
# $period : "5 Minutes", "15 Minutes", "30 Minutes", "Hourly", "4 Hours", "Daily", "Weekly", or "Monthly"
# $ordertype f:descending order
if ($period=='5')
$per = '5 minutes';
elseif ($period=='15')
$per = '15 minutes';
elseif ($period=='30')
$per = '30 minutes';
elseif ($period=='H')
$per = 'Hourly';
elseif ($period=='4H')
$per = '4 Hours';
elseif ($period=='D')
$per = 'Daily';
elseif ($period=='W')
$per = 'Weekly';
elseif ($period=='M')
$per = 'Monthly';
$r = $this->api->GetBars($viewchart, $per, $ordertype);
if(property_exists($r, "Bar")) {
foreach($r->Bar as $n => $Bar) {
foreach($Bar as $field => $value) {
$arr[$n][$field] = $value;
}
}
}
return $arr;
}