Files
ritmex-bot/src/utils/depth.ts
T
discountry fda6bcad1d refactor: rename Aster-prefixed universal types to clean names
- AsterOrder → Order
- AsterAccountSnapshot → AccountSnapshot
- AsterAccountPosition → AccountPosition
- AsterAccountAsset → AccountAsset
- AsterDepthLevel → DepthLevel
- AsterDepth → Depth
- AsterTicker → Ticker
- AsterKline → Kline

These types are the platform-agnostic contract used by all 8 exchanges,
not Aster-specific. Renamed across 63 files.
2026-04-06 18:11:57 +08:00

43 lines
1.1 KiB
TypeScript

import type { Depth } from "../exchanges/types";
export type DepthImbalance = "balanced" | "buy_dominant" | "sell_dominant";
export function computeDepthStats(
depth: Depth,
levels = 10,
ratio = 3
): {
buySum: number;
sellSum: number;
skipBuySide: boolean;
skipSellSide: boolean;
imbalance: DepthImbalance;
} {
const topBids = (depth.bids ?? []).slice(0, levels);
const topAsks = (depth.asks ?? []).slice(0, levels);
const buySum = topBids.reduce((total, level) => {
const qty = Number(level?.[1]);
return Number.isFinite(qty) ? total + qty : total;
}, 0);
const sellSum = topAsks.reduce((total, level) => {
const qty = Number(level?.[1]);
return Number.isFinite(qty) ? total + qty : total;
}, 0);
const skipSellSide = sellSum === 0 || sellSum * ratio < buySum;
const skipBuySide = buySum === 0 || buySum * ratio < sellSum;
let imbalance: DepthImbalance = "balanced";
if (buySum > sellSum * ratio) {
imbalance = "buy_dominant";
} else if (sellSum > buySum * ratio) {
imbalance = "sell_dominant";
}
return { buySum, sellSum, skipBuySide, skipSellSide, imbalance };
}