mirror of
https://github.com/discountry/ritmex-bot.git
synced 2026-09-11 17:28:08 +00:00
fix position size
This commit is contained in:
@@ -214,9 +214,13 @@ export class TrendEngine {
|
|||||||
try {
|
try {
|
||||||
await this.exchange.cancelAllOrders({ symbol: this.config.symbol });
|
await this.exchange.cancelAllOrders({ symbol: this.config.symbol });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (isUnknownOrderError(err)) {
|
||||||
|
this.tradeLog.push("order", "撤单时部分订单已不存在,忽略");
|
||||||
|
} else {
|
||||||
this.tradeLog.push("error", `撤销挂单失败: ${String(err)}`);
|
this.tradeLog.push("error", `撤销挂单失败: ${String(err)}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (this.lastPrice > currentSma && currentPrice < currentSma) {
|
if (this.lastPrice > currentSma && currentPrice < currentSma) {
|
||||||
await this.submitMarketOrder("SELL", currentPrice, "下穿SMA30,市价开空");
|
await this.submitMarketOrder("SELL", currentPrice, "下穿SMA30,市价开空");
|
||||||
} else if (this.lastPrice < currentSma && currentPrice > currentSma) {
|
} else if (this.lastPrice < currentSma && currentPrice > currentSma) {
|
||||||
@@ -327,7 +331,7 @@ export class TrendEngine {
|
|||||||
this.timers,
|
this.timers,
|
||||||
this.pending,
|
this.pending,
|
||||||
direction === "long" ? "SELL" : "BUY",
|
direction === "long" ? "SELL" : "BUY",
|
||||||
this.config.tradeAmount,
|
Math.abs(position.positionAmt),
|
||||||
(type, detail) => this.tradeLog.push(type, detail)
|
(type, detail) => this.tradeLog.push(type, detail)
|
||||||
);
|
);
|
||||||
this.tradeLog.push("close", `止损平仓: ${direction === "long" ? "SELL" : "BUY"}`);
|
this.tradeLog.push("close", `止损平仓: ${direction === "long" ? "SELL" : "BUY"}`);
|
||||||
@@ -350,6 +354,8 @@ export class TrendEngine {
|
|||||||
lastPrice: number
|
lastPrice: number
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
try {
|
try {
|
||||||
|
const position = getPosition(this.accountSnapshot, this.config.symbol);
|
||||||
|
const quantity = Math.abs(position.positionAmt) || this.config.tradeAmount;
|
||||||
await placeStopLossOrder(
|
await placeStopLossOrder(
|
||||||
this.exchange,
|
this.exchange,
|
||||||
this.config.symbol,
|
this.config.symbol,
|
||||||
@@ -359,7 +365,7 @@ export class TrendEngine {
|
|||||||
this.pending,
|
this.pending,
|
||||||
side,
|
side,
|
||||||
stopPrice,
|
stopPrice,
|
||||||
this.config.tradeAmount,
|
quantity,
|
||||||
lastPrice,
|
lastPrice,
|
||||||
(type, detail) => this.tradeLog.push(type, detail)
|
(type, detail) => this.tradeLog.push(type, detail)
|
||||||
);
|
);
|
||||||
|
|||||||
+2
-2
@@ -77,7 +77,7 @@ export function TrendApp({ onExit }: TrendAppProps) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { position, tradeLog, openOrders, trend, ready, lastPrice, sma30 } = snapshot;
|
const { position, tradeLog, openOrders, trend, ready, lastPrice, sma30, sessionVolume } = snapshot;
|
||||||
const hasPosition = Math.abs(position.positionAmt) > 1e-5;
|
const hasPosition = Math.abs(position.positionAmt) > 1e-5;
|
||||||
const lastLogs = tradeLog.slice(-5);
|
const lastLogs = tradeLog.slice(-5);
|
||||||
const sortedOrders = [...openOrders].sort((a, b) => (Number(b.updateTime ?? 0) - Number(a.updateTime ?? 0)) || Number(b.orderId) - Number(a.orderId));
|
const sortedOrders = [...openOrders].sort((a, b) => (Number(b.updateTime ?? 0) - Number(a.updateTime ?? 0)) || Number(b.orderId) - Number(a.orderId));
|
||||||
@@ -132,7 +132,7 @@ export function TrendApp({ onExit }: TrendAppProps) {
|
|||||||
累计交易次数: {snapshot.totalTrades} | 累计收益: {formatNumber(snapshot.totalProfit, 4)} USDT
|
累计交易次数: {snapshot.totalTrades} | 累计收益: {formatNumber(snapshot.totalProfit, 4)} USDT
|
||||||
</Text>
|
</Text>
|
||||||
<Text>
|
<Text>
|
||||||
累计成交量: {formatNumber(snapshot.sessionVolume, 2)} USDT
|
累计成交量: {formatNumber(sessionVolume, 2)} USDT
|
||||||
</Text>
|
</Text>
|
||||||
{snapshot.lastOpenSignal.side ? (
|
{snapshot.lastOpenSignal.side ? (
|
||||||
<Text color="gray">
|
<Text color="gray">
|
||||||
|
|||||||
Reference in New Issue
Block a user