正在显示
1 个修改的文件
包含
15 行增加
和
8 行删除
| @@ -230,8 +230,8 @@ class ExBroker | @@ -230,8 +230,8 @@ class ExBroker | ||
| 230 | $data = $this->api->depth(['symbol' => $data['s'], 'limit' => 1000]); | 230 | $data = $this->api->depth(['symbol' => $data['s'], 'limit' => 1000]); |
| 231 | if ($data) { | 231 | if ($data) { |
| 232 | $this->depthData['lid'] = $data['lastUpdateId']; | 232 | $this->depthData['lid'] = $data['lastUpdateId']; |
| 233 | - $this->depthData['bids'] = $this->formatDepthData($data['bids']); | ||
| 234 | - $this->depthData['asks'] = $this->formatDepthData($data['asks']); | 233 | + $this->depthData['bids'] = $this->formatDepthData($data['bids'], 'bids'); |
| 234 | + $this->depthData['asks'] = $this->formatDepthData($data['asks'], 'asks'); | ||
| 235 | $this->depthData['uts'] = $data['T']; | 235 | $this->depthData['uts'] = $data['T']; |
| 236 | } | 236 | } |
| 237 | $this->gettingDepth = false; | 237 | $this->gettingDepth = false; |
| @@ -255,7 +255,7 @@ class ExBroker | @@ -255,7 +255,7 @@ class ExBroker | ||
| 255 | $this->addDepthData($data); | 255 | $this->addDepthData($data); |
| 256 | } | 256 | } |
| 257 | } | 257 | } |
| 258 | - private function formatDepthData($data) | 258 | + private function formatDepthData($data, $type) |
| 259 | { | 259 | { |
| 260 | $newData = []; | 260 | $newData = []; |
| 261 | foreach ($data as $item) { | 261 | foreach ($data as $item) { |
| @@ -263,12 +263,19 @@ class ExBroker | @@ -263,12 +263,19 @@ class ExBroker | ||
| 263 | $qty = ($item[1]); | 263 | $qty = ($item[1]); |
| 264 | $newData[$price] = $qty; | 264 | $newData[$price] = $qty; |
| 265 | } | 265 | } |
| 266 | + if ($type == 'asks') { | ||
| 267 | + //从小到大排序 | ||
| 268 | + ksort($newData); | ||
| 269 | + } else { | ||
| 270 | + //从大到小排序 | ||
| 271 | + krsort($newData); | ||
| 272 | + } | ||
| 266 | return $newData; | 273 | return $newData; |
| 267 | } | 274 | } |
| 268 | private function addDepthData($data) | 275 | private function addDepthData($data) |
| 269 | { | 276 | { |
| 270 | - $data['a'] = $this->formatDepthData($data['a']); | ||
| 271 | - $data['b'] = $this->formatDepthData($data['b']); | 277 | + $data['a'] = $this->formatDepthData($data['a'], 'asks'); |
| 278 | + $data['b'] = $this->formatDepthData($data['b'], 'bids'); | ||
| 272 | $this->depthData['asks'] = array_merge($this->depthData['asks'], $data['a']); | 279 | $this->depthData['asks'] = array_merge($this->depthData['asks'], $data['a']); |
| 273 | $this->depthData['bids'] = array_merge($this->depthData['bids'], $data['b']); | 280 | $this->depthData['bids'] = array_merge($this->depthData['bids'], $data['b']); |
| 274 | //保留值不为0的数据 | 281 | //保留值不为0的数据 |
| @@ -278,10 +285,10 @@ class ExBroker | @@ -278,10 +285,10 @@ class ExBroker | ||
| 278 | $this->depthData['bids'] = array_filter($this->depthData['bids'], function ($v) { | 285 | $this->depthData['bids'] = array_filter($this->depthData['bids'], function ($v) { |
| 279 | return floatval($v) != 0; | 286 | return floatval($v) != 0; |
| 280 | }); | 287 | }); |
| 281 | - //从大到小排序 | ||
| 282 | - krsort($this->depthData['asks']); | ||
| 283 | //从小到大排序 | 288 | //从小到大排序 |
| 284 | - ksort($this->depthData['bids']); | 289 | + ksort($this->depthData['asks']); |
| 290 | + //从大到小排序 | ||
| 291 | + krsort($this->depthData['bids']); | ||
| 285 | $this->depthData['lid'] = $data['u']; | 292 | $this->depthData['lid'] = $data['u']; |
| 286 | $this->depthData['uts'] = $data['T']; | 293 | $this->depthData['uts'] = $data['T']; |
| 287 | } | 294 | } |
-
请 注册 或 登录 后发表评论