mirror of
https://github.com/discountry/ritmex-bot.git
synced 2026-09-10 08:48:07 +00:00
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.
This commit is contained in:
@@ -7,7 +7,7 @@ import type {
|
||||
OrderListener,
|
||||
TickerListener,
|
||||
} from "../adapter";
|
||||
import type { AsterOrder, CreateOrderParams } from "../types";
|
||||
import type { Order, CreateOrderParams } from "../types";
|
||||
import { extractMessage } from "../../utils/errors";
|
||||
import { LighterGateway, type LighterGatewayOptions } from "./gateway";
|
||||
|
||||
@@ -102,7 +102,7 @@ export class LighterExchangeAdapter implements ExchangeAdapter {
|
||||
this.gateway.watchKlines(interval, handler);
|
||||
}
|
||||
|
||||
async createOrder(params: CreateOrderParams): Promise<AsterOrder> {
|
||||
async createOrder(params: CreateOrderParams): Promise<Order> {
|
||||
await this.ensureInitialized("createOrder");
|
||||
return this.gateway.createOrder(params);
|
||||
}
|
||||
|
||||
@@ -8,12 +8,12 @@ import type {
|
||||
TickerListener,
|
||||
} from "../adapter";
|
||||
import type {
|
||||
AsterAccountAsset,
|
||||
AsterAccountSnapshot,
|
||||
AsterDepth,
|
||||
AsterKline,
|
||||
AsterOrder,
|
||||
AsterTicker,
|
||||
AccountAsset,
|
||||
AccountSnapshot,
|
||||
Depth,
|
||||
Kline,
|
||||
Order,
|
||||
Ticker,
|
||||
CreateOrderParams,
|
||||
} from "../types";
|
||||
import type { OrderSide, OrderType } from "../types";
|
||||
@@ -189,12 +189,12 @@ export class LighterGateway {
|
||||
private accountPollInFlight = false;
|
||||
private ordersResyncTimer: ReturnType<typeof setInterval> | null = null;
|
||||
private ordersResyncInFlight = false;
|
||||
private readonly klineCache = new Map<string, AsterKline[]>();
|
||||
private readonly accountEvent = createEvent<AsterAccountSnapshot>();
|
||||
private readonly ordersEvent = createEvent<AsterOrder[]>();
|
||||
private readonly depthEvent = createEvent<AsterDepth>();
|
||||
private readonly tickerEvent = createEvent<AsterTicker>();
|
||||
private readonly klinesEvent = createEvent<AsterKline[]>();
|
||||
private readonly klineCache = new Map<string, Kline[]>();
|
||||
private readonly accountEvent = createEvent<AccountSnapshot>();
|
||||
private readonly ordersEvent = createEvent<Order[]>();
|
||||
private readonly depthEvent = createEvent<Depth>();
|
||||
private readonly tickerEvent = createEvent<Ticker>();
|
||||
private readonly klinesEvent = createEvent<Kline[]>();
|
||||
private readonly auth = { token: null as string | null, expiresAt: 0 };
|
||||
private readonly l1Address: string | null;
|
||||
private loggedCreateOrderPayload = false;
|
||||
@@ -359,8 +359,8 @@ export class LighterGateway {
|
||||
this.klinesEvent.add(handler);
|
||||
}
|
||||
|
||||
async createOrder(params: CreateOrderParams): Promise<AsterOrder> {
|
||||
const run = async (): Promise<AsterOrder> => {
|
||||
async createOrder(params: CreateOrderParams): Promise<Order> {
|
||||
const run = async (): Promise<Order> => {
|
||||
await this.ensureInitialized();
|
||||
const conversion = this.mapCreateOrderParams(params);
|
||||
const { baseAmountScaledString, priceScaledString, triggerPriceScaledString, ...signParams } = conversion;
|
||||
@@ -1710,7 +1710,7 @@ export class LighterGateway {
|
||||
const bestAsk = getBestPrice(this.orderBook.asks, "ask");
|
||||
if (bestBid == null && bestAsk == null) return;
|
||||
const last = bestBid != null && bestAsk != null ? (bestBid + bestAsk) / 2 : (bestBid ?? bestAsk ?? 0);
|
||||
const ticker: AsterTicker = {
|
||||
const ticker: Ticker = {
|
||||
symbol: this.displaySymbol,
|
||||
eventType: "lighterSyntheticTicker",
|
||||
eventTime: Date.now(),
|
||||
@@ -1736,10 +1736,10 @@ export class LighterGateway {
|
||||
this.tickerEvent.emit(ticker);
|
||||
}
|
||||
|
||||
private buildAccountAssets(): AsterAccountAsset[] {
|
||||
private buildAccountAssets(): AccountAsset[] {
|
||||
if (!this.assets.size) return [];
|
||||
const now = Date.now();
|
||||
const list: AsterAccountAsset[] = [];
|
||||
const list: AccountAsset[] = [];
|
||||
for (const asset of this.assets.values()) {
|
||||
const balanceNum = parseNumber(asset.balance);
|
||||
const lockedNum = parseNumber(asset.locked_balance ?? 0);
|
||||
@@ -2039,7 +2039,7 @@ function mergeLevels(existing: LighterOrderBookLevel[], updates: LighterOrderBoo
|
||||
return Array.from(map.entries()).map(([price, size]) => ({ price, size } as LighterOrderBookLevel));
|
||||
}
|
||||
|
||||
function cloneKlines(klines: AsterKline[]): AsterKline[] {
|
||||
function cloneKlines(klines: Kline[]): Kline[] {
|
||||
return klines.map((kline) => ({ ...kline }));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import type {
|
||||
AsterAccountAsset,
|
||||
AsterAccountPosition,
|
||||
AsterAccountSnapshot,
|
||||
AsterDepth,
|
||||
AsterDepthLevel,
|
||||
AsterKline,
|
||||
AsterOrder,
|
||||
AsterTicker,
|
||||
AccountAsset,
|
||||
AccountPosition,
|
||||
AccountSnapshot,
|
||||
Depth,
|
||||
DepthLevel,
|
||||
Kline,
|
||||
Order,
|
||||
Ticker,
|
||||
OrderSide,
|
||||
OrderType,
|
||||
} from "../types";
|
||||
@@ -23,8 +23,8 @@ import { coerceBooleanFlag, normalizeBooleanFlag } from "./flags";
|
||||
import { normalizeOrderIdentity } from "./order-identity";
|
||||
import { normalizeOrderStatus } from "./status";
|
||||
|
||||
export function toDepth(symbol: string, snapshot: LighterOrderBookSnapshot): AsterDepth {
|
||||
const toLevels = (levels: LighterOrderBookLevel[]): AsterDepthLevel[] =>
|
||||
export function toDepth(symbol: string, snapshot: LighterOrderBookSnapshot): Depth {
|
||||
const toLevels = (levels: LighterOrderBookLevel[]): DepthLevel[] =>
|
||||
levels.map((level) => [level.price, level.size]);
|
||||
return {
|
||||
symbol,
|
||||
@@ -36,7 +36,7 @@ export function toDepth(symbol: string, snapshot: LighterOrderBookSnapshot): Ast
|
||||
};
|
||||
}
|
||||
|
||||
export function toTicker(symbol: string, stats: LighterMarketStats): AsterTicker {
|
||||
export function toTicker(symbol: string, stats: LighterMarketStats): Ticker {
|
||||
return {
|
||||
symbol,
|
||||
eventType: "lighterTicker",
|
||||
@@ -50,10 +50,10 @@ export function toTicker(symbol: string, stats: LighterMarketStats): AsterTicker
|
||||
priceChange: stats.daily_price_change != null ? String(stats.daily_price_change) : undefined,
|
||||
markPrice: stats.mid_price ?? stats.mark_price ?? stats.index_price,
|
||||
weightedAvgPrice: undefined,
|
||||
} as AsterTicker;
|
||||
} as Ticker;
|
||||
}
|
||||
|
||||
export function toKlines(symbol: string, interval: string, klines: LighterKline[]): AsterKline[] {
|
||||
export function toKlines(symbol: string, interval: string, klines: LighterKline[]): Kline[] {
|
||||
return klines.map((entry) => ({
|
||||
symbol,
|
||||
eventType: "lighterKline",
|
||||
@@ -72,11 +72,11 @@ export function toKlines(symbol: string, interval: string, klines: LighterKline[
|
||||
}));
|
||||
}
|
||||
|
||||
export function toOrders(symbol: string, orders: LighterOrder[]): AsterOrder[] {
|
||||
export function toOrders(symbol: string, orders: LighterOrder[]): Order[] {
|
||||
return orders.map((order) => lighterOrderToAster(symbol, order));
|
||||
}
|
||||
|
||||
export function lighterOrderToAster(symbol: string, order: LighterOrder): AsterOrder {
|
||||
export function lighterOrderToAster(symbol: string, order: LighterOrder): Order {
|
||||
const booleanIsAsk = normalizeBooleanFlag(order.is_ask);
|
||||
const normalizedSide = order.side?.toLowerCase();
|
||||
const side: OrderSide =
|
||||
@@ -162,7 +162,7 @@ export function toAccountSnapshot(
|
||||
symbol: string,
|
||||
details: LighterAccountDetails,
|
||||
positions: LighterPosition[] = [],
|
||||
assets: AsterAccountAsset[] = [],
|
||||
assets: AccountAsset[] = [],
|
||||
options?: {
|
||||
marketSymbol?: string | null;
|
||||
marketId?: number | null;
|
||||
@@ -172,7 +172,7 @@ export function toAccountSnapshot(
|
||||
baseAssetId?: number | null;
|
||||
quoteAssetId?: number | null;
|
||||
}
|
||||
): AsterAccountSnapshot {
|
||||
): AccountSnapshot {
|
||||
const targetSymbol = options?.marketSymbol ?? null;
|
||||
const targetMarketId =
|
||||
options?.marketId != null && Number.isFinite(Number(options.marketId))
|
||||
@@ -228,7 +228,7 @@ export function toAccountSnapshot(
|
||||
};
|
||||
}
|
||||
|
||||
function defaultAsset(details: LighterAccountDetails, quoteAsset: string): AsterAccountAsset[] {
|
||||
function defaultAsset(details: LighterAccountDetails, quoteAsset: string): AccountAsset[] {
|
||||
return [
|
||||
{
|
||||
asset: quoteAsset || "USDC",
|
||||
@@ -239,7 +239,7 @@ function defaultAsset(details: LighterAccountDetails, quoteAsset: string): Aster
|
||||
];
|
||||
}
|
||||
|
||||
function computeTotalWalletBalance(assets: AsterAccountAsset[], details: LighterAccountDetails): string {
|
||||
function computeTotalWalletBalance(assets: AccountAsset[], details: LighterAccountDetails): string {
|
||||
const sum = assets.reduce((acc, asset) => acc + Number(asset.walletBalance ?? 0), 0);
|
||||
if (Number.isFinite(sum) && sum > 0) {
|
||||
return sum.toString();
|
||||
@@ -247,7 +247,7 @@ function computeTotalWalletBalance(assets: AsterAccountAsset[], details: Lighter
|
||||
return details.total_asset_value ?? details.collateral ?? "0";
|
||||
}
|
||||
|
||||
function findAsset(assets: AsterAccountAsset[], target: string | undefined | null): AsterAccountAsset | undefined {
|
||||
function findAsset(assets: AccountAsset[], target: string | undefined | null): AccountAsset | undefined {
|
||||
if (!target) return undefined;
|
||||
const normalizedTarget = target.toUpperCase().split(/[-:/]/)[0];
|
||||
return assets.find((asset) => asset.asset.toUpperCase().split(/[-:/]/)[0] === normalizedTarget);
|
||||
@@ -261,7 +261,7 @@ function normalizeMarketType(value: string | null | undefined): "perp" | "spot"
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function lighterPositionToAster(symbol: string, position: LighterPosition): AsterAccountPosition {
|
||||
function lighterPositionToAster(symbol: string, position: LighterPosition): AccountPosition {
|
||||
const sign = position.sign ?? 0;
|
||||
const positionSide = sign > 0 ? "LONG" : sign < 0 ? "SHORT" : "BOTH";
|
||||
const magnitude = Number(position.position ?? 0);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { AsterOrder, CreateOrderParams } from "../types";
|
||||
import type { Order, CreateOrderParams } from "../types";
|
||||
import type {
|
||||
BaseOrderIntent,
|
||||
ClosePositionIntent,
|
||||
@@ -25,7 +25,7 @@ function applyCommonFields(params: CreateOrderParams, intent: BaseOrderIntent):
|
||||
return params;
|
||||
}
|
||||
|
||||
export async function createLimitOrder(intent: LimitOrderIntent): Promise<AsterOrder> {
|
||||
export async function createLimitOrder(intent: LimitOrderIntent): Promise<Order> {
|
||||
const params: CreateOrderParams = applyCommonFields(
|
||||
{
|
||||
symbol: intent.symbol,
|
||||
@@ -40,7 +40,7 @@ export async function createLimitOrder(intent: LimitOrderIntent): Promise<AsterO
|
||||
return intent.adapter.createOrder(params);
|
||||
}
|
||||
|
||||
export async function createMarketOrder(intent: MarketOrderIntent): Promise<AsterOrder> {
|
||||
export async function createMarketOrder(intent: MarketOrderIntent): Promise<Order> {
|
||||
const params: CreateOrderParams = applyCommonFields(
|
||||
{
|
||||
symbol: intent.symbol,
|
||||
@@ -54,7 +54,7 @@ export async function createMarketOrder(intent: MarketOrderIntent): Promise<Aste
|
||||
return intent.adapter.createOrder(params);
|
||||
}
|
||||
|
||||
export async function createStopOrder(intent: StopOrderIntent): Promise<AsterOrder> {
|
||||
export async function createStopOrder(intent: StopOrderIntent): Promise<Order> {
|
||||
const params: CreateOrderParams = applyCommonFields(
|
||||
{
|
||||
symbol: intent.symbol,
|
||||
@@ -71,11 +71,11 @@ export async function createStopOrder(intent: StopOrderIntent): Promise<AsterOrd
|
||||
return intent.adapter.createOrder(params);
|
||||
}
|
||||
|
||||
export async function createTrailingStopOrder(_intent: TrailingStopOrderIntent): Promise<AsterOrder> {
|
||||
export async function createTrailingStopOrder(_intent: TrailingStopOrderIntent): Promise<Order> {
|
||||
throw new Error("Lighter exchange does not support trailing stop orders");
|
||||
}
|
||||
|
||||
export async function createClosePositionOrder(intent: ClosePositionIntent): Promise<AsterOrder> {
|
||||
export async function createClosePositionOrder(intent: ClosePositionIntent): Promise<Order> {
|
||||
const params: CreateOrderParams = applyCommonFields(
|
||||
{
|
||||
symbol: intent.symbol,
|
||||
|
||||
Reference in New Issue
Block a user