作者 karlet

feat:正负处理

... ... @@ -198,6 +198,10 @@ class CmBroker
});
if ($wsDataPos) {
$pos = Pos::transferWsDataPos($wsDataPos);
if ($this->posMode != self::MODE_ONE_SIDE) {
$pos->qty = abs($pos->qty); // 统一为正
$pos->lot = abs($pos->lot); // 统一为正
}
$positions[$wsDataPos->symbol . "_" . $wsDataPos->posSide] = $pos;
$wsData = new WsData($this->plat, 'pos', $trade = null, $pos = $wsDataPos);
$onData($wsData);
... ... @@ -650,12 +654,20 @@ class CmBroker
$item = Pos::transferOkxPos($value, $this->symbolInfos, function ($symbol) {
return $this->getSymbolSt($symbol);
});
if ($this->posMode != self::MODE_ONE_SIDE) {
$item->qty = abs($item->qty);
$item->lot = abs($item->lot);
}
$newPositions[$item->symbol . "_" . $item->posSide] = $item;
}
if ($this->plat == self::PLAT_BINANCE) {
$item = Pos::transferBinancePos($value, $this->symbolInfos, function ($symbol) {
return $this->getSymbolSt($symbol);
});
if ($this->posMode != self::MODE_ONE_SIDE) {
$item->qty = abs($item->qty);
$item->lot = abs($item->lot);
}
$newPositions[$item->symbol . "_" . $item->posSide] = $item;
}
}
... ...
... ... @@ -49,7 +49,7 @@ class Pos
/** @var SymbolInfo $symbolInfo */
$symbolInfo = $symbolInfos[$symbol];
$posSide = strtoupper($pos['posSide']);
$lot = abs($pos['pos']);
$lot = $pos['pos'];
$qty = round($lot * $symbolInfo->ctVal, $symbolInfo->qtyPrec);
$avgPrice = $pos['avgPx'];
$pnl = $pos['upl'];
... ... @@ -68,7 +68,7 @@ class Pos
/** @var SymbolInfo $symbolInfo */
$symbolInfo = $symbolInfos[$symbol];
$posSide = strtoupper($pos['positionSide']);
$qty = abs($pos['positionAmt']);
$qty = $pos['positionAmt'];
$lot = round($qty / $symbolInfo->ctVal, $symbolInfo->qtyPrec);
$avgPrice = -1;
$pnl = $pos['unrealizedProfit'];
... ...