mirror of
https://github.com/discountry/ritmex-bot.git
synced 2026-09-11 09:18:08 +00:00
feat: 优化 Lighter 适配器的账户消息处理逻辑,支持部分更新和市场订单类型的处理
This commit is contained in:
@@ -566,9 +566,14 @@ export class LighterGateway {
|
|||||||
|
|
||||||
private handleAccountAll(message: any): void {
|
private handleAccountAll(message: any): void {
|
||||||
if (!message) return;
|
if (!message) return;
|
||||||
|
// account_all messages may be partial updates; if positions is omitted, retain existing positions
|
||||||
|
if (Object.prototype.hasOwnProperty.call(message, "positions")) {
|
||||||
const positionsObject = message.positions ?? {};
|
const positionsObject = message.positions ?? {};
|
||||||
const positions: LighterPosition[] = Object.values(positionsObject) as LighterPosition[];
|
const positions: LighterPosition[] = (Array.isArray(positionsObject)
|
||||||
|
? (positionsObject as LighterPosition[])
|
||||||
|
: (Object.values(positionsObject) as LighterPosition[])) as LighterPosition[];
|
||||||
this.positions = positions;
|
this.positions = positions;
|
||||||
|
}
|
||||||
this.emitAccount();
|
this.emitAccount();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -727,7 +732,7 @@ export class LighterGateway {
|
|||||||
const baseAmountScaledString = scaledToDecimalString(baseAmount, this.sizeDecimals);
|
const baseAmountScaledString = scaledToDecimalString(baseAmount, this.sizeDecimals);
|
||||||
const clientOrderIndex = BigInt(Date.now() % Number.MAX_SAFE_INTEGER);
|
const clientOrderIndex = BigInt(Date.now() % Number.MAX_SAFE_INTEGER);
|
||||||
let priceScaled = params.price != null ? decimalToScaled(params.price, this.priceDecimals) : null;
|
let priceScaled = params.price != null ? decimalToScaled(params.price, this.priceDecimals) : null;
|
||||||
if (params.type === "MARKET" && priceScaled == null) {
|
if ((params.type === "MARKET" || params.type === "STOP_MARKET") && priceScaled == null) {
|
||||||
priceScaled = decimalToScaled(this.estimateMarketPrice(side), this.priceDecimals);
|
priceScaled = decimalToScaled(this.estimateMarketPrice(side), this.priceDecimals);
|
||||||
}
|
}
|
||||||
if (priceScaled == null) {
|
if (priceScaled == null) {
|
||||||
@@ -840,7 +845,12 @@ function mapOrderType(type: OrderType): number {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function mapTimeInForce(timeInForce: string | undefined, type: OrderType): number {
|
function mapTimeInForce(timeInForce: string | undefined, type: OrderType): number {
|
||||||
const value = (timeInForce ?? (type === "MARKET" ? "IOC" : "GTC")).toUpperCase();
|
// Lighter expects STOP orders to be immediate-or-cancel at trigger time.
|
||||||
|
// Force IOC for MARKET and STOP_MARKET to satisfy chain validation.
|
||||||
|
if (type === "MARKET" || type === "STOP_MARKET") {
|
||||||
|
return LIGHTER_TIME_IN_FORCE.IMMEDIATE_OR_CANCEL;
|
||||||
|
}
|
||||||
|
const value = (timeInForce ?? "GTC").toUpperCase();
|
||||||
switch (value) {
|
switch (value) {
|
||||||
case "IOC":
|
case "IOC":
|
||||||
return LIGHTER_TIME_IN_FORCE.IMMEDIATE_OR_CANCEL;
|
return LIGHTER_TIME_IN_FORCE.IMMEDIATE_OR_CANCEL;
|
||||||
|
|||||||
Reference in New Issue
Block a user