mirror of
https://github.com/discountry/ritmex-bot.git
synced 2026-09-12 09:48:07 +00:00
- 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.
43 lines
1.1 KiB
TypeScript
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 };
|
|
}
|
|
|
|
|