Enhance MakerPoints functionality and configuration

- Updated `filterMinDepth` in `config.ts` from 1 to 50 to improve depth filtering logic.
- Added new translation entries for band depth display in `i18n/index.ts`.
- Introduced `bandDepths` to `MakerPointsSnapshot` in `maker-points-engine.ts` to track depth across different bands.
- Enhanced `BinanceDepthTracker` to support dynamic depth levels and speed settings.
- Updated `MakerPointsApp` to display band depth information, improving user interface clarity.
This commit is contained in:
discountry
2026-01-22 02:27:45 +08:00
parent ed855f6859
commit 24339929dc
5 changed files with 52 additions and 5 deletions
+2 -2
View File
@@ -199,7 +199,7 @@ export interface MakerPointsConfig {
minRepriceBps: number; minRepriceBps: number;
/** 是否根据 Binance 盘口深度失衡自动取消单边挂单,默认 true */ /** 是否根据 Binance 盘口深度失衡自动取消单边挂单,默认 true */
enableBinanceDepthCancel: boolean; enableBinanceDepthCancel: boolean;
/** 各档位最小深度阈值 (BTC),盘口到目标价之间的挂单量低于此值则跳过该档位,默认 1 */ /** 各档位最小深度阈值 (BTC),盘口到目标价之间的挂单量低于此值则跳过该档位,默认 50 */
filterMinDepth: number; filterMinDepth: number;
} }
@@ -226,7 +226,7 @@ export const makerPointsConfig: MakerPointsConfig = {
band30To100Amount: parseNumber(process.env.MAKER_POINTS_BAND_30_100_AMOUNT, defaultMakerPointsAmount), band30To100Amount: parseNumber(process.env.MAKER_POINTS_BAND_30_100_AMOUNT, defaultMakerPointsAmount),
minRepriceBps: parseNumber(process.env.MAKER_POINTS_MIN_REPRICE_BPS, 3), minRepriceBps: parseNumber(process.env.MAKER_POINTS_MIN_REPRICE_BPS, 3),
enableBinanceDepthCancel: parseBoolean(process.env.MAKER_POINTS_BINANCE_DEPTH_CANCEL, true), enableBinanceDepthCancel: parseBoolean(process.env.MAKER_POINTS_BINANCE_DEPTH_CANCEL, true),
filterMinDepth: parseNumber(process.env.MAKER_POINTS_FILTER_MIN_DEPTH, 1), filterMinDepth: parseNumber(process.env.MAKER_POINTS_FILTER_MIN_DEPTH, 50),
}; };
export interface BasisArbConfig { export interface BasisArbConfig {
+4
View File
@@ -202,6 +202,10 @@ const translations: Record<string, TranslationEntry> = {
zh: "Binance 深度: 买10 {buy} 卖10 {sell} 状态: {status}", zh: "Binance 深度: 买10 {buy} 卖10 {sell} 状态: {status}",
en: "Binance depth: bid10 {buy} | ask10 {sell} | Status: {status}", en: "Binance depth: bid10 {buy} | ask10 {sell} | Status: {status}",
}, },
"makerPoints.bandDepthLine": {
zh: "StandX 档位 {band}bps 深度: 买 {buy} 卖 {sell}",
en: "StandX band {band}bps depth: buy {buy} | sell {sell}",
},
"makerPoints.mode.closeOnly": { zh: "平仓", en: "Close only" }, "makerPoints.mode.closeOnly": { zh: "平仓", en: "Close only" },
"makerPoints.mode.normal": { zh: "正常", en: "Normal" }, "makerPoints.mode.normal": { zh: "正常", en: "Normal" },
"makerPoints.feed.binance": { zh: "Binance", en: "Binance" }, "makerPoints.feed.binance": { zh: "Binance", en: "Binance" },
+4 -1
View File
@@ -65,6 +65,7 @@ export class BinanceDepthTracker {
baseUrl?: string; baseUrl?: string;
levels?: number; levels?: number;
ratio?: number; ratio?: number;
speedMs?: number;
logger?: (context: string, error: unknown) => void; logger?: (context: string, error: unknown) => void;
} }
) {} ) {}
@@ -229,7 +230,9 @@ export class BinanceDepthTracker {
private buildUrl(): string { private buildUrl(): string {
const base = this.options?.baseUrl ?? DEFAULT_BASE_URL; const base = this.options?.baseUrl ?? DEFAULT_BASE_URL;
const stream = `${this.symbol.toLowerCase()}@depth10@100ms`; const levels = this.options?.levels ?? 10;
const speed = this.options?.speedMs ?? 100;
const stream = `${this.symbol.toLowerCase()}@depth${levels}@${speed}ms`;
return `${base}/${stream}`; return `${base}/${stream}`;
} }
+32 -2
View File
@@ -71,6 +71,13 @@ export interface MakerPointsSnapshot {
binance: boolean; binance: boolean;
}; };
binanceDepth: BinanceDepthSnapshot | null; binanceDepth: BinanceDepthSnapshot | null;
bandDepths: Array<{
band: "0-10" | "10-30" | "30-100";
bps: number;
buyDepth: number | null;
sellDepth: number | null;
enabled: boolean;
}>;
quoteStatus: { quoteStatus: {
closeOnly: boolean; closeOnly: boolean;
skipBuy: boolean; skipBuy: boolean;
@@ -184,8 +191,9 @@ export class MakerPointsEngine {
this.qtyStep = Math.max(1e-9, this.config.qtyStep); this.qtyStep = Math.max(1e-9, this.config.qtyStep);
this.binanceDepth = new BinanceDepthTracker(resolveBinanceSymbol(this.config.symbol), { this.binanceDepth = new BinanceDepthTracker(resolveBinanceSymbol(this.config.symbol), {
baseUrl: process.env.BINANCE_WS_URL, baseUrl: process.env.BINANCE_WS_URL,
levels: 10, levels: 20,
ratio: 3, ratio: 5,
speedMs: 500,
logger: (context, error) => { logger: (context, error) => {
this.tradeLog.push("warn", `Binance ${context} 异常: ${extractMessage(error)}`); this.tradeLog.push("warn", `Binance ${context} 异常: ${extractMessage(error)}`);
}, },
@@ -1190,6 +1198,7 @@ export class MakerPointsEngine {
const { topBid, topAsk } = getTopPrices(this.depthSnapshot); const { topBid, topAsk } = getTopPrices(this.depthSnapshot);
const spread = topBid != null && topAsk != null ? topAsk - topBid : null; const spread = topBid != null && topAsk != null ? topAsk - topBid : null;
const pnl = computePositionPnl(position, topBid, topAsk); const pnl = computePositionPnl(position, topBid, topAsk);
const bandDepths = this.computeBandDepths(topBid, topAsk);
return { return {
ready: this.isReady(), ready: this.isReady(),
@@ -1208,6 +1217,7 @@ export class MakerPointsEngine {
lastUpdated: Date.now(), lastUpdated: Date.now(),
feedStatus: { ...this.feedStatus }, feedStatus: { ...this.feedStatus },
binanceDepth: this.binanceDepth.getSnapshot(), binanceDepth: this.binanceDepth.getSnapshot(),
bandDepths,
quoteStatus: { quoteStatus: {
closeOnly: this.lastCloseOnly, closeOnly: this.lastCloseOnly,
skipBuy: this.lastSkipBuy, skipBuy: this.lastSkipBuy,
@@ -1216,6 +1226,26 @@ export class MakerPointsEngine {
}; };
} }
private computeBandDepths(topBid: number | null, topAsk: number | null): MakerPointsSnapshot["bandDepths"] {
const bands: MakerPointsSnapshot["bandDepths"] = [
{ band: "0-10", bps: 9, buyDepth: null, sellDepth: null, enabled: this.config.enableBand0To10 },
{ band: "10-30", bps: 29, buyDepth: null, sellDepth: null, enabled: this.config.enableBand10To30 },
{ band: "30-100", bps: 99, buyDepth: null, sellDepth: null, enabled: this.config.enableBand30To100 },
];
if (!this.depthSnapshot || topBid == null || topAsk == null) {
return bands;
}
return bands.map((band) => {
const buyPrice = topBid * (1 - band.bps / 10000);
const sellPrice = topAsk * (1 + band.bps / 10000);
const buyDepth = getDepthBetweenPrices(this.depthSnapshot, "BUY", buyPrice);
const sellDepth = getDepthBetweenPrices(this.depthSnapshot, "SELL", sellPrice);
return { ...band, buyDepth, sellDepth };
});
}
private getReferencePrice(): number | null { private getReferencePrice(): number | null {
return getMidOrLast(this.depthSnapshot, this.tickerSnapshot); return getMidOrLast(this.depthSnapshot, this.tickerSnapshot);
} }
+10
View File
@@ -135,6 +135,7 @@ export function MakerPointsApp({ onExit }: MakerPointsAppProps) {
? t("offset.imbalance.sell") ? t("offset.imbalance.sell")
: t("offset.imbalance.balanced"); : t("offset.imbalance.balanced");
const quoteMode = snapshot.quoteStatus.closeOnly ? t("makerPoints.mode.closeOnly") : t("makerPoints.mode.normal"); const quoteMode = snapshot.quoteStatus.closeOnly ? t("makerPoints.mode.closeOnly") : t("makerPoints.mode.normal");
const formatDepth = (value: number | null) => (value == null ? "-" : formatNumber(value, 4));
return ( return (
<Box flexDirection="column" paddingX={1}> <Box flexDirection="column" paddingX={1}>
@@ -164,6 +165,15 @@ export function MakerPointsApp({ onExit }: MakerPointsAppProps) {
status: imbalanceLabel, status: imbalanceLabel,
})} })}
</Text> </Text>
{snapshot.bandDepths.map((band) => (
<Text key={band.band} color={band.enabled ? undefined : "gray"}>
{t("makerPoints.bandDepthLine", {
band: band.band,
buy: formatDepth(band.buyDepth),
sell: formatDepth(band.sellDepth),
})}
</Text>
))}
<Text> <Text>
{t("maker.dataStatus")} {t("maker.dataStatus")}
{feedEntries.map((entry, index) => ( {feedEntries.map((entry, index) => (