作者 karlet

feat:增加异常处理

@@ -41,6 +41,7 @@ use trader\struct\IndexTicker; @@ -41,6 +41,7 @@ use trader\struct\IndexTicker;
41 use \Exception; 41 use \Exception;
42 use function jytools\timeFormat; 42 use function jytools\timeFormat;
43 use function jytools\getMicrotime; 43 use function jytools\getMicrotime;
  44 +use function jytools\output;
44 45
45 class CmBroker 46 class CmBroker
46 { 47 {
@@ -711,11 +712,18 @@ class CmBroker @@ -711,11 +712,18 @@ class CmBroker
711 $posSide = strtolower($posSide); 712 $posSide = strtolower($posSide);
712 $symbolInfo = $this->symbolInfos[$symbol]; 713 $symbolInfo = $this->symbolInfos[$symbol];
713 $lot = $this->exBroker->getPos($symbolOri, $posSide); 714 $lot = $this->exBroker->getPos($symbolOri, $posSide);
  715 + if ($lot === false) {
  716 + return false;
  717 + }
714 $qty = round($lot * $symbolInfo->ctVal, $symbolInfo->qtyPrec); 718 $qty = round($lot * $symbolInfo->ctVal, $symbolInfo->qtyPrec);
715 if ($this->posMode != self::MODE_ONE_SIDE) { 719 if ($this->posMode != self::MODE_ONE_SIDE) {
716 $qty = abs($qty); 720 $qty = abs($qty);
717 $lot = abs($lot); 721 $lot = abs($lot);
718 } 722 }
  723 + if ($lot != 0 && $qty == 0) {
  724 + output("获取仓位异常,持仓合约张数与币数异常", $symbol, $posSide, $lot, $qty, "合约面值:", $symbolInfo->ctVal);
  725 + return false;
  726 + }
719 return $qty; 727 return $qty;
720 } else { 728 } else {
721 throw new \Exception("获取仓位失败,当前交易所未实现该方法"); 729 throw new \Exception("获取仓位失败,当前交易所未实现该方法");