@raintree-technology/perps 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/LICENSE +21 -0
- package/README.md +175 -0
- package/dist/adapters/aevo.d.ts +64 -0
- package/dist/adapters/aevo.js +899 -0
- package/dist/adapters/certification.d.ts +33 -0
- package/dist/adapters/certification.js +99 -0
- package/dist/adapters/decibel/order-manager.d.ts +45 -0
- package/dist/adapters/decibel/order-manager.js +140 -0
- package/dist/adapters/decibel/rest-client.d.ts +176 -0
- package/dist/adapters/decibel/rest-client.js +155 -0
- package/dist/adapters/decibel/ws-feed.d.ts +28 -0
- package/dist/adapters/decibel/ws-feed.js +166 -0
- package/dist/adapters/decibel.d.ts +108 -0
- package/dist/adapters/decibel.js +1377 -0
- package/dist/adapters/hyperliquid.d.ts +63 -0
- package/dist/adapters/hyperliquid.js +797 -0
- package/dist/adapters/index.d.ts +11 -0
- package/dist/adapters/index.js +12 -0
- package/dist/adapters/interface.d.ts +310 -0
- package/dist/adapters/interface.js +15 -0
- package/dist/adapters/orderly.d.ts +70 -0
- package/dist/adapters/orderly.js +936 -0
- package/dist/adapters/paradex.d.ts +69 -0
- package/dist/adapters/paradex.js +862 -0
- package/dist/adapters/utils.d.ts +17 -0
- package/dist/adapters/utils.js +122 -0
- package/dist/cli/command-metadata.d.ts +2 -0
- package/dist/cli/command-metadata.js +44 -0
- package/dist/cli/context.d.ts +14 -0
- package/dist/cli/context.js +59 -0
- package/dist/cli/experience.d.ts +48 -0
- package/dist/cli/experience.js +243 -0
- package/dist/cli/ink/app/AppShell.d.ts +12 -0
- package/dist/cli/ink/app/AppShell.js +32 -0
- package/dist/cli/ink/app/MetricStrip.d.ts +6 -0
- package/dist/cli/ink/app/MetricStrip.js +14 -0
- package/dist/cli/ink/app/Panel.d.ts +9 -0
- package/dist/cli/ink/app/Panel.js +7 -0
- package/dist/cli/ink/app/ascii.d.ts +2 -0
- package/dist/cli/ink/app/ascii.js +46 -0
- package/dist/cli/ink/app/index.d.ts +5 -0
- package/dist/cli/ink/app/index.js +4 -0
- package/dist/cli/ink/app/types.d.ts +15 -0
- package/dist/cli/ink/app/types.js +1 -0
- package/dist/cli/ink/components/PnL.d.ts +12 -0
- package/dist/cli/ink/components/PnL.js +23 -0
- package/dist/cli/ink/components/Spinner.d.ts +13 -0
- package/dist/cli/ink/components/Spinner.js +13 -0
- package/dist/cli/ink/components/Table.d.ts +14 -0
- package/dist/cli/ink/components/Table.js +42 -0
- package/dist/cli/ink/components/WatchHeader.d.ts +10 -0
- package/dist/cli/ink/components/WatchHeader.js +18 -0
- package/dist/cli/ink/components/index.d.ts +4 -0
- package/dist/cli/ink/components/index.js +4 -0
- package/dist/cli/ink/index.d.ts +4 -0
- package/dist/cli/ink/index.js +4 -0
- package/dist/cli/ink/render.d.ts +12 -0
- package/dist/cli/ink/render.js +21 -0
- package/dist/cli/ink/theme.d.ts +29 -0
- package/dist/cli/ink/theme.js +40 -0
- package/dist/cli/network-defaults.d.ts +10 -0
- package/dist/cli/network-defaults.js +35 -0
- package/dist/cli/output.d.ts +11 -0
- package/dist/cli/output.js +115 -0
- package/dist/cli/program.d.ts +18 -0
- package/dist/cli/program.js +164 -0
- package/dist/cli/watch.d.ts +19 -0
- package/dist/cli/watch.js +35 -0
- package/dist/client/index.d.ts +55 -0
- package/dist/client/index.js +157 -0
- package/dist/commands/account/add.d.ts +2 -0
- package/dist/commands/account/add.js +510 -0
- package/dist/commands/account/balances-simple.d.ts +5 -0
- package/dist/commands/account/balances-simple.js +63 -0
- package/dist/commands/account/index.d.ts +2 -0
- package/dist/commands/account/index.js +17 -0
- package/dist/commands/account/ls.d.ts +2 -0
- package/dist/commands/account/ls.js +95 -0
- package/dist/commands/account/positions-simple.d.ts +5 -0
- package/dist/commands/account/positions-simple.js +77 -0
- package/dist/commands/account/remove.d.ts +2 -0
- package/dist/commands/account/remove.js +47 -0
- package/dist/commands/account/set-default.d.ts +2 -0
- package/dist/commands/account/set-default.js +47 -0
- package/dist/commands/agent/index.d.ts +2 -0
- package/dist/commands/agent/index.js +126 -0
- package/dist/commands/arb/alert.d.ts +6 -0
- package/dist/commands/arb/alert.js +88 -0
- package/dist/commands/arb/basis-execute.d.ts +6 -0
- package/dist/commands/arb/basis-execute.js +332 -0
- package/dist/commands/arb/basis.d.ts +6 -0
- package/dist/commands/arb/basis.js +181 -0
- package/dist/commands/arb/compare.d.ts +6 -0
- package/dist/commands/arb/compare.js +216 -0
- package/dist/commands/arb/execute.d.ts +6 -0
- package/dist/commands/arb/execute.js +467 -0
- package/dist/commands/arb/funding.d.ts +6 -0
- package/dist/commands/arb/funding.js +201 -0
- package/dist/commands/arb/history.d.ts +6 -0
- package/dist/commands/arb/history.js +153 -0
- package/dist/commands/arb/index.d.ts +6 -0
- package/dist/commands/arb/index.js +29 -0
- package/dist/commands/arb/positions.d.ts +6 -0
- package/dist/commands/arb/positions.js +158 -0
- package/dist/commands/arb/spread.d.ts +6 -0
- package/dist/commands/arb/spread.js +253 -0
- package/dist/commands/arb/track.d.ts +6 -0
- package/dist/commands/arb/track.js +259 -0
- package/dist/commands/asset/book-simple.d.ts +5 -0
- package/dist/commands/asset/book-simple.js +77 -0
- package/dist/commands/asset/index.d.ts +2 -0
- package/dist/commands/asset/index.js +5 -0
- package/dist/commands/completion.d.ts +2 -0
- package/dist/commands/completion.js +161 -0
- package/dist/commands/config/index.d.ts +5 -0
- package/dist/commands/config/index.js +109 -0
- package/dist/commands/data/index.d.ts +31 -0
- package/dist/commands/data/index.js +1466 -0
- package/dist/commands/doctor.d.ts +2 -0
- package/dist/commands/doctor.js +201 -0
- package/dist/commands/exchange/index.d.ts +2 -0
- package/dist/commands/exchange/index.js +107 -0
- package/dist/commands/index.d.ts +2 -0
- package/dist/commands/index.js +48 -0
- package/dist/commands/markets/index.d.ts +2 -0
- package/dist/commands/markets/index.js +5 -0
- package/dist/commands/markets/ls-simple.d.ts +7 -0
- package/dist/commands/markets/ls-simple.js +277 -0
- package/dist/commands/operator/index.d.ts +2 -0
- package/dist/commands/operator/index.js +146 -0
- package/dist/commands/order/cancel-simple.d.ts +5 -0
- package/dist/commands/order/cancel-simple.js +104 -0
- package/dist/commands/order/index.d.ts +2 -0
- package/dist/commands/order/index.js +13 -0
- package/dist/commands/order/limit-simple.d.ts +5 -0
- package/dist/commands/order/limit-simple.js +195 -0
- package/dist/commands/order/market-simple.d.ts +5 -0
- package/dist/commands/order/market-simple.js +190 -0
- package/dist/commands/order/shared.d.ts +17 -0
- package/dist/commands/order/shared.js +51 -0
- package/dist/commands/order/trigger-simple.d.ts +5 -0
- package/dist/commands/order/trigger-simple.js +246 -0
- package/dist/commands/referral/index.d.ts +2 -0
- package/dist/commands/referral/index.js +7 -0
- package/dist/commands/referral/set.d.ts +2 -0
- package/dist/commands/referral/set.js +26 -0
- package/dist/commands/referral/status.d.ts +2 -0
- package/dist/commands/referral/status.js +31 -0
- package/dist/commands/replay/index.d.ts +2 -0
- package/dist/commands/replay/index.js +152 -0
- package/dist/commands/risk/analytics.d.ts +2 -0
- package/dist/commands/risk/analytics.js +64 -0
- package/dist/commands/risk/audit.d.ts +2 -0
- package/dist/commands/risk/audit.js +52 -0
- package/dist/commands/risk/index.d.ts +2 -0
- package/dist/commands/risk/index.js +9 -0
- package/dist/commands/risk/rules.d.ts +2 -0
- package/dist/commands/risk/rules.js +102 -0
- package/dist/commands/server.d.ts +2 -0
- package/dist/commands/server.js +208 -0
- package/dist/commands/setup/index.d.ts +2 -0
- package/dist/commands/setup/index.js +478 -0
- package/dist/commands/signal/index.d.ts +2 -0
- package/dist/commands/signal/index.js +129 -0
- package/dist/commands/state/index.d.ts +2 -0
- package/dist/commands/state/index.js +5 -0
- package/dist/commands/state/show.d.ts +2 -0
- package/dist/commands/state/show.js +105 -0
- package/dist/commands/strategy/index.d.ts +4 -0
- package/dist/commands/strategy/index.js +73 -0
- package/dist/commands/traces/index.d.ts +2 -0
- package/dist/commands/traces/index.js +76 -0
- package/dist/commands/ui/demo.d.ts +9 -0
- package/dist/commands/ui/demo.js +195 -0
- package/dist/commands/ui/index.d.ts +2 -0
- package/dist/commands/ui/index.js +7 -0
- package/dist/commands/ui/terminal.d.ts +2 -0
- package/dist/commands/ui/terminal.js +255 -0
- package/dist/commands/upgrade.d.ts +2 -0
- package/dist/commands/upgrade.js +98 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +4 -0
- package/dist/lib/agent/audit.d.ts +12 -0
- package/dist/lib/agent/audit.js +13 -0
- package/dist/lib/agent/gateway.d.ts +13 -0
- package/dist/lib/agent/gateway.js +598 -0
- package/dist/lib/agent/metrics.d.ts +33 -0
- package/dist/lib/agent/metrics.js +175 -0
- package/dist/lib/agent/signature.d.ts +8 -0
- package/dist/lib/agent/signature.js +28 -0
- package/dist/lib/agent/tools.d.ts +28 -0
- package/dist/lib/agent/tools.js +453 -0
- package/dist/lib/agent/x402.d.ts +23 -0
- package/dist/lib/agent/x402.js +62 -0
- package/dist/lib/api-wallet.d.ts +69 -0
- package/dist/lib/api-wallet.js +101 -0
- package/dist/lib/balance-watcher.d.ts +25 -0
- package/dist/lib/balance-watcher.js +83 -0
- package/dist/lib/book-watcher.d.ts +25 -0
- package/dist/lib/book-watcher.js +48 -0
- package/dist/lib/config.d.ts +88 -0
- package/dist/lib/config.js +427 -0
- package/dist/lib/constants.d.ts +50 -0
- package/dist/lib/constants.js +84 -0
- package/dist/lib/contracts.d.ts +7 -0
- package/dist/lib/contracts.js +8 -0
- package/dist/lib/credential-vault.d.ts +22 -0
- package/dist/lib/credential-vault.js +109 -0
- package/dist/lib/db/accounts.d.ts +83 -0
- package/dist/lib/db/accounts.js +203 -0
- package/dist/lib/db/funding-history.d.ts +69 -0
- package/dist/lib/db/funding-history.js +183 -0
- package/dist/lib/db/index.d.ts +11 -0
- package/dist/lib/db/index.js +272 -0
- package/dist/lib/events/bus.d.ts +10 -0
- package/dist/lib/events/bus.js +17 -0
- package/dist/lib/events/types.d.ts +51 -0
- package/dist/lib/events/types.js +1 -0
- package/dist/lib/exchange.d.ts +30 -0
- package/dist/lib/exchange.js +84 -0
- package/dist/lib/execution/journal.d.ts +25 -0
- package/dist/lib/execution/journal.js +158 -0
- package/dist/lib/execution/safety.d.ts +34 -0
- package/dist/lib/execution/safety.js +197 -0
- package/dist/lib/exit-codes.d.ts +18 -0
- package/dist/lib/exit-codes.js +60 -0
- package/dist/lib/fetch.d.ts +18 -0
- package/dist/lib/fetch.js +66 -0
- package/dist/lib/fs-security.d.ts +10 -0
- package/dist/lib/fs-security.js +26 -0
- package/dist/lib/funding-tracker.d.ts +40 -0
- package/dist/lib/funding-tracker.js +118 -0
- package/dist/lib/logger.d.ts +27 -0
- package/dist/lib/logger.js +82 -0
- package/dist/lib/network-model.d.ts +13 -0
- package/dist/lib/network-model.js +30 -0
- package/dist/lib/onboarding.d.ts +133 -0
- package/dist/lib/onboarding.js +1459 -0
- package/dist/lib/operator-state.d.ts +25 -0
- package/dist/lib/operator-state.js +82 -0
- package/dist/lib/orders-watcher.d.ts +24 -0
- package/dist/lib/orders-watcher.js +74 -0
- package/dist/lib/paths.d.ts +20 -0
- package/dist/lib/paths.js +23 -0
- package/dist/lib/portfolio-watcher.d.ts +33 -0
- package/dist/lib/portfolio-watcher.js +95 -0
- package/dist/lib/position-watcher.d.ts +16 -0
- package/dist/lib/position-watcher.js +44 -0
- package/dist/lib/price-watcher.d.ts +15 -0
- package/dist/lib/price-watcher.js +84 -0
- package/dist/lib/prompts.d.ts +32 -0
- package/dist/lib/prompts.js +105 -0
- package/dist/lib/rate-limit.d.ts +32 -0
- package/dist/lib/rate-limit.js +88 -0
- package/dist/lib/risk/analytics.d.ts +39 -0
- package/dist/lib/risk/analytics.js +98 -0
- package/dist/lib/risk/drawdown.d.ts +18 -0
- package/dist/lib/risk/drawdown.js +49 -0
- package/dist/lib/risk/evaluation-log.d.ts +29 -0
- package/dist/lib/risk/evaluation-log.js +61 -0
- package/dist/lib/risk/index.d.ts +4 -0
- package/dist/lib/risk/index.js +4 -0
- package/dist/lib/risk/limits.d.ts +23 -0
- package/dist/lib/risk/limits.js +27 -0
- package/dist/lib/risk/manager.d.ts +32 -0
- package/dist/lib/risk/manager.js +85 -0
- package/dist/lib/risk/policy-middleware.d.ts +33 -0
- package/dist/lib/risk/policy-middleware.js +267 -0
- package/dist/lib/risk/position-sizer.d.ts +9 -0
- package/dist/lib/risk/position-sizer.js +14 -0
- package/dist/lib/risk/rules-store.d.ts +16 -0
- package/dist/lib/risk/rules-store.js +47 -0
- package/dist/lib/schema.d.ts +254 -0
- package/dist/lib/schema.js +199 -0
- package/dist/lib/secrets.d.ts +3 -0
- package/dist/lib/secrets.js +62 -0
- package/dist/lib/settings.d.ts +24 -0
- package/dist/lib/settings.js +86 -0
- package/dist/lib/signals.d.ts +73 -0
- package/dist/lib/signals.js +136 -0
- package/dist/lib/stable-stringify.d.ts +6 -0
- package/dist/lib/stable-stringify.js +17 -0
- package/dist/lib/state-context.d.ts +44 -0
- package/dist/lib/state-context.js +133 -0
- package/dist/lib/strategy/basis-trade.d.ts +2 -0
- package/dist/lib/strategy/basis-trade.js +24 -0
- package/dist/lib/strategy/funding-arb.d.ts +2 -0
- package/dist/lib/strategy/funding-arb.js +23 -0
- package/dist/lib/strategy/interface.d.ts +23 -0
- package/dist/lib/strategy/interface.js +1 -0
- package/dist/lib/strategy/registry.d.ts +4 -0
- package/dist/lib/strategy/registry.js +10 -0
- package/dist/lib/telemetry.d.ts +25 -0
- package/dist/lib/telemetry.js +101 -0
- package/dist/lib/trace-queries.d.ts +20 -0
- package/dist/lib/trace-queries.js +133 -0
- package/dist/lib/trace.d.ts +1 -0
- package/dist/lib/trace.js +4 -0
- package/dist/lib/trade-reputation.d.ts +6 -0
- package/dist/lib/trade-reputation.js +99 -0
- package/dist/lib/ui-tokens.d.ts +21 -0
- package/dist/lib/ui-tokens.js +26 -0
- package/dist/lib/validate.d.ts +39 -0
- package/dist/lib/validate.js +108 -0
- package/dist/lib/validation.d.ts +9 -0
- package/dist/lib/validation.js +64 -0
- package/dist/server/cache.d.ts +38 -0
- package/dist/server/cache.js +56 -0
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.js +89 -0
- package/dist/server/ipc.d.ts +18 -0
- package/dist/server/ipc.js +159 -0
- package/dist/server/subscriptions.d.ts +18 -0
- package/dist/server/subscriptions.js +114 -0
- package/package.json +124 -0
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
2
|
+
import { getDefaultAccountForExchange } from "./db/index.js";
|
|
3
|
+
import { parseEnv } from "./schema.js";
|
|
4
|
+
import { recordTelemetryMetric } from "./telemetry.js";
|
|
5
|
+
const DECIBEL_NETWORK_DEFAULTS = {
|
|
6
|
+
testnet: {
|
|
7
|
+
fullnodeUrl: "https://api.testnet.aptoslabs.com/v1",
|
|
8
|
+
restUrl: "https://api.testnet.aptoslabs.com/decibel",
|
|
9
|
+
wsUrl: "wss://api.testnet.aptoslabs.com/decibel/ws",
|
|
10
|
+
packageAddress: "0x95254fcb0816b9f3ec71aa4de5f5f7f8f3efeef9239f0d705a4cd3fe2f452de3",
|
|
11
|
+
},
|
|
12
|
+
mainnet: {
|
|
13
|
+
fullnodeUrl: "https://api.mainnet.aptoslabs.com/v1",
|
|
14
|
+
restUrl: "https://api.mainnet.aptoslabs.com/decibel",
|
|
15
|
+
wsUrl: "wss://api.mainnet.aptoslabs.com/decibel/ws",
|
|
16
|
+
packageAddress: "0xb8a5788314451ce4d2fbbad32e1bad88d4184b73943b7fe5166eab93cf1a5a95",
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
const ORDERLY_DEFAULTS = {
|
|
20
|
+
testnet: "https://testnet-api.orderly.org/v1",
|
|
21
|
+
mainnet: "https://api-evm.orderly.org/v1",
|
|
22
|
+
};
|
|
23
|
+
const AEVO_DEFAULTS = {
|
|
24
|
+
testnet: "https://api-testnet.aevo.xyz",
|
|
25
|
+
mainnet: "https://api.aevo.xyz",
|
|
26
|
+
};
|
|
27
|
+
const PARADEX_DEFAULTS = {
|
|
28
|
+
testnet: "https://api.testnet.paradex.trade/v1",
|
|
29
|
+
mainnet: "https://api.prod.paradex.trade/v1",
|
|
30
|
+
};
|
|
31
|
+
const PARADEX_CHAIN_DEFAULTS = {
|
|
32
|
+
testnet: "SN_SEPOLIA",
|
|
33
|
+
mainnet: "SN_MAIN",
|
|
34
|
+
};
|
|
35
|
+
function resolveExchangeNetwork(defaultTestnet, override) {
|
|
36
|
+
if (override) {
|
|
37
|
+
return override;
|
|
38
|
+
}
|
|
39
|
+
return defaultTestnet ? "testnet" : "mainnet";
|
|
40
|
+
}
|
|
41
|
+
function loadDefaultAccount(exchangeId) {
|
|
42
|
+
try {
|
|
43
|
+
return getDefaultAccountForExchange(exchangeId);
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function resolveStoredAccount(exchangeId) {
|
|
50
|
+
const defaultAccount = loadDefaultAccount(exchangeId);
|
|
51
|
+
if (defaultAccount) {
|
|
52
|
+
return {
|
|
53
|
+
privateKey: defaultAccount.apiWalletPrivateKey || undefined,
|
|
54
|
+
walletAddress: defaultAccount.userAddress,
|
|
55
|
+
account: {
|
|
56
|
+
alias: defaultAccount.alias,
|
|
57
|
+
type: defaultAccount.type,
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
return {};
|
|
62
|
+
}
|
|
63
|
+
function resolveHyperliquidSettings(testnet, env) {
|
|
64
|
+
const stored = resolveStoredAccount("hyperliquid");
|
|
65
|
+
const network = resolveExchangeNetwork(testnet, env.HYPERLIQUID_NETWORK);
|
|
66
|
+
if (stored.walletAddress || stored.privateKey) {
|
|
67
|
+
return {
|
|
68
|
+
network,
|
|
69
|
+
privateKey: stored.privateKey,
|
|
70
|
+
walletAddress: stored.walletAddress,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
const privateKey = env.HYPERLIQUID_PRIVATE_KEY;
|
|
74
|
+
let walletAddress = env.HYPERLIQUID_WALLET_ADDRESS;
|
|
75
|
+
if (privateKey && !walletAddress) {
|
|
76
|
+
walletAddress = privateKeyToAccount(privateKey).address;
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
network,
|
|
80
|
+
privateKey,
|
|
81
|
+
walletAddress,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function resolveDecibelSettings(testnet, env) {
|
|
85
|
+
const network = resolveExchangeNetwork(testnet, env.DECIBEL_NETWORK);
|
|
86
|
+
const defaults = DECIBEL_NETWORK_DEFAULTS[network];
|
|
87
|
+
const credentials = {
|
|
88
|
+
apiWalletPrivateKey: env.DECIBEL_API_WALLET_PRIVATE_KEY,
|
|
89
|
+
apiWalletAddress: env.DECIBEL_API_WALLET_ADDRESS,
|
|
90
|
+
apiBearerToken: env.DECIBEL_API_BEARER_TOKEN,
|
|
91
|
+
subaccountAddress: env.DECIBEL_SUBACCOUNT_ADDRESS,
|
|
92
|
+
};
|
|
93
|
+
const hasAnyCredentials = !!credentials.apiWalletPrivateKey ||
|
|
94
|
+
!!credentials.apiWalletAddress ||
|
|
95
|
+
!!credentials.apiBearerToken ||
|
|
96
|
+
!!credentials.subaccountAddress;
|
|
97
|
+
return {
|
|
98
|
+
network,
|
|
99
|
+
fullnodeUrl: env.DECIBEL_FULLNODE_URL ?? defaults.fullnodeUrl,
|
|
100
|
+
restUrl: env.DECIBEL_REST_URL ?? defaults.restUrl,
|
|
101
|
+
wsUrl: env.DECIBEL_WS_URL ?? defaults.wsUrl,
|
|
102
|
+
packageAddress: env.DECIBEL_PACKAGE_ADDRESS ?? defaults.packageAddress,
|
|
103
|
+
credentials: hasAnyCredentials ? credentials : undefined,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function resolveAevoSettings(testnet, env) {
|
|
107
|
+
const network = resolveExchangeNetwork(testnet, env.AEVO_NETWORK);
|
|
108
|
+
return {
|
|
109
|
+
network,
|
|
110
|
+
restUrl: env.AEVO_REST_URL ?? AEVO_DEFAULTS[network],
|
|
111
|
+
apiKey: env.AEVO_API_KEY,
|
|
112
|
+
apiSecret: env.AEVO_API_SECRET,
|
|
113
|
+
signingKey: env.AEVO_SIGNING_KEY,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function resolveOrderlySettings(testnet, env) {
|
|
117
|
+
const network = resolveExchangeNetwork(testnet, env.ORDERLY_NETWORK);
|
|
118
|
+
return {
|
|
119
|
+
network,
|
|
120
|
+
restUrl: env.ORDERLY_REST_URL ?? ORDERLY_DEFAULTS[network],
|
|
121
|
+
accountId: env.ORDERLY_ACCOUNT_ID,
|
|
122
|
+
key: env.ORDERLY_KEY,
|
|
123
|
+
secret: env.ORDERLY_SECRET,
|
|
124
|
+
tradingKey: env.ORDERLY_TRADING_KEY,
|
|
125
|
+
tradingSecret: env.ORDERLY_TRADING_SECRET,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function resolveParadexSettings(testnet, env) {
|
|
129
|
+
const network = resolveExchangeNetwork(testnet, env.PARADEX_NETWORK);
|
|
130
|
+
return {
|
|
131
|
+
network,
|
|
132
|
+
restUrl: env.PARADEX_REST_URL ?? PARADEX_DEFAULTS[network],
|
|
133
|
+
apiBearerToken: env.PARADEX_API_BEARER_TOKEN,
|
|
134
|
+
account: env.PARADEX_ACCOUNT_ADDRESS,
|
|
135
|
+
ethereumAccount: env.PARADEX_ETHEREUM_ACCOUNT,
|
|
136
|
+
privateKey: env.PARADEX_PRIVATE_KEY,
|
|
137
|
+
chainId: env.PARADEX_CHAIN_ID ?? PARADEX_CHAIN_DEFAULTS[network],
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function resolveSelectedExchangeNetwork(exchangeId, settings, fallbackTestnet) {
|
|
141
|
+
switch (exchangeId) {
|
|
142
|
+
case "hyperliquid":
|
|
143
|
+
return settings.hyperliquid.network;
|
|
144
|
+
case "decibel":
|
|
145
|
+
return settings.decibel.network;
|
|
146
|
+
case "aevo":
|
|
147
|
+
return settings.aevo.network;
|
|
148
|
+
case "orderly":
|
|
149
|
+
return settings.orderly.network;
|
|
150
|
+
case "paradex":
|
|
151
|
+
return settings.paradex.network;
|
|
152
|
+
default:
|
|
153
|
+
return fallbackTestnet ? "testnet" : "mainnet";
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
export function loadConfig(testnet, exchangeId = "hyperliquid") {
|
|
157
|
+
const env = parseEnv(process.env);
|
|
158
|
+
const normalizedExchangeId = exchangeId.toLowerCase();
|
|
159
|
+
const selectedAccount = resolveStoredAccount(normalizedExchangeId);
|
|
160
|
+
const hyperliquid = resolveHyperliquidSettings(testnet, env);
|
|
161
|
+
const decibel = resolveDecibelSettings(testnet, env);
|
|
162
|
+
const aevo = resolveAevoSettings(testnet, env);
|
|
163
|
+
const orderly = resolveOrderlySettings(testnet, env);
|
|
164
|
+
const paradex = resolveParadexSettings(testnet, env);
|
|
165
|
+
const exchanges = {
|
|
166
|
+
hyperliquid,
|
|
167
|
+
decibel,
|
|
168
|
+
aevo,
|
|
169
|
+
orderly,
|
|
170
|
+
paradex,
|
|
171
|
+
};
|
|
172
|
+
const selectedNetwork = resolveSelectedExchangeNetwork(normalizedExchangeId, exchanges, testnet);
|
|
173
|
+
if (selectedAccount.walletAddress || selectedAccount.privateKey) {
|
|
174
|
+
if (normalizedExchangeId === "decibel") {
|
|
175
|
+
decibel.credentials = {
|
|
176
|
+
...decibel.credentials,
|
|
177
|
+
apiWalletPrivateKey: selectedAccount.privateKey ?? decibel.credentials?.apiWalletPrivateKey,
|
|
178
|
+
apiWalletAddress: selectedAccount.walletAddress ?? decibel.credentials?.apiWalletAddress,
|
|
179
|
+
subaccountAddress: decibel.credentials?.subaccountAddress ??
|
|
180
|
+
selectedAccount.walletAddress ??
|
|
181
|
+
decibel.credentials?.apiWalletAddress,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
else if (normalizedExchangeId === "aevo") {
|
|
185
|
+
if (!aevo.signingKey && selectedAccount.privateKey) {
|
|
186
|
+
aevo.signingKey = selectedAccount.privateKey;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
else if (normalizedExchangeId === "orderly") {
|
|
190
|
+
if (!orderly.accountId && selectedAccount.walletAddress) {
|
|
191
|
+
orderly.accountId = selectedAccount.walletAddress;
|
|
192
|
+
}
|
|
193
|
+
if (!orderly.tradingSecret && selectedAccount.privateKey) {
|
|
194
|
+
orderly.tradingSecret = selectedAccount.privateKey;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
else if (normalizedExchangeId === "paradex") {
|
|
198
|
+
if (!paradex.privateKey && selectedAccount.privateKey) {
|
|
199
|
+
paradex.privateKey = selectedAccount.privateKey;
|
|
200
|
+
}
|
|
201
|
+
if (!paradex.account && selectedAccount.walletAddress) {
|
|
202
|
+
paradex.account = selectedAccount.walletAddress;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
let privateKey;
|
|
207
|
+
let walletAddress;
|
|
208
|
+
if (selectedAccount.walletAddress || selectedAccount.privateKey) {
|
|
209
|
+
privateKey = selectedAccount.privateKey;
|
|
210
|
+
walletAddress = selectedAccount.walletAddress;
|
|
211
|
+
}
|
|
212
|
+
else if (normalizedExchangeId === "decibel") {
|
|
213
|
+
privateKey = decibel.credentials?.apiWalletPrivateKey;
|
|
214
|
+
walletAddress = undefined;
|
|
215
|
+
}
|
|
216
|
+
else if (normalizedExchangeId === "hyperliquid") {
|
|
217
|
+
privateKey = hyperliquid.privateKey;
|
|
218
|
+
walletAddress = hyperliquid.walletAddress;
|
|
219
|
+
}
|
|
220
|
+
else if (normalizedExchangeId === "aevo") {
|
|
221
|
+
privateKey = aevo.signingKey;
|
|
222
|
+
walletAddress = privateKey ? privateKeyToAccount(privateKey).address : undefined;
|
|
223
|
+
}
|
|
224
|
+
return {
|
|
225
|
+
privateKey,
|
|
226
|
+
walletAddress,
|
|
227
|
+
testnet: selectedNetwork === "testnet",
|
|
228
|
+
account: selectedAccount.account,
|
|
229
|
+
risk: {
|
|
230
|
+
maxPositionSizeUsd: env.RISK_MAX_POSITION_SIZE_USD,
|
|
231
|
+
maxTotalExposureUsd: env.RISK_MAX_TOTAL_EXPOSURE_USD,
|
|
232
|
+
maxLeverage: env.RISK_MAX_LEVERAGE,
|
|
233
|
+
minSignalConfidence: env.RISK_MIN_SIGNAL_CONFIDENCE,
|
|
234
|
+
maxDrawdownPct: env.RISK_MAX_DRAWDOWN_PCT,
|
|
235
|
+
defaultLeverage: env.RISK_DEFAULT_LEVERAGE,
|
|
236
|
+
},
|
|
237
|
+
executionSafety: {
|
|
238
|
+
stopLossPct: env.EXECUTION_STOP_LOSS_PCT,
|
|
239
|
+
takeProfitPct: env.EXECUTION_TAKE_PROFIT_PCT,
|
|
240
|
+
spreadOffset: env.EXECUTION_SPREAD_OFFSET_PCT / 100,
|
|
241
|
+
},
|
|
242
|
+
operator: {
|
|
243
|
+
heartbeatIntervalMs: env.OPERATOR_HEARTBEAT_INTERVAL_MS,
|
|
244
|
+
},
|
|
245
|
+
exchanges,
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
export function getExchangeCredentials(config, exchangeId, requirement = {}) {
|
|
249
|
+
const id = exchangeId.toLowerCase();
|
|
250
|
+
const recordAuth = (scope, status) => {
|
|
251
|
+
recordTelemetryMetric({
|
|
252
|
+
metric: `auth.${id}.${scope}`,
|
|
253
|
+
status,
|
|
254
|
+
});
|
|
255
|
+
};
|
|
256
|
+
if (id === "hyperliquid") {
|
|
257
|
+
const credentials = {
|
|
258
|
+
privateKey: config.exchanges.hyperliquid.privateKey,
|
|
259
|
+
walletAddress: config.exchanges.hyperliquid.walletAddress,
|
|
260
|
+
network: config.exchanges.hyperliquid.network,
|
|
261
|
+
};
|
|
262
|
+
if (requirement.requireReadAccess && !credentials.walletAddress && !credentials.privateKey) {
|
|
263
|
+
recordAuth("read", "failed");
|
|
264
|
+
throw new Error("No Hyperliquid account configured. Run 'perps account add' or set HYPERLIQUID_WALLET_ADDRESS.");
|
|
265
|
+
}
|
|
266
|
+
if (requirement.requireReadAccess) {
|
|
267
|
+
recordAuth("read", "success");
|
|
268
|
+
}
|
|
269
|
+
if (requirement.requireTrading && !credentials.privateKey) {
|
|
270
|
+
recordAuth("trade", "failed");
|
|
271
|
+
throw new Error("Hyperliquid trading requires HYPERLIQUID_PRIVATE_KEY or an API-wallet account from 'perps account add'.");
|
|
272
|
+
}
|
|
273
|
+
if (requirement.requireTrading) {
|
|
274
|
+
recordAuth("trade", "success");
|
|
275
|
+
}
|
|
276
|
+
return credentials;
|
|
277
|
+
}
|
|
278
|
+
if (id === "decibel") {
|
|
279
|
+
const decibel = config.exchanges.decibel;
|
|
280
|
+
const credentials = {
|
|
281
|
+
privateKey: decibel.credentials?.apiWalletPrivateKey,
|
|
282
|
+
accountAddress: decibel.credentials?.apiWalletAddress,
|
|
283
|
+
apiBearerToken: decibel.credentials?.apiBearerToken,
|
|
284
|
+
subaccountAddress: decibel.credentials?.subaccountAddress ?? decibel.credentials?.apiWalletAddress,
|
|
285
|
+
packageAddress: decibel.packageAddress,
|
|
286
|
+
restUrl: decibel.restUrl,
|
|
287
|
+
wsUrl: decibel.wsUrl,
|
|
288
|
+
fullnodeUrl: decibel.fullnodeUrl,
|
|
289
|
+
network: decibel.network,
|
|
290
|
+
};
|
|
291
|
+
if (requirement.requireReadAccess &&
|
|
292
|
+
(!credentials.apiBearerToken || !credentials.accountAddress)) {
|
|
293
|
+
recordAuth("read", "failed");
|
|
294
|
+
throw new Error("Decibel authenticated reads require DECIBEL_API_WALLET_ADDRESS + DECIBEL_API_BEARER_TOKEN.");
|
|
295
|
+
}
|
|
296
|
+
if (requirement.requireReadAccess) {
|
|
297
|
+
recordAuth("read", "success");
|
|
298
|
+
}
|
|
299
|
+
if (requirement.requireTrading &&
|
|
300
|
+
(!credentials.privateKey ||
|
|
301
|
+
!credentials.accountAddress ||
|
|
302
|
+
!credentials.apiBearerToken ||
|
|
303
|
+
!credentials.packageAddress)) {
|
|
304
|
+
recordAuth("trade", "failed");
|
|
305
|
+
throw new Error("Decibel trading requires DECIBEL_API_WALLET_PRIVATE_KEY, DECIBEL_API_WALLET_ADDRESS, DECIBEL_API_BEARER_TOKEN, and package/network settings.");
|
|
306
|
+
}
|
|
307
|
+
if (requirement.requireTrading) {
|
|
308
|
+
recordAuth("trade", "success");
|
|
309
|
+
}
|
|
310
|
+
return credentials;
|
|
311
|
+
}
|
|
312
|
+
if (id === "aevo") {
|
|
313
|
+
const aevo = config.exchanges.aevo;
|
|
314
|
+
const credentials = {
|
|
315
|
+
restUrl: aevo.restUrl,
|
|
316
|
+
network: aevo.network,
|
|
317
|
+
apiKey: aevo.apiKey,
|
|
318
|
+
apiSecret: aevo.apiSecret,
|
|
319
|
+
privateKey: aevo.signingKey,
|
|
320
|
+
walletAddress: aevo.signingKey ? privateKeyToAccount(aevo.signingKey).address : undefined,
|
|
321
|
+
};
|
|
322
|
+
if (requirement.requireReadAccess && (!credentials.apiKey || !credentials.apiSecret)) {
|
|
323
|
+
recordAuth("read", "failed");
|
|
324
|
+
throw new Error("Aevo account reads require AEVO_API_KEY and AEVO_API_SECRET.");
|
|
325
|
+
}
|
|
326
|
+
if (requirement.requireReadAccess) {
|
|
327
|
+
recordAuth("read", "success");
|
|
328
|
+
}
|
|
329
|
+
if (requirement.requireTrading &&
|
|
330
|
+
(!credentials.apiKey || !credentials.apiSecret || !credentials.privateKey)) {
|
|
331
|
+
recordAuth("trade", "failed");
|
|
332
|
+
throw new Error("Aevo trading requires AEVO_API_KEY, AEVO_API_SECRET, and AEVO_SIGNING_KEY.");
|
|
333
|
+
}
|
|
334
|
+
if (requirement.requireTrading) {
|
|
335
|
+
recordAuth("trade", "success");
|
|
336
|
+
}
|
|
337
|
+
return credentials;
|
|
338
|
+
}
|
|
339
|
+
if (id === "orderly") {
|
|
340
|
+
const orderly = config.exchanges.orderly;
|
|
341
|
+
const credentials = {
|
|
342
|
+
network: orderly.network,
|
|
343
|
+
restUrl: orderly.restUrl,
|
|
344
|
+
orderlyAccountId: orderly.accountId,
|
|
345
|
+
orderlyKey: orderly.key,
|
|
346
|
+
orderlySecret: orderly.secret,
|
|
347
|
+
orderlyTradingKey: orderly.tradingKey,
|
|
348
|
+
orderlyTradingSecret: orderly.tradingSecret,
|
|
349
|
+
accountAddress: orderly.accountId,
|
|
350
|
+
apiKey: orderly.key,
|
|
351
|
+
apiSecret: orderly.secret,
|
|
352
|
+
passphrase: orderly.tradingSecret,
|
|
353
|
+
subaccountId: orderly.tradingKey,
|
|
354
|
+
};
|
|
355
|
+
if (requirement.requireReadAccess &&
|
|
356
|
+
(!credentials.orderlyAccountId || !credentials.orderlyKey || !credentials.orderlySecret)) {
|
|
357
|
+
recordAuth("read", "failed");
|
|
358
|
+
throw new Error("Orderly account reads require ORDERLY_ACCOUNT_ID, ORDERLY_KEY, and ORDERLY_SECRET.");
|
|
359
|
+
}
|
|
360
|
+
if (requirement.requireReadAccess) {
|
|
361
|
+
recordAuth("read", "success");
|
|
362
|
+
}
|
|
363
|
+
if (requirement.requireTrading &&
|
|
364
|
+
(!credentials.orderlyAccountId ||
|
|
365
|
+
!credentials.orderlyKey ||
|
|
366
|
+
!credentials.orderlySecret ||
|
|
367
|
+
!credentials.orderlyTradingSecret)) {
|
|
368
|
+
recordAuth("trade", "failed");
|
|
369
|
+
throw new Error("Orderly trading requires ORDERLY_ACCOUNT_ID, ORDERLY_KEY, ORDERLY_SECRET, and ORDERLY_TRADING_SECRET.");
|
|
370
|
+
}
|
|
371
|
+
if (requirement.requireTrading) {
|
|
372
|
+
recordAuth("trade", "success");
|
|
373
|
+
}
|
|
374
|
+
return credentials;
|
|
375
|
+
}
|
|
376
|
+
if (id === "paradex") {
|
|
377
|
+
const paradex = config.exchanges.paradex;
|
|
378
|
+
const credentials = {
|
|
379
|
+
network: paradex.network,
|
|
380
|
+
restUrl: paradex.restUrl,
|
|
381
|
+
apiBearerToken: paradex.apiBearerToken,
|
|
382
|
+
paradexAccount: paradex.account,
|
|
383
|
+
paradexEthereumAccount: paradex.ethereumAccount,
|
|
384
|
+
paradexChainId: paradex.chainId,
|
|
385
|
+
accountAddress: paradex.account,
|
|
386
|
+
privateKey: paradex.privateKey,
|
|
387
|
+
};
|
|
388
|
+
const canRead = !!credentials.apiBearerToken || !!(credentials.paradexAccount && credentials.privateKey);
|
|
389
|
+
if (requirement.requireReadAccess && !canRead) {
|
|
390
|
+
recordAuth("read", "failed");
|
|
391
|
+
throw new Error("Paradex reads require PARADEX_API_BEARER_TOKEN or PARADEX_ACCOUNT_ADDRESS + PARADEX_PRIVATE_KEY.");
|
|
392
|
+
}
|
|
393
|
+
if (requirement.requireReadAccess) {
|
|
394
|
+
recordAuth("read", "success");
|
|
395
|
+
}
|
|
396
|
+
if (requirement.requireTrading &&
|
|
397
|
+
!credentials.apiBearerToken &&
|
|
398
|
+
!(credentials.paradexAccount && credentials.privateKey)) {
|
|
399
|
+
recordAuth("trade", "failed");
|
|
400
|
+
throw new Error("Paradex trading requires PARADEX_API_BEARER_TOKEN or PARADEX_ACCOUNT_ADDRESS + PARADEX_PRIVATE_KEY.");
|
|
401
|
+
}
|
|
402
|
+
if (requirement.requireTrading) {
|
|
403
|
+
recordAuth("trade", "success");
|
|
404
|
+
}
|
|
405
|
+
return credentials;
|
|
406
|
+
}
|
|
407
|
+
const generic = {
|
|
408
|
+
privateKey: config.privateKey,
|
|
409
|
+
walletAddress: config.walletAddress,
|
|
410
|
+
network: config.testnet ? "testnet" : "mainnet",
|
|
411
|
+
};
|
|
412
|
+
if (requirement.requireReadAccess && !generic.walletAddress && !generic.privateKey) {
|
|
413
|
+
recordAuth("read", "failed");
|
|
414
|
+
throw new Error(`No ${exchangeId} account configured. Run 'perps -e ${exchangeId} account add' or set credentials in the environment.`);
|
|
415
|
+
}
|
|
416
|
+
if (requirement.requireReadAccess) {
|
|
417
|
+
recordAuth("read", "success");
|
|
418
|
+
}
|
|
419
|
+
if (requirement.requireTrading && !generic.privateKey) {
|
|
420
|
+
recordAuth("trade", "failed");
|
|
421
|
+
throw new Error(`${exchangeId} trading requires a private key. Run 'perps -e ${exchangeId} account add' with API wallet support or set credentials in the environment.`);
|
|
422
|
+
}
|
|
423
|
+
if (requirement.requireTrading) {
|
|
424
|
+
recordAuth("trade", "success");
|
|
425
|
+
}
|
|
426
|
+
return generic;
|
|
427
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constants and Configuration
|
|
3
|
+
*/
|
|
4
|
+
/** Default timeout for API requests (ms) */
|
|
5
|
+
export declare const DEFAULT_TIMEOUT_MS = 10000;
|
|
6
|
+
/** Default number of retries for failed requests */
|
|
7
|
+
export declare const DEFAULT_RETRIES = 2;
|
|
8
|
+
/** Default delay between retries (ms) */
|
|
9
|
+
export declare const DEFAULT_RETRY_DELAY_MS = 1000;
|
|
10
|
+
/** Maximum concurrent API requests per exchange */
|
|
11
|
+
export declare const MAX_CONCURRENT_REQUESTS = 3;
|
|
12
|
+
/** Rate limit: max requests per window */
|
|
13
|
+
export declare const RATE_LIMIT_REQUESTS = 10;
|
|
14
|
+
export declare const RATE_LIMIT_WINDOW_MS = 1000;
|
|
15
|
+
/** Standard funding interval (hours) */
|
|
16
|
+
export declare const FUNDING_INTERVAL_HOURS = 8;
|
|
17
|
+
/** Major markets for bulk queries (to avoid rate limits) */
|
|
18
|
+
export declare const MAJOR_MARKETS: readonly ["BTC-PERP", "ETH-PERP", "SOL-PERP", "DOGE-PERP", "ARB-PERP", "OP-PERP"];
|
|
19
|
+
/** Common assets for arbitrage tracking */
|
|
20
|
+
export declare const COMMON_ASSETS: readonly ["BTC", "ETH", "SOL", "DOGE", "ARB", "OP", "WIF", "PEPE", "AVAX", "LINK"];
|
|
21
|
+
/** Default orderbook depth */
|
|
22
|
+
export declare const DEFAULT_ORDERBOOK_DEPTH = 20;
|
|
23
|
+
/** Default number of trades to fetch */
|
|
24
|
+
export declare const DEFAULT_TRADES_LIMIT = 100;
|
|
25
|
+
/** Default position size for arb execution (USD) */
|
|
26
|
+
export declare const DEFAULT_ARB_SIZE_USD = 1000;
|
|
27
|
+
/** Minimum annualized spread to consider profitable (%) */
|
|
28
|
+
export declare const MIN_PROFITABLE_SPREAD_PCT = 10;
|
|
29
|
+
/** Days to keep funding history */
|
|
30
|
+
export declare const FUNDING_HISTORY_RETENTION_DAYS = 7;
|
|
31
|
+
/** Default hours for historical analysis */
|
|
32
|
+
export declare const DEFAULT_HISTORY_HOURS = 24;
|
|
33
|
+
/** Default tracking interval (ms) */
|
|
34
|
+
export declare const DEFAULT_TRACK_INTERVAL_MS: number;
|
|
35
|
+
/** Default watch mode refresh (seconds) */
|
|
36
|
+
export declare const DEFAULT_WATCH_INTERVAL_SEC = 30;
|
|
37
|
+
/** Alert check interval (ms) */
|
|
38
|
+
export declare const DEFAULT_ALERT_INTERVAL_MS: number;
|
|
39
|
+
/** Map exchange display names to IDs */
|
|
40
|
+
export declare const EXCHANGE_NAME_TO_ID: Record<string, string>;
|
|
41
|
+
/** Map exchange IDs to display names */
|
|
42
|
+
export declare const EXCHANGE_ID_TO_NAME: Record<string, string>;
|
|
43
|
+
/**
|
|
44
|
+
* Get exchange ID from display name
|
|
45
|
+
*/
|
|
46
|
+
export declare function getExchangeIdByName(name: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* Get display name from exchange ID
|
|
49
|
+
*/
|
|
50
|
+
export declare function getExchangeNameById(id: string): string;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constants and Configuration
|
|
3
|
+
*/
|
|
4
|
+
/** Default timeout for API requests (ms) */
|
|
5
|
+
export const DEFAULT_TIMEOUT_MS = 10000;
|
|
6
|
+
/** Default number of retries for failed requests */
|
|
7
|
+
export const DEFAULT_RETRIES = 2;
|
|
8
|
+
/** Default delay between retries (ms) */
|
|
9
|
+
export const DEFAULT_RETRY_DELAY_MS = 1000;
|
|
10
|
+
/** Maximum concurrent API requests per exchange */
|
|
11
|
+
export const MAX_CONCURRENT_REQUESTS = 3;
|
|
12
|
+
/** Rate limit: max requests per window */
|
|
13
|
+
export const RATE_LIMIT_REQUESTS = 10;
|
|
14
|
+
export const RATE_LIMIT_WINDOW_MS = 1000;
|
|
15
|
+
/** Standard funding interval (hours) */
|
|
16
|
+
export const FUNDING_INTERVAL_HOURS = 8;
|
|
17
|
+
/** Major markets for bulk queries (to avoid rate limits) */
|
|
18
|
+
export const MAJOR_MARKETS = [
|
|
19
|
+
"BTC-PERP",
|
|
20
|
+
"ETH-PERP",
|
|
21
|
+
"SOL-PERP",
|
|
22
|
+
"DOGE-PERP",
|
|
23
|
+
"ARB-PERP",
|
|
24
|
+
"OP-PERP",
|
|
25
|
+
];
|
|
26
|
+
/** Common assets for arbitrage tracking */
|
|
27
|
+
export const COMMON_ASSETS = [
|
|
28
|
+
"BTC",
|
|
29
|
+
"ETH",
|
|
30
|
+
"SOL",
|
|
31
|
+
"DOGE",
|
|
32
|
+
"ARB",
|
|
33
|
+
"OP",
|
|
34
|
+
"WIF",
|
|
35
|
+
"PEPE",
|
|
36
|
+
"AVAX",
|
|
37
|
+
"LINK",
|
|
38
|
+
];
|
|
39
|
+
/** Default orderbook depth */
|
|
40
|
+
export const DEFAULT_ORDERBOOK_DEPTH = 20;
|
|
41
|
+
/** Default number of trades to fetch */
|
|
42
|
+
export const DEFAULT_TRADES_LIMIT = 100;
|
|
43
|
+
/** Default position size for arb execution (USD) */
|
|
44
|
+
export const DEFAULT_ARB_SIZE_USD = 1000;
|
|
45
|
+
/** Minimum annualized spread to consider profitable (%) */
|
|
46
|
+
export const MIN_PROFITABLE_SPREAD_PCT = 10;
|
|
47
|
+
/** Days to keep funding history */
|
|
48
|
+
export const FUNDING_HISTORY_RETENTION_DAYS = 7;
|
|
49
|
+
/** Default hours for historical analysis */
|
|
50
|
+
export const DEFAULT_HISTORY_HOURS = 24;
|
|
51
|
+
/** Default tracking interval (ms) */
|
|
52
|
+
export const DEFAULT_TRACK_INTERVAL_MS = 5 * 60 * 1000; // 5 minutes
|
|
53
|
+
/** Default watch mode refresh (seconds) */
|
|
54
|
+
export const DEFAULT_WATCH_INTERVAL_SEC = 30;
|
|
55
|
+
/** Alert check interval (ms) */
|
|
56
|
+
export const DEFAULT_ALERT_INTERVAL_MS = 5 * 60 * 1000; // 5 minutes
|
|
57
|
+
/** Map exchange display names to IDs */
|
|
58
|
+
export const EXCHANGE_NAME_TO_ID = {
|
|
59
|
+
"Hyperliquid": "hyperliquid",
|
|
60
|
+
"Aevo": "aevo",
|
|
61
|
+
"Paradex": "paradex",
|
|
62
|
+
"Orderly Network": "orderly",
|
|
63
|
+
"Decibel": "decibel",
|
|
64
|
+
};
|
|
65
|
+
/** Map exchange IDs to display names */
|
|
66
|
+
export const EXCHANGE_ID_TO_NAME = {
|
|
67
|
+
"hyperliquid": "Hyperliquid",
|
|
68
|
+
"aevo": "Aevo",
|
|
69
|
+
"paradex": "Paradex",
|
|
70
|
+
"orderly": "Orderly Network",
|
|
71
|
+
"decibel": "Decibel",
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Get exchange ID from display name
|
|
75
|
+
*/
|
|
76
|
+
export function getExchangeIdByName(name) {
|
|
77
|
+
return EXCHANGE_NAME_TO_ID[name] || name.toLowerCase().replace(/\s+/g, "");
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Get display name from exchange ID
|
|
81
|
+
*/
|
|
82
|
+
export function getExchangeNameById(id) {
|
|
83
|
+
return EXCHANGE_ID_TO_NAME[id] || id;
|
|
84
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { OnboardingProfile } from "./onboarding.js";
|
|
2
|
+
export interface CredentialVaultEntry {
|
|
3
|
+
id: string;
|
|
4
|
+
createdAt: string;
|
|
5
|
+
mode: string;
|
|
6
|
+
exchanges: string[];
|
|
7
|
+
wallets: {
|
|
8
|
+
evmAddress?: string;
|
|
9
|
+
aptosAddress?: string;
|
|
10
|
+
starkPublicKey?: string;
|
|
11
|
+
};
|
|
12
|
+
encrypted: Record<string, string>;
|
|
13
|
+
}
|
|
14
|
+
export declare function saveOnboardingProfileToVault(profile: OnboardingProfile): {
|
|
15
|
+
id: string;
|
|
16
|
+
path: string;
|
|
17
|
+
};
|
|
18
|
+
export declare function getCredentialVaultSummary(): {
|
|
19
|
+
path: string;
|
|
20
|
+
entries: number;
|
|
21
|
+
updatedAt?: string;
|
|
22
|
+
};
|