<?php
class bitkop
{
protected $secretKey = '';
protected $apiKey = '';
protected $tradePwd = '';
protected $base_url = 'https://apiv2.bitkop.com';
protected $url = '';
public function __construct($options = null)
{
$this->url = $this->base_url;
try {
if (is_array($options))
{
foreach ($options as $option => $value)
{
$this->$option = $value;
}
}
else
{
return false;
}
}
catch (PDOException $e) {
throw new Exception($e->getMessage());
}
}
public function ticker(array $parms){
$sendData = $this->getData($parms);
$url = $this->url.'/Market/ticker?'.http_build_query($sendData);
return $this->httpRequest($url);
}
public function kline(array $parms){
$sendData = $this->getData($parms);
$url = $this->url.'/Market/kline?'.http_build_query($sendData);
return $this->httpRequest($url);
}
public function depth(array $parms){
$sendData = $this->getData($parms);
$url = $this->url.'/Market/depth?'.http_build_query($sendData);
return $this->httpRequest($url);
}
public function order(array $parms){
$sendData = $this->getData($parms);
$url = $this->url.'/Market/order?'.http_build_query($sendData);
return $this->httpRequest($url);
}
public function tickerall(array $parms){
$sendData = $this->getData($parms);
$url = $this->url.'/Market/tickerall?'.http_build_query($sendData);
return $this->httpRequest($url);
}
public function symbolList(array $parms){
$sendData = $this->getData($parms);
$url = $this->url.'/Market/symbolList?'.http_build_query($sendData);
return $this->httpRequest($url);
}
public function currencyRate(array $parms){
$sendData = $this->getData($parms);
$url = $this->url.'/Market/currencyRate?'.http_build_query($sendData);
return $this->httpRequest($url);
}
public function currencyCoinRate(array $parms){
$sendData = $this->getData($parms);
$url = $this->url.'/Market/currencyCoinRate?'.http_build_query($sendData);
return $this->httpRequest($url);
}
public function coinRate(array $parms){
$sendData = $this->getData($parms);
$url = $this->url.'/Market/coinRate?'.http_build_query($sendData);
return $this->httpRequest($url);
}
public function getUserAssets(){
$sendData = $this->getData();
$url = $this->url.'/Assets/getUserAssets';
return $this->httpRequest($url,$sendData);
}
public function addEntrustSheet(array $parms)
{
$parms['tradePwd'] = $this->tradePwd;
$sendData = $this->getData($parms);
$url = $this->url.'/Trade/addEntrustSheet';
return $this->httpRequest($url,$sendData);
}
public function cancelEntrustSheet(array $parms){
$sendData = $this->getData($parms);
$url = $this->url.'/Trade/cancelEntrustSheet';
return $this->httpRequest($url,$sendData);
}
public function cancelAllEntrustSheet(array $parms){
$sendData = $this->getData($parms);
$url = $this->url.'/Trade/cancelAllEntrustSheet';
return $this->httpRequest($url,$sendData);
}
public function getEntrustSheetInfo(array $parms){
$sendData = $this->getData($parms);
$url = $this->url.'/Trade/getEntrustSheetInfo';
return $this->httpRequest($url,$sendData);
}
public function getUserNowEntrustSheet(array $parms){
$sendData = $this->getData($parms);
$url = $this->url.'/Trade/getUserNowEntrustSheet';
return $this->httpRequest($url,$sendData);
}
public function getUserHistoryEntrustSheet(array $parms){
$sendData = $this->getData($parms);
$url = $this->url.'/Trade/getUserHistoryEntrustSheet';
return $this->httpRequest($url,$sendData);
}
protected function getData($data = null){
$baseArr = array(
'timeStamp' => time(),
'nonce' => $this->getRandomString(6),
'apiKey' => $this->apiKey,
);
if(isset($data)){
$sendData = array_merge($baseArr,$data);
}else{
$sendData = $baseArr;
}
$sendData['sign'] = $this->getSign($sendData);
return $sendData;
}
protected function getSign($data)
{
ksort($data);
$dataStr = '';
foreach ($data as $k => $v)
{
$dataStr .= $k.'='.$v."&";
}
return md5(trim($dataStr,"&").$this->secretKey);
}
protected function getRandomString($len, $chars=null)
{
if (is_null($chars)){
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
}
for ($i = 0, $str = '', $lc = strlen($chars)-1; $i < $len; $i++){
$str .= $chars[mt_rand(0, $lc)];
}
return $str;
}
protected function httpRequest($url,$data = null){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
if(!empty($data)){
curl_setopt($curl,CURLOPT_POST,1);
curl_setopt($curl,CURLOPT_POSTFIELDS,$data);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($curl);
curl_close($curl);
return $output;
}
}
$bitkop = new bitkop();
$parms = array('symbol' => 'eos_btc');
print_r($bitkop->ticker($parms));