feat: 添加 Lighter 适配器及相关功能,支持 trailing stops 和新的交易逻辑

This commit is contained in:
discountry
2025-09-30 22:08:05 +08:00
parent e83bdfccf9
commit c8b0ab1c8e
101 changed files with 90621 additions and 3 deletions
+10 -2
View File
@@ -1,15 +1,17 @@
import type { ExchangeAdapter } from "./adapter";
import { AsterExchangeAdapter, type AsterCredentials } from "./aster-adapter";
import { GrvtExchangeAdapter, type GrvtCredentials } from "./grvt/adapter";
import { LighterExchangeAdapter, type LighterCredentials } from "./lighter/adapter";
export interface ExchangeFactoryOptions {
symbol: string;
exchange?: string;
aster?: AsterCredentials;
grvt?: GrvtCredentials;
lighter?: LighterCredentials;
}
export type SupportedExchangeId = "aster" | "grvt";
export type SupportedExchangeId = "aster" | "grvt" | "lighter";
export function resolveExchangeId(value?: string | null): SupportedExchangeId {
const fallback = (value ?? process.env.EXCHANGE ?? process.env.TRADE_EXCHANGE ?? "aster")
@@ -17,11 +19,14 @@ export function resolveExchangeId(value?: string | null): SupportedExchangeId {
.trim()
.toLowerCase();
if (fallback === "grvt") return "grvt";
if (fallback === "lighter") return "lighter";
return "aster";
}
export function getExchangeDisplayName(id: SupportedExchangeId): string {
return id === "grvt" ? "GRVT" : "AsterDex";
if (id === "grvt") return "GRVT";
if (id === "lighter") return "Lighter";
return "AsterDex";
}
export function createExchangeAdapter(options: ExchangeFactoryOptions): ExchangeAdapter {
@@ -29,5 +34,8 @@ export function createExchangeAdapter(options: ExchangeFactoryOptions): Exchange
if (id === "grvt") {
return new GrvtExchangeAdapter({ ...options.grvt, symbol: options.symbol });
}
if (id === "lighter") {
return new LighterExchangeAdapter({ ...options.lighter, displaySymbol: options.symbol });
}
return new AsterExchangeAdapter({ ...options.aster, symbol: options.symbol });
}