These are classes for accessing a SOAP-like stock market. The main class is the StockMarket
class and accepts an WSDL URL. We can initialize the StockMarket
class, for example, using:
require("classes/StockMarket.php"); $stockmarket = new StockMarket("http://www.nasdaqomxnordic.com/Bsews/intraday.asmx?wsdl");
at which one can retrieve symbols and indices. For example:
$indice = $stockmarket->getIndice("OMX"); print_r($indice);
and print out the parameters.
The code contains a main class called StockMarket.php
and three other object classes:
each of them responsible for initializing the symbol or indice object.
<?php require_once("Symbol.php"); require_once("Level.php"); require_once("Indice.php"); ini_set("default_socket_timeout", 60); /** * Stock-market class. */ class StockMarket { var $soapClient; function StockMarket($wsdlAddress) { $this->soapClient = new SoapClient($wsdlAddress); } function obj2array($obj) { $out = array(); foreach ($obj as $key => $val) { switch (true) { case is_object($val): $out[$key] = $this->obj2array($val); break; case is_array($val): $out[$key] = $this->obj2array($val); break; default: $out[$key] = $val; } } return $out; } /* * get indices based on market code. */ function getIndice($code) { $in = array( "code" => $code ); $indici = $this->soapClient->__soapCall('Indices', array( 'parameters' => $in ), null, null); $result = $this->obj2array($indici); $result = $result['IndicesResult']; $result = $result['TypeIndices']; $indice = new Indice(); $indice->setCode($code); $indice->setLastUpdateTime($result['LastUpdateTime']); $indice->setOpenValue($result['OpenValue']); $indice->setCurrentValue($result['CurrentValue']); $indice->setLowValue($result['LowValue']); $indice->setHighValue($result['HighValue']); $indice->setNetChange($result['NetChange']); $indice->setPrcChange($result['PrcChange']); return $indice; } /** * get symbol based on market. */ function getSymbol($symbol, $market) { $in = array( "symbol" => $symbol, "market" => $market ); $level1 = $this->soapClient->__soapCall('Level1', array( 'parameters' => $in ), null, null); $level1Result = $this->obj2array($level1); $level1Result = $level1Result['Level1Result']; $symbol = new Symbol(); $symbol->setMarketCode($level1Result['Marketcode']); $symbol->setSymbolCode($level1Result['Symbolcode']); $symbol->setLastTradeTime($level1Result['LastTradeTime']); $symbol->setOpenPrice($level1Result['Openprice']); $symbol->setClosePrice($level1Result['Closeprice']); $symbol->setValue($level1Result['Value']); $symbol->setVolume($level1Result['Volume']); $symbol->setTrades($level1Result['Trades']); $symbol->setLowPriceCurrent($level1Result['Lowpricecurrent']); $symbol->setHighPriceCurrent($level1Result['Highpricecurrent']); $symbol->setAvgprice($level1Result['Avgprice']); $symbol->setNetChgFromOfficialPrice($level1Result['NetChgFromOfficialPrice']); $symbol->setPrcChgFromOfficialPrice($level1Result['PrcChgFromOfficialPrice']); $symbol->setReferencePrice($level1Result['ReferencePrice']); $symbol->setPotentialOpenVol($level1Result['PotentialOpenVol']); $symbol->setPotentialOpenPrice($level1Result['PotentialOpenPrice']); $symbol->setSymbolStatus($level1Result['SymbolStatus']); $symbol->setLastBestTime($level1Result['LastBestTime']); $symbol->setBestBidVol($level1Result['BestBidVol']); $symbol->setBestBidPrice($level1Result['BestBidPricev']); $symbol->setBestAskVol($level1Result['BestAskVol']); $symbol->setBestAskPrice($level1Result['BestAskPrice']); return $symbol; } /** * get structured symbol based on market. */ function getSymbolPeNivele($symbol, $market) { $in = array( "symbol" => $symbol, "market" => $market ); $level2 = $this->soapClient->__soapCall('Level2', array( 'parameters' => $in ), null, null); $level2Result = $this->obj2array($level2); $level2Result = $level2Result['Level2Result']; $symbol = new Symbol(); $symbol->setMarketCode($level2Result['Marketcode']); $symbol->setSymbolCode($level2Result['Symbolcode']); $symbol->setLastTradeTime($level2Result['LastTradeTime']); $symbol->setOpenPrice($level2Result['Openprice']); $symbol->setClosePrice($level2Result['Closeprice']); $symbol->setValue($level2Result['Value']); $symbol->setVolume($level2Result['Volume']); $symbol->setTrades($level2Result['Trades']); $symbol->setLowPriceCurrent($level2Result['Lowpricecurrent']); $symbol->setHighPriceCurrent($level2Result['Highpricecurrent']); $symbol->setAvgprice($level2Result['Avgprice']); $symbol->setNetChgFromOfficialPrice($level2Result['NetChgFromOfficialPrice']); $symbol->setPrcChgFromOfficialPrice($level2Result['PrcChgFromOfficialPrice']); $symbol->setReferencePrice($level2Result['ReferencePrice']); $symbol->setPotentialOpenVol($level2Result['PotentialOpenVol']); $symbol->setPotentialOpenPrice($level2Result['PotentialOpenPrice']); $symbol->setSymbolStatus($level2Result['SymbolStatus']); $symbol->setLastTopTime($level2Result['LastTopTime']); $symbol->setNivel1($level2Result['A1Price'], $level2Result['B1Price'], $level2Result['A1Vol'], $level2Result['B1Vol']); $symbol->setNivel2($level2Result['A2Price'], $level2Result['B2Price'], $level2Result['A2Vol'], $level2Result['B2Vol']); $symbol->setNivel3($level2Result['A3Price'], $level2Result['B3Price'], $level2Result['A3Vol'], $level2Result['B3Vol']); $symbol->setNivel4($level2Result['A4Price'], $level2Result['B4Price'], $level2Result['A4Vol'], $level2Result['B4Vol']); $symbol->setNivel5($level2Result['A5Price'], $level2Result['B5Price'], $level2Result['A5Vol'], $level2Result['B5Vol']); return $symbol; } }
<?php /** * symbol object */ class Symbol { var $symbolCode; var $marketCode; var $lastTradeTime; var $openPrice; var $closePrice; var $value; var $volume; var $trades; var $lowpriceCurrent; var $highpriceCurrent; var $avgprice; var $netChgFromOfficialPrice; var $prcChgFromOfficialPrice; var $referencePrice; var $potentialOpenVol; var $potentialOpenPrice; var $symbolStatus; var $lastBestTime; var $lastTopTime; var $bestBidVol; var $bestBidPrice; var $bestAskVol; var $bestAskPrice; var $nivel1; var $nivel2; var $nivel3; var $nivel4; var $nivel5; function setAvgprice($s) { $this->avgprice = $s; } function getAvgprice() { return $this->avgprice; } function setBestAskPrice($s) { $this->bestAskPrice = $s; } function getBestAskPrice() { return $this->bestAskPrice; } function setBestAskVol($s) { $this->bestAskVol = $s; } function getBestAskVol() { return $this->bestAskVol; } function setBestBidVol($s) { $this->bestBidVol = $s; } function getBestBidVol() { return $this->bestBidVol; } function setBestBidPrice($s) { $this->bestBidPrice = $s; } function getBestBidPrice() { return $this->bestBidPrice; } function setClosePrice($s) { $this->closePrice = $s; } function getClosePrice() { return $this->closePrice; } function setHighPriceCurrent($s) { $this->highpriceCurrent = $s; } function getHighPriceCurrent() { return $this->highpriceCurrent; } function setLastBestTime($s) { $this->lastBestTime = $s; } function getLastBestTime() { return $this->lastBestTime; } function setLastTopTime($s) { $this->lastTopTime = $s; } function getLastTopTime() { return $this->lastTopTime; } function setLastTradeTime($s) { $this->lastTradeTime = $s; } function getLastTradeTime() { return $this->lastTradeTime; } function setLowPriceCurrent($s) { $this->lowpriceCurrent = $s; } function getLowpriceCurrent() { return $this->lowpriceCurrent; } function setMarketCode($s) { $this->marketCode = $s; } function getMarketCode() { return $this->marketCode; } function setNetChgFromOfficialPrice($s) { $this->netChgFromOfficialPrice = $s; } function getNetChgFromOfficialPrice() { return $this->netChgFromOfficialPrice; } function setOpenPrice($s) { $this->openPrice = $s; } function getOpenPrice() { return $this->openPrice; } function setPotentialOpenPrice($s) { $this->potentialOpenPrice = $s; } function getPotentialOpenPrice() { return $this->potentialOpenPrice; } function setPotentialOpenVol($s) { $this->potentialOpenVol = $s; } function getPotentialOpenVol() { return $this->potentialOpenVol; } function setPrcChgFromOfficialPrice($s) { $this->prcChgFromOfficialPrice = $s; } function getPrcChgFromOfficialPrice() { return $this->prcChgFromOfficialPrice; } function setReferencePrice($s) { $this->referencePrice = $s; } function getReferencePrice() { return $this->referencePrice; } function setSymbolCode($s) { $this->symbolCode = $s; } function getSymbolCode() { return $this->symbolCode; } function setSymbolStatus($s) { $this->symbolStatus = $s; } function getSymbolStatus() { return $this->symbolStatus; } function setTrades($s) { $this->trades = $s; } function getTrades() { return $this->trades; } function setValue($s) { $this->value = $s; } function getValue() { return $this->value; } function setVolume($s) { $this->volume = $s; } function getVolume() { return $this->volume; } function setNivel1($a, $b, $aVol, $bVol) { $this->nivel1 = new Nivel($a, $b, $aVol, $bVol); } function getNivel1() { return $this->nivel1; } function setNivel2($a, $b, $aVol, $bVol) { $this->nivel2 = new Nivel($a, $b, $aVol, $bVol); } function getNivel2() { return $this->nivel2; } function setNivel3($a, $b, $aVol, $bVol) { $this->nivel3 = new Nivel($a, $b, $aVol, $bVol); } function getNivel3() { return $this->nivel3; } function setNivel4($a, $b, $aVol, $bVol) { $this->nivel4 = new Nivel($a, $b, $aVol, $bVol); } function getNivel4() { return $this->nivel4; } function setNivel5($a, $b, $aVol, $bVol) { $this->nivel5 = new Nivel($a, $b, $aVol, $bVol); } function getNivel5() { return $this->nivel5; } } ?>
<?php /** * indice object */ class Indice { var $code; var $lastUpdateTime; var $openValue; var $currentValue; var $lowValue; var $highValue; var $netChange; var $prcChange; function setCode($s) { $this->code = $s; } function getCode() { return $this->code; } function setLastUpdateTime($s) { $this->lastUpdateTime = $s; } function getLastUpdateTime() { return $this->lastUpdateTime; } function setOpenValue($s) { $this->openValue = $s; } function getOpenValue() { return $this->openValue; } function setCurrentValue($s) { $this->currentValue = $s; } function getCurrentValue() { return $this->currentValue; } function setLowValue($s) { $this->lowValue = $s; } function getLowValue() { return $this->lowValue; } function setHighValue($s) { $this->highValue = $s; } function getHighValue() { return $this->highValue; } function setNetChange($s) { $this->netChange = $s; } function getNetChange() { return $this->netChange; } function setPrcChange($s) { $this->prcChange = $s; } function getPrcChange() { return $this->prcChange; } } ?>
<?php /** * used to model structured symbols. */ class Level { var $a; var $b; var $aVol; var $bVol; function Level($a, $b, $aVol, $bVol) { $this->a = $a; $this->b = $b; $this->aVol = $aVol; $this->bVol = $bVol; } function getA() { return $this->a; } function getAVol() { return $this->aVol; } function getB() { return $this->b; } function getBVol() { return $this->bVol; } } ?>