mirror of
https://github.com/discountry/ritmex-bot.git
synced 2026-09-10 16:58:08 +00:00
Enhance entry price logic in Maker and Liquidity Maker strategies
- Added `entryDepthLevel` configuration option to `MakerConfig` and `LiquidityMakerConfig` for specifying order entry levels. - Implemented `getPricesAtLevel` utility function to retrieve bid and ask prices at specified depth levels. - Updated `MakerEngine`, `LiquidityMakerEngine`, and `OffsetMakerEngine` to utilize the new entry level logic for determining opening prices based on market depth. - Improved price handling to ensure more accurate order placements in varying market conditions.
This commit is contained in:
@@ -14,7 +14,7 @@ import { isOrderActiveStatus } from "../utils/order-status";
|
||||
import { getPosition } from "../utils/strategy";
|
||||
import type { PositionSnapshot } from "../utils/strategy";
|
||||
import { computePositionPnl } from "../utils/pnl";
|
||||
import { getTopPrices, getMidOrLast } from "../utils/price";
|
||||
import { getTopPrices, getPricesAtLevel, getMidOrLast } from "../utils/price";
|
||||
import { shouldStopLoss } from "../utils/risk";
|
||||
import {
|
||||
marketClose,
|
||||
@@ -305,10 +305,18 @@ export class MakerEngine {
|
||||
|
||||
// 直接使用orderbook价格,格式化为字符串避免精度问题
|
||||
const priceDecimals = this.getPriceDecimals();
|
||||
// 平仓价格始终使用买1/卖1
|
||||
const closeBidPrice = formatPriceToString(topBid, priceDecimals);
|
||||
const closeAskPrice = formatPriceToString(topAsk, priceDecimals);
|
||||
const bidPrice = formatPriceToString(topBid - this.config.bidOffset, priceDecimals);
|
||||
const askPrice = formatPriceToString(topAsk + this.config.askOffset, priceDecimals);
|
||||
|
||||
// 开仓价格根据 entryDepthLevel 使用指定档位
|
||||
const entryLevel = this.config.entryDepthLevel ?? 1;
|
||||
const { bidAtLevel: entryBid, askAtLevel: entryAsk } = getPricesAtLevel(depth, entryLevel);
|
||||
const entryBidBase = entryBid ?? topBid;
|
||||
const entryAskBase = entryAsk ?? topAsk;
|
||||
|
||||
const bidPrice = formatPriceToString(entryBidBase - this.config.bidOffset, priceDecimals);
|
||||
const askPrice = formatPriceToString(entryAskBase + this.config.askOffset, priceDecimals);
|
||||
const position = getPosition(this.accountSnapshot, this.config.symbol);
|
||||
const absPosition = Math.abs(position.positionAmt);
|
||||
const desired: DesiredOrder[] = [];
|
||||
|
||||
Reference in New Issue
Block a user