作者 karlet

feat:增加异常处理

... ... @@ -41,6 +41,7 @@ use trader\struct\IndexTicker;
use \Exception;
use function jytools\timeFormat;
use function jytools\getMicrotime;
use function jytools\output;
class CmBroker
{
... ... @@ -711,11 +712,18 @@ class CmBroker
$posSide = strtolower($posSide);
$symbolInfo = $this->symbolInfos[$symbol];
$lot = $this->exBroker->getPos($symbolOri, $posSide);
if ($lot === false) {
return false;
}
$qty = round($lot * $symbolInfo->ctVal, $symbolInfo->qtyPrec);
if ($this->posMode != self::MODE_ONE_SIDE) {
$qty = abs($qty);
$lot = abs($lot);
}
if ($lot != 0 && $qty == 0) {
output("获取仓位异常,持仓合约张数与币数异常", $symbol, $posSide, $lot, $qty, "合约面值:", $symbolInfo->ctVal);
return false;
}
return $qty;
} else {
throw new \Exception("获取仓位失败,当前交易所未实现该方法");
... ...