作者 karlet

feat:增加下单返佣码

@@ -34,6 +34,7 @@ use trader\struct\WsDataAccount; @@ -34,6 +34,7 @@ use trader\struct\WsDataAccount;
34 use trader\struct\Pos; 34 use trader\struct\Pos;
35 use \Exception; 35 use \Exception;
36 use function jytools\timeFormat; 36 use function jytools\timeFormat;
  37 +use function jytools\getMicrotime;
37 38
38 class CmBroker 39 class CmBroker
39 { 40 {
@@ -41,6 +42,8 @@ class CmBroker @@ -41,6 +42,8 @@ class CmBroker
41 const PLAT_BINANCE = 'binance'; 42 const PLAT_BINANCE = 'binance';
42 const PLAT_BYBIT = 'bybit'; 43 const PLAT_BYBIT = 'bybit';
43 const PLAT_BITGET = 'bitget'; 44 const PLAT_BITGET = 'bitget';
  45 + const BN_FEE_KEY = "x-tdk3UjFd";
  46 + const OK_FEE_KEY = "059de09b75e8BCDE";
44 /** 47 /**
45 * @var string 当前使用的交易平台 48 * @var string 当前使用的交易平台
46 * @see PLAT_OKX 49 * @see PLAT_OKX
@@ -116,6 +119,7 @@ class CmBroker @@ -116,6 +119,7 @@ class CmBroker
116 return $this->getSymbolSt($symbol); 119 return $this->getSymbolSt($symbol);
117 }); 120 });
118 if ($wsDataTrade != null) { 121 if ($wsDataTrade != null) {
  122 + $wsDataTrade->cliOrdId = str_replace(self::BN_FEE_KEY, '', $wsDataTrade->cliOrdId);
119 $wsData = new WsData($this->plat, 'trade', $trade = $wsDataTrade); 123 $wsData = new WsData($this->plat, 'trade', $trade = $wsDataTrade);
120 $onData($wsData); 124 $onData($wsData);
121 } 125 }
@@ -124,6 +128,7 @@ class CmBroker @@ -124,6 +128,7 @@ class CmBroker
124 return $this->getSymbolSt($symbol); 128 return $this->getSymbolSt($symbol);
125 }); 129 });
126 if ($wsDataOrder != null) { 130 if ($wsDataOrder != null) {
  131 + $wsDataOrder->cliOrdId = str_replace(self::BN_FEE_KEY, '', $wsDataOrder->cliOrdId);
127 $wsData = new WsData($this->plat, 'order', $trade = null, $pos = null, $order = $wsDataOrder); 132 $wsData = new WsData($this->plat, 'order', $trade = null, $pos = null, $order = $wsDataOrder);
128 $onData($wsData); 133 $onData($wsData);
129 } 134 }
@@ -287,6 +292,9 @@ class CmBroker @@ -287,6 +292,9 @@ class CmBroker
287 $orderOri = $order->toOkxOrder($this->symbolInfos, function ($symbol) { 292 $orderOri = $order->toOkxOrder($this->symbolInfos, function ($symbol) {
288 return $this->getSymbolOri($symbol); 293 return $this->getSymbolOri($symbol);
289 }); 294 });
  295 + if (!isset($orderOri['tag'])) {
  296 + $orderOri['tag'] = self::OK_FEE_KEY;
  297 + }
290 $this->msg("下单", $orderOri); 298 $this->msg("下单", $orderOri);
291 if ($orderOri['sz'] == 0) { 299 if ($orderOri['sz'] == 0) {
292 $msg = "当前下单数量为{$order->qty},最小下单数量为{$symbolInfo->minQty},不下单"; 300 $msg = "当前下单数量为{$order->qty},最小下单数量为{$symbolInfo->minQty},不下单";
@@ -301,6 +309,11 @@ class CmBroker @@ -301,6 +309,11 @@ class CmBroker
301 $orderOri = $order->toBinanceOrder($this->symbolInfos, function ($symbol) { 309 $orderOri = $order->toBinanceOrder($this->symbolInfos, function ($symbol) {
302 return $this->getSymbolOri($symbol, $this->plat); 310 return $this->getSymbolOri($symbol, $this->plat);
303 }); 311 });
  312 + if (isset($orderOri['newClientOrderId'])) {
  313 + $orderOri['newClientOrderId'] = self::BN_FEE_KEY . $orderOri['newClientOrderId'];
  314 + } else {
  315 + $orderOri['newClientOrderId'] = self::BN_FEE_KEY . getMicrotime();
  316 + }
304 $this->msg("下单", $orderOri); 317 $this->msg("下单", $orderOri);
305 if ($orderOri['quantity'] == 0) { 318 if ($orderOri['quantity'] == 0) {
306 $msg = "当前下单数量为{$order->qty},最小下单数量为{$symbolInfo->minQty},不下单"; 319 $msg = "当前下单数量为{$order->qty},最小下单数量为{$symbolInfo->minQty},不下单";
@@ -309,6 +322,9 @@ class CmBroker @@ -309,6 +322,9 @@ class CmBroker
309 } 322 }
310 $res = $this->exBroker->placeOrder($orderOri); 323 $res = $this->exBroker->placeOrder($orderOri);
311 $this->msg("下单结果", $res); 324 $this->msg("下单结果", $res);
  325 + if ($res && isset($res['clientOrderId'])) {
  326 + $res['clientOrderId'] = str_replace(self::BN_FEE_KEY, '', $res['clientOrderId']);
  327 + }
312 return $res; 328 return $res;
313 } 329 }
314 } 330 }