作者 karlet

feat:查询获取所有仓位

@@ -256,4 +256,17 @@ class CmBroker @@ -256,4 +256,17 @@ class CmBroker
256 $symbol = $this->getSymbolOri($symbol, $this->plat); 256 $symbol = $this->getSymbolOri($symbol, $this->plat);
257 $this->exBroker->setLever($symbol, $lever); 257 $this->exBroker->setLever($symbol, $lever);
258 } 258 }
  259 + //查询获取全部持仓
  260 + public function getAllPos(): array
  261 + {
  262 + $positions = $this->exBroker->getAllPos();
  263 + $newPositions = [];
  264 + foreach ($positions as $key => $value) {
  265 + $item = Pos::transferOkxPos($value, $this->symbolInfos, function ($symbol) {
  266 + return $this->getSymbolSt($symbol);
  267 + });
  268 + $newPositions[$item->symbol . "_" . $item->posSide] = $item;
  269 + }
  270 + return $newPositions;
  271 + }
259 } 272 }
@@ -307,4 +307,24 @@ class ExBroker @@ -307,4 +307,24 @@ class ExBroker
307 return false; 307 return false;
308 } 308 }
309 } 309 }
  310 + //查询获取所有仓位
  311 + public function getAllPos()
  312 + {
  313 + $newPositions = [];
  314 + $param = [
  315 + 'instType' => 'SWAP'
  316 + ];
  317 + $res = $this->api->getPositions($param);
  318 + if ($res['code'] == 0) {
  319 + $positions = $res['data'];
  320 + foreach ($positions as $key => $value) {
  321 + if ($value['pos'] != 0) {
  322 + $newPositions[] = $value;
  323 + }
  324 + }
  325 + } else {
  326 + output($res);
  327 + }
  328 + return $newPositions;
  329 + }
310 } 330 }