作者 karlet

feat:持仓模式

@@ -48,6 +48,8 @@ class CmBroker @@ -48,6 +48,8 @@ class CmBroker
48 const PLAT_BITGET = 'bitget'; 48 const PLAT_BITGET = 'bitget';
49 const BN_FEE_KEY = "x-tdk3UjFd"; 49 const BN_FEE_KEY = "x-tdk3UjFd";
50 const OK_FEE_KEY = "059de09b75e8BCDE"; 50 const OK_FEE_KEY = "059de09b75e8BCDE";
  51 + const MODE_TWO_SIDE = 'TWO_SIDE';
  52 + const MODE_ONE_SIDE = 'ONE_SIDE';
51 /** 53 /**
52 * @var string 当前使用的交易平台 54 * @var string 当前使用的交易平台
53 * @see PLAT_OKX 55 * @see PLAT_OKX
@@ -64,6 +66,7 @@ class CmBroker @@ -64,6 +66,7 @@ class CmBroker
64 public $name = ''; 66 public $name = '';
65 public $levers = []; 67 public $levers = [];
66 public $uid; 68 public $uid;
  69 + public $posMode = '';
67 70
68 71
69 public function __construct($plat, ?ApiInfo $apiInfo, $wsHost = null, $restHost = null) 72 public function __construct($plat, ?ApiInfo $apiInfo, $wsHost = null, $restHost = null)
@@ -101,6 +104,7 @@ class CmBroker @@ -101,6 +104,7 @@ class CmBroker
101 } 104 }
102 public function init() 105 public function init()
103 { 106 {
  107 + $this->initPosMode();
104 $this->initSymbolInfos(); 108 $this->initSymbolInfos();
105 } 109 }
106 public function accListen(callable $onData) 110 public function accListen(callable $onData)
@@ -730,4 +734,12 @@ class CmBroker @@ -730,4 +734,12 @@ class CmBroker
730 } 734 }
731 return $data; 735 return $data;
732 } 736 }
  737 + private function initPosMode()
  738 + {
  739 + if ($this->plat == self::PLAT_OKX) {
  740 + $res = $this->exBroker->getAccountConfig();
  741 + $config = $res['data'][0];
  742 + $this->posMode = $config['posMode'] == 'long_short_mode' ? self::MODE_TWO_SIDE : self::MODE_ONE_SIDE;
  743 + }
  744 + }
733 } 745 }
@@ -114,6 +114,12 @@ class Api @@ -114,6 +114,12 @@ class Api
114 $method = 'POST'; 114 $method = 'POST';
115 return $this->request($path, $method, $param, $this->apiInfo); 115 return $this->request($path, $method, $param, $this->apiInfo);
116 } 116 }
  117 + public function getAccountConfig($param = [])
  118 + {
  119 + $path = '/api/v5/account/config';
  120 + $method = 'GET';
  121 + return $this->request($path, $method, $param, $this->apiInfo);
  122 + }
117 123
118 //------------------------------------- 124 //-------------------------------------
119 125
@@ -383,4 +383,8 @@ class ExBroker @@ -383,4 +383,8 @@ class ExBroker
383 $res = $this->api->fundingRate($param); 383 $res = $this->api->fundingRate($param);
384 return $res; 384 return $res;
385 } 385 }
  386 + public function getAccountConfig()
  387 + {
  388 + return $this->api->getAccountConfig();
  389 + }
386 } 390 }