|
...
|
...
|
@@ -230,8 +230,8 @@ class ExBroker |
|
|
|
$data = $this->api->depth(['symbol' => $data['s'], 'limit' => 1000]);
|
|
|
|
if ($data) {
|
|
|
|
$this->depthData['lid'] = $data['lastUpdateId'];
|
|
|
|
$this->depthData['bids'] = $this->formatDepthData($data['bids']);
|
|
|
|
$this->depthData['asks'] = $this->formatDepthData($data['asks']);
|
|
|
|
$this->depthData['bids'] = $this->formatDepthData($data['bids'], 'bids');
|
|
|
|
$this->depthData['asks'] = $this->formatDepthData($data['asks'], 'asks');
|
|
|
|
$this->depthData['uts'] = $data['T'];
|
|
|
|
}
|
|
|
|
$this->gettingDepth = false;
|
|
...
|
...
|
@@ -255,7 +255,7 @@ class ExBroker |
|
|
|
$this->addDepthData($data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private function formatDepthData($data)
|
|
|
|
private function formatDepthData($data, $type)
|
|
|
|
{
|
|
|
|
$newData = [];
|
|
|
|
foreach ($data as $item) {
|
|
...
|
...
|
@@ -263,12 +263,19 @@ class ExBroker |
|
|
|
$qty = ($item[1]);
|
|
|
|
$newData[$price] = $qty;
|
|
|
|
}
|
|
|
|
if ($type == 'asks') {
|
|
|
|
//从小到大排序
|
|
|
|
ksort($newData);
|
|
|
|
} else {
|
|
|
|
//从大到小排序
|
|
|
|
krsort($newData);
|
|
|
|
}
|
|
|
|
return $newData;
|
|
|
|
}
|
|
|
|
private function addDepthData($data)
|
|
|
|
{
|
|
|
|
$data['a'] = $this->formatDepthData($data['a']);
|
|
|
|
$data['b'] = $this->formatDepthData($data['b']);
|
|
|
|
$data['a'] = $this->formatDepthData($data['a'], 'asks');
|
|
|
|
$data['b'] = $this->formatDepthData($data['b'], 'bids');
|
|
|
|
$this->depthData['asks'] = array_merge($this->depthData['asks'], $data['a']);
|
|
|
|
$this->depthData['bids'] = array_merge($this->depthData['bids'], $data['b']);
|
|
|
|
//保留值不为0的数据
|
|
...
|
...
|
@@ -278,10 +285,10 @@ class ExBroker |
|
|
|
$this->depthData['bids'] = array_filter($this->depthData['bids'], function ($v) {
|
|
|
|
return floatval($v) != 0;
|
|
|
|
});
|
|
|
|
//从大到小排序
|
|
|
|
krsort($this->depthData['asks']);
|
|
|
|
//从小到大排序
|
|
|
|
ksort($this->depthData['bids']);
|
|
|
|
ksort($this->depthData['asks']);
|
|
|
|
//从大到小排序
|
|
|
|
krsort($this->depthData['bids']);
|
|
|
|
$this->depthData['lid'] = $data['u'];
|
|
|
|
$this->depthData['uts'] = $data['T'];
|
|
|
|
}
|
...
|
...
|
|