feat: 添加 Paradex 适配器支持,更新环境变量配置和适配器构建逻辑

This commit is contained in:
discountry
2025-10-06 18:06:23 +08:00
parent ccc3a2bf89
commit cfd5f4309d
18 changed files with 1681 additions and 177 deletions
+3 -51
View File
@@ -1,10 +1,7 @@
import { makerConfig, tradingConfig } from "../config";
import {
createExchangeAdapter,
getExchangeDisplayName,
resolveExchangeId,
} from "../exchanges/create-adapter";
import { getExchangeDisplayName, resolveExchangeId } from "../exchanges/create-adapter";
import type { ExchangeAdapter } from "../exchanges/adapter";
import { buildAdapterFromEnv } from "../exchanges/resolve-from-env";
import {
MakerEngine,
type MakerEngineSnapshot,
@@ -147,52 +144,7 @@ async function runEngine<TSnapshot extends TrendEngineSnapshot | MakerEngineSnap
}
function createAdapterOrThrow(symbol: string): ExchangeAdapter {
const exchangeId = resolveExchangeId();
if (exchangeId === "aster") {
const apiKey = process.env.ASTER_API_KEY;
const apiSecret = process.env.ASTER_API_SECRET;
if (!apiKey || !apiSecret) {
throw new Error("Missing ASTER_API_KEY or ASTER_API_SECRET environment variables");
}
return createExchangeAdapter({
exchange: exchangeId,
symbol,
aster: { apiKey, apiSecret },
});
}
if (exchangeId === "lighter") {
const accountIndex = parseInt(process.env.LIGHTER_ACCOUNT_INDEX ?? "", 10);
const privateKey = process.env.LIGHTER_API_PRIVATE_KEY;
if (!Number.isFinite(accountIndex) || !privateKey) {
throw new Error("LIGHTER_ACCOUNT_INDEX and LIGHTER_API_PRIVATE_KEY environment variables are required for Lighter exchange");
}
const apiKeyIndex = process.env.LIGHTER_API_KEY_INDEX ? Number(process.env.LIGHTER_API_KEY_INDEX) : 0;
const lighterSymbol = process.env.LIGHTER_SYMBOL ?? symbol;
const marketId = process.env.LIGHTER_MARKET_ID ? Number(process.env.LIGHTER_MARKET_ID) : undefined;
const priceDecimals = process.env.LIGHTER_PRICE_DECIMALS ? Number(process.env.LIGHTER_PRICE_DECIMALS) : undefined;
const sizeDecimals = process.env.LIGHTER_SIZE_DECIMALS ? Number(process.env.LIGHTER_SIZE_DECIMALS) : undefined;
return createExchangeAdapter({
exchange: exchangeId,
symbol,
lighter: {
marketSymbol: lighterSymbol,
accountIndex,
apiPrivateKey: privateKey,
apiKeyIndex,
baseUrl: process.env.LIGHTER_BASE_URL,
environment: process.env.LIGHTER_ENV,
marketId,
priceDecimals,
sizeDecimals,
},
});
}
return createExchangeAdapter({
exchange: exchangeId,
symbol,
grvt: { symbol },
});
return buildAdapterFromEnv({ exchangeId: resolveExchangeId(), symbol });
}
type TradeLogEntry = { time: string; type: string; detail: string };