作者 karlet

feat:币安增加k线获取

... ... @@ -739,6 +739,20 @@ class CmBroker
$newKlines = array_reverse($newKlines);
return $newKlines;
}
if ($this->plat == self::PLAT_BINANCE) {
$res = $this->exBroker->getKlines($symbolOri, $peroidOri, $limit);
if ($res['code'] != 0) {
return [];
}
$newKlines = [];
foreach ($res['data'] as $key => $value) {
$kline = Kline::transferBinanceRest($value);
$newKlines[] = $kline;
}
//把 $newKlines 倒序
$newKlines = array_reverse($newKlines);
return $newKlines;
}
return [];
}
public function initPositions()
... ...
... ... @@ -37,6 +37,13 @@ class Api
$method = "GET";
return $this->request($method, $url, $params);
}
//获取k线
public function klines($params)
{
$url = "/fapi/v1/klines";
$method = "GET";
return $this->request($method, $url, $params);
}
//-------private interface ------------
//获取用户监听key
... ...
... ... @@ -164,4 +164,21 @@ class ExBroker
$res = $this->api->symbolConfig(['symbol' => $symbol]);
return $res;
}
//获取k线
public function getKlines($symbol, $interval, $limit = 200, $start = '', $end = '')
{
$params = [
'symbol' => $symbol,
'interval' => $interval,
'limit' => $limit,
];
if ($start) {
$params['startTime'] = $start;
}
if ($end) {
$params['endTime'] = $end;
}
$res = $this->api->klines($params);
return $res;
}
}
... ...
... ... @@ -14,4 +14,12 @@ class ApiInfo
$this->secret = $secret;
$this->passphrase = $passphrase;
}
public function toArray()
{
return [
'key' => $this->key,
'secret' => $this->secret,
'passphrase' => $this->passphrase,
];
}
}
... ...
... ... @@ -71,6 +71,19 @@ class Kline
$isFinal = $kline['x'];
return new Kline($time, $open, $high, $low, $close, $vol, $volQuote, $uts, $isFinal);
}
public static function transferBinanceRest($data)
{
$time = $data[0];
$open = $data[1];
$high = $data[2];
$low = $data[3];
$close = $data[4];
$vol = $data[5];
$volQuote = $data[7];
$uts = $data[0];
$isFinal = true;
return new Kline($time, $open, $high, $low, $close, $vol, $volQuote, $uts, $isFinal);
}
public static function transferBybit($data)
{
$kline = $data['data'][0];
... ...