perp-cli 0.9.8 → 0.12.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/README.md +30 -25
- package/dist/_stderr-filter.d.ts +0 -0
- package/dist/_stderr-filter.js +30 -0
- package/dist/agent-wallet/expiry.d.ts +15 -0
- package/dist/agent-wallet/expiry.js +26 -0
- package/dist/agent-wallet/lighter-keystore.d.ts +34 -0
- package/dist/agent-wallet/lighter-keystore.js +232 -0
- package/dist/agent-wallet/passphrase.d.ts +13 -0
- package/dist/agent-wallet/passphrase.js +54 -0
- package/dist/agent-wallet/signing-strategy.d.ts +67 -0
- package/dist/agent-wallet/signing-strategy.js +51 -0
- package/dist/agent-wallet/store.d.ts +37 -0
- package/dist/agent-wallet/store.js +172 -0
- package/dist/api/public/_http.d.ts +15 -0
- package/dist/api/public/_http.js +24 -0
- package/dist/api/public/hyperliquid.js +36 -24
- package/dist/api/public/lighter.d.ts +7 -1
- package/dist/api/public/lighter.js +85 -37
- package/dist/api/public/pacifica.js +47 -18
- package/dist/bot/engine.js +23 -4
- package/dist/bot/presets.js +3 -3
- package/dist/bot/strategies/funding-arb-strategy.d.ts +0 -23
- package/dist/bot/strategies/funding-arb-strategy.js +41 -176
- package/dist/bot/strategies/funding-auto.js +2 -2
- package/dist/bridge-engine.js +102 -49
- package/dist/cli-spec.js +1 -2
- package/dist/commands/account.js +2 -500
- package/dist/commands/agent.d.ts +8 -2
- package/dist/commands/agent.js +1903 -366
- package/dist/commands/alerts.js +3 -1
- package/dist/commands/arb/index.js +37 -7
- package/dist/commands/arb-auto.js +44 -11
- package/dist/commands/arb.js +83 -34
- package/dist/commands/bot.d.ts +1 -1
- package/dist/commands/bot.js +20 -16
- package/dist/commands/bridge.d.ts +1 -1
- package/dist/commands/bridge.js +4 -4
- package/dist/commands/funds.d.ts +1 -1
- package/dist/commands/funds.js +18 -68
- package/dist/commands/jobs.d.ts +1 -1
- package/dist/commands/jobs.js +2 -2
- package/dist/commands/manage.d.ts +1 -1
- package/dist/commands/manage.js +12 -84
- package/dist/commands/plan.d.ts +1 -1
- package/dist/commands/plan.js +2 -2
- package/dist/commands/portfolio.d.ts +19 -3
- package/dist/commands/portfolio.js +747 -163
- package/dist/commands/rebalance.d.ts +1 -1
- package/dist/commands/rebalance.js +18 -12
- package/dist/commands/risk.js +2 -6
- package/dist/commands/settings.js +30 -53
- package/dist/commands/trade.js +16 -15
- package/dist/commands/wallet.d.ts +2 -1
- package/dist/commands/wallet.js +1122 -176
- package/dist/config.d.ts +9 -0
- package/dist/config.js +55 -9
- package/dist/errors.d.ts +64 -0
- package/dist/errors.js +82 -2
- package/dist/event-stream.js +12 -1
- package/dist/exchanges/aster-typed-data.d.ts +156 -0
- package/dist/exchanges/aster-typed-data.js +189 -0
- package/dist/exchanges/aster.d.ts +60 -11
- package/dist/exchanges/aster.js +278 -136
- package/dist/exchanges/hyperliquid.d.ts +14 -0
- package/dist/exchanges/hyperliquid.js +88 -34
- package/dist/exchanges/lighter-spot.js +19 -5
- package/dist/exchanges/lighter.d.ts +66 -0
- package/dist/exchanges/lighter.js +213 -31
- package/dist/exchanges/pacifica-typed-data.d.ts +75 -0
- package/dist/exchanges/pacifica-typed-data.js +74 -0
- package/dist/exchanges/pacifica.d.ts +29 -1
- package/dist/exchanges/pacifica.js +94 -6
- package/dist/funding/rates.js +59 -21
- package/dist/guardrail/contracts.d.ts +14 -0
- package/dist/guardrail/contracts.js +72 -0
- package/dist/guardrail/perp-guardrail.d.ts +21 -0
- package/dist/guardrail/perp-guardrail.js +145 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +307 -362
- package/dist/jobs.js +3 -1
- package/dist/mcp-server.js +92 -88
- package/dist/position-history.js +47 -4
- package/dist/settings.d.ts +69 -3
- package/dist/settings.js +3 -2
- package/dist/signer/index.d.ts +2 -0
- package/dist/signer/index.js +2 -0
- package/dist/signer/ows-evm.d.ts +32 -0
- package/dist/signer/ows-evm.js +86 -0
- package/dist/signer/ows-loader.d.ts +2 -0
- package/dist/signer/ows-loader.js +6 -0
- package/dist/signer/ows-solana.d.ts +25 -0
- package/dist/signer/ows-solana.js +56 -0
- package/dist/smart-order.d.ts +8 -2
- package/dist/smart-order.js +46 -11
- package/dist/strategies/funding-arb.js +29 -8
- package/dist/trade-validator.js +30 -5
- package/dist/utils.d.ts +10 -0
- package/dist/utils.js +19 -0
- package/package.json +4 -2
- package/skills/perp-cli/SKILL.md +23 -14
- package/skills/perp-cli/references/agent-operations.md +6 -4
- package/skills/perp-cli/references/commands.md +55 -34
- package/skills/perp-cli/scripts/preflight.sh +4 -4
- package/skills/perp-cli/scripts/spot-perp-scan.sh +2 -2
- package/dist/__tests__/alert-logic.test.d.ts +0 -1
- package/dist/__tests__/alert-logic.test.js +0 -107
- package/dist/__tests__/arb-auto-3dex.test.d.ts +0 -1
- package/dist/__tests__/arb-auto-3dex.test.js +0 -397
- package/dist/__tests__/arb-history-stats.test.d.ts +0 -1
- package/dist/__tests__/arb-history-stats.test.js +0 -176
- package/dist/__tests__/arb-logic.test.d.ts +0 -1
- package/dist/__tests__/arb-logic.test.js +0 -84
- package/dist/__tests__/arb-manage.test.d.ts +0 -1
- package/dist/__tests__/arb-manage.test.js +0 -253
- package/dist/__tests__/arb-new-features.test.d.ts +0 -1
- package/dist/__tests__/arb-new-features.test.js +0 -457
- package/dist/__tests__/arb-sizing.test.d.ts +0 -1
- package/dist/__tests__/arb-sizing.test.js +0 -48
- package/dist/__tests__/arb-state.test.d.ts +0 -1
- package/dist/__tests__/arb-state.test.js +0 -284
- package/dist/__tests__/arb-userflow.test.d.ts +0 -1
- package/dist/__tests__/arb-userflow.test.js +0 -945
- package/dist/__tests__/arb-utils.test.d.ts +0 -1
- package/dist/__tests__/arb-utils.test.js +0 -264
- package/dist/__tests__/bot-conditions.test.d.ts +0 -1
- package/dist/__tests__/bot-conditions.test.js +0 -341
- package/dist/__tests__/client-id-tracker.test.d.ts +0 -1
- package/dist/__tests__/client-id-tracker.test.js +0 -137
- package/dist/__tests__/commands/new-atomic-commands.test.d.ts +0 -1
- package/dist/__tests__/commands/new-atomic-commands.test.js +0 -502
- package/dist/__tests__/commands/order-intent.test.d.ts +0 -1
- package/dist/__tests__/commands/order-intent.test.js +0 -600
- package/dist/__tests__/commands/trade-commands.test.d.ts +0 -1
- package/dist/__tests__/commands/trade-commands.test.js +0 -821
- package/dist/__tests__/config.test.d.ts +0 -1
- package/dist/__tests__/config.test.js +0 -86
- package/dist/__tests__/cross-chain-margin.test.d.ts +0 -1
- package/dist/__tests__/cross-chain-margin.test.js +0 -287
- package/dist/__tests__/dex-asset-map.test.d.ts +0 -1
- package/dist/__tests__/dex-asset-map.test.js +0 -191
- package/dist/__tests__/errors.test.d.ts +0 -1
- package/dist/__tests__/errors.test.js +0 -110
- package/dist/__tests__/event-stream.test.d.ts +0 -1
- package/dist/__tests__/event-stream.test.js +0 -276
- package/dist/__tests__/exchanges/interface.test.d.ts +0 -1
- package/dist/__tests__/exchanges/interface.test.js +0 -132
- package/dist/__tests__/exchanges/mock-adapter.d.ts +0 -69
- package/dist/__tests__/exchanges/mock-adapter.js +0 -137
- package/dist/__tests__/execution-log.test.d.ts +0 -1
- package/dist/__tests__/execution-log.test.js +0 -106
- package/dist/__tests__/funding-calc.test.d.ts +0 -1
- package/dist/__tests__/funding-calc.test.js +0 -71
- package/dist/__tests__/funding-history.test.d.ts +0 -1
- package/dist/__tests__/funding-history.test.js +0 -343
- package/dist/__tests__/funding-rates.test.d.ts +0 -1
- package/dist/__tests__/funding-rates.test.js +0 -342
- package/dist/__tests__/funding.test.d.ts +0 -1
- package/dist/__tests__/funding.test.js +0 -173
- package/dist/__tests__/gap-logic.test.d.ts +0 -1
- package/dist/__tests__/gap-logic.test.js +0 -43
- package/dist/__tests__/hip3-dex.test.d.ts +0 -1
- package/dist/__tests__/hip3-dex.test.js +0 -234
- package/dist/__tests__/integration/agent-features.integration.test.d.ts +0 -1
- package/dist/__tests__/integration/agent-features.integration.test.js +0 -553
- package/dist/__tests__/integration/atomic-commands.integration.test.d.ts +0 -13
- package/dist/__tests__/integration/atomic-commands.integration.test.js +0 -246
- package/dist/__tests__/integration/bridge-simulation.integration.test.d.ts +0 -1
- package/dist/__tests__/integration/bridge-simulation.integration.test.js +0 -453
- package/dist/__tests__/integration/bridge-strict.integration.test.d.ts +0 -1
- package/dist/__tests__/integration/bridge-strict.integration.test.js +0 -812
- package/dist/__tests__/integration/bridge.integration.test.d.ts +0 -1
- package/dist/__tests__/integration/bridge.integration.test.js +0 -309
- package/dist/__tests__/integration/cli-e2e.integration.test.d.ts +0 -1
- package/dist/__tests__/integration/cli-e2e.integration.test.js +0 -202
- package/dist/__tests__/integration/dex-arb.integration.test.d.ts +0 -1
- package/dist/__tests__/integration/dex-arb.integration.test.js +0 -116
- package/dist/__tests__/integration/envelope-consistency.integration.test.d.ts +0 -13
- package/dist/__tests__/integration/envelope-consistency.integration.test.js +0 -205
- package/dist/__tests__/integration/hip3-dex.integration.test.d.ts +0 -1
- package/dist/__tests__/integration/hip3-dex.integration.test.js +0 -147
- package/dist/__tests__/integration/hyperliquid.integration.test.d.ts +0 -1
- package/dist/__tests__/integration/hyperliquid.integration.test.js +0 -79
- package/dist/__tests__/integration/lighter.integration.test.d.ts +0 -1
- package/dist/__tests__/integration/lighter.integration.test.js +0 -53
- package/dist/__tests__/integration/new-commands-e2e.integration.test.d.ts +0 -9
- package/dist/__tests__/integration/new-commands-e2e.integration.test.js +0 -236
- package/dist/__tests__/integration/order-verification.integration.test.d.ts +0 -1
- package/dist/__tests__/integration/order-verification.integration.test.js +0 -321
- package/dist/__tests__/integration/pacifica.integration.test.d.ts +0 -1
- package/dist/__tests__/integration/pacifica.integration.test.js +0 -75
- package/dist/__tests__/integration/response-shapes.integration.test.d.ts +0 -1
- package/dist/__tests__/integration/response-shapes.integration.test.js +0 -278
- package/dist/__tests__/liquidity.test.d.ts +0 -1
- package/dist/__tests__/liquidity.test.js +0 -225
- package/dist/__tests__/plan-executor.test.d.ts +0 -1
- package/dist/__tests__/plan-executor.test.js +0 -314
- package/dist/__tests__/position-history.test.d.ts +0 -1
- package/dist/__tests__/position-history.test.js +0 -367
- package/dist/__tests__/retry.test.d.ts +0 -1
- package/dist/__tests__/retry.test.js +0 -310
- package/dist/__tests__/risk-assessment.test.d.ts +0 -1
- package/dist/__tests__/risk-assessment.test.js +0 -288
- package/dist/__tests__/security-adversarial.test.d.ts +0 -1
- package/dist/__tests__/security-adversarial.test.js +0 -574
- package/dist/__tests__/strategies.test.d.ts +0 -1
- package/dist/__tests__/strategies.test.js +0 -539
- package/dist/__tests__/trade-execution.test.d.ts +0 -1
- package/dist/__tests__/trade-execution.test.js +0 -129
- package/dist/__tests__/trade-validator.test.d.ts +0 -1
- package/dist/__tests__/trade-validator.test.js +0 -655
- package/dist/__tests__/utils.test.d.ts +0 -1
- package/dist/__tests__/utils.test.js +0 -76
- package/dist/arb/reconcile.d.ts +0 -28
- package/dist/arb/reconcile.js +0 -162
- package/dist/commands/alert.d.ts +0 -2
- package/dist/commands/alert.js +0 -421
- package/dist/commands/analytics.d.ts +0 -3
- package/dist/commands/analytics.js +0 -311
- package/dist/commands/arb-manage.d.ts +0 -5
- package/dist/commands/arb-manage.js +0 -5
- package/dist/commands/dashboard.d.ts +0 -3
- package/dist/commands/dashboard.js +0 -176
- package/dist/commands/deposit.d.ts +0 -4
- package/dist/commands/deposit.js +0 -573
- package/dist/commands/dex.d.ts +0 -3
- package/dist/commands/dex.js +0 -120
- package/dist/commands/env.d.ts +0 -2
- package/dist/commands/env.js +0 -136
- package/dist/commands/funding.d.ts +0 -3
- package/dist/commands/funding.js +0 -554
- package/dist/commands/gap.d.ts +0 -2
- package/dist/commands/gap.js +0 -305
- package/dist/commands/health.d.ts +0 -2
- package/dist/commands/health.js +0 -67
- package/dist/commands/multileg.d.ts +0 -16
- package/dist/commands/multileg.js +0 -174
- package/dist/commands/pnl.d.ts +0 -12
- package/dist/commands/pnl.js +0 -243
- package/dist/commands/run.d.ts +0 -3
- package/dist/commands/run.js +0 -202
- package/dist/commands/stream.d.ts +0 -5
- package/dist/commands/stream.js +0 -200
- package/dist/commands/withdraw.d.ts +0 -3
- package/dist/commands/withdraw.js +0 -187
- package/dist/exchanges/edgex.d.ts +0 -62
- package/dist/exchanges/edgex.js +0 -552
- package/dist/exchanges/nado.d.ts +0 -52
- package/dist/exchanges/nado.js +0 -223
- package/dist/funding/index.d.ts +0 -3
- package/dist/funding/index.js +0 -3
- package/dist/retry.d.ts +0 -74
- package/dist/retry.js +0 -129
- package/dist/ws/market-feed.d.ts +0 -74
- package/dist/ws/market-feed.js +0 -227
package/dist/exchanges/nado.js
DELETED
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Nado DEX adapter — Orderbook DEX on Ink L2.
|
|
3
|
-
* API: https://gateway.nado.xyz/v1 (mainnet) / https://gateway.test.nado.xyz/v1 (testnet)
|
|
4
|
-
* Docs: https://docs.nado.xyz/developer-resources/api/gateway
|
|
5
|
-
* Note: API documentation is incomplete — many endpoints are stubbed pending full docs.
|
|
6
|
-
*/
|
|
7
|
-
export class NadoAdapter {
|
|
8
|
-
name = "nado";
|
|
9
|
-
chain = "ink";
|
|
10
|
-
aliases = ["nad"];
|
|
11
|
-
_baseUrl;
|
|
12
|
-
_apiKey;
|
|
13
|
-
constructor(apiKey, testnet = false) {
|
|
14
|
-
this._apiKey = apiKey || process.env.NADO_API_KEY || "";
|
|
15
|
-
this._baseUrl = testnet
|
|
16
|
-
? "https://gateway.test.nado.xyz/v1"
|
|
17
|
-
: "https://gateway.nado.xyz/v1";
|
|
18
|
-
}
|
|
19
|
-
async init() {
|
|
20
|
-
// Verify connectivity
|
|
21
|
-
try {
|
|
22
|
-
await this._get("/markets");
|
|
23
|
-
}
|
|
24
|
-
catch { /* non-critical */ }
|
|
25
|
-
}
|
|
26
|
-
async getMarkets() {
|
|
27
|
-
try {
|
|
28
|
-
const data = await this._get("/markets");
|
|
29
|
-
return (data ?? []).map(m => ({
|
|
30
|
-
symbol: String(m.symbol ?? m.name ?? ""),
|
|
31
|
-
markPrice: String(m.mark_price ?? m.last_price ?? "0"),
|
|
32
|
-
indexPrice: String(m.index_price ?? "0"),
|
|
33
|
-
fundingRate: String(m.funding_rate ?? "0"),
|
|
34
|
-
volume24h: String(m.volume_24h ?? m.volume ?? "0"),
|
|
35
|
-
openInterest: String(m.open_interest ?? "0"),
|
|
36
|
-
maxLeverage: Number(m.max_leverage ?? 50),
|
|
37
|
-
}));
|
|
38
|
-
}
|
|
39
|
-
catch {
|
|
40
|
-
return [];
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
async getOrderbook(symbol) {
|
|
44
|
-
try {
|
|
45
|
-
const data = await this._get(`/orderbook?symbol=${symbol}`);
|
|
46
|
-
return {
|
|
47
|
-
bids: (data.bids ?? []),
|
|
48
|
-
asks: (data.asks ?? []),
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
catch {
|
|
52
|
-
return { bids: [], asks: [] };
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
async getRecentTrades(symbol, limit = 20) {
|
|
56
|
-
try {
|
|
57
|
-
const data = await this._get(`/trades?symbol=${symbol}&limit=${limit}`);
|
|
58
|
-
return (data ?? []).map(t => ({
|
|
59
|
-
time: Number(t.time ?? t.timestamp ?? 0),
|
|
60
|
-
symbol, side: String(t.side ?? "buy"),
|
|
61
|
-
price: String(t.price ?? "0"), size: String(t.size ?? t.qty ?? "0"), fee: "0",
|
|
62
|
-
}));
|
|
63
|
-
}
|
|
64
|
-
catch {
|
|
65
|
-
return [];
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
async getFundingHistory(symbol, _limit = 10) {
|
|
69
|
-
try {
|
|
70
|
-
const data = await this._get(`/funding?symbol=${symbol}`);
|
|
71
|
-
return (data ?? []).map(f => ({
|
|
72
|
-
time: Number(f.time ?? 0), rate: String(f.rate ?? "0"), price: null,
|
|
73
|
-
}));
|
|
74
|
-
}
|
|
75
|
-
catch {
|
|
76
|
-
return [];
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
async getKlines(symbol, interval, startTime, endTime) {
|
|
80
|
-
try {
|
|
81
|
-
const data = await this._get(`/klines?symbol=${symbol}&interval=${interval}&start=${startTime}&end=${endTime}`);
|
|
82
|
-
return (data ?? []).map(k => ({
|
|
83
|
-
time: Number(k[0]), open: String(k[1]), high: String(k[2]),
|
|
84
|
-
low: String(k[3]), close: String(k[4]), volume: String(k[5]), trades: 0,
|
|
85
|
-
}));
|
|
86
|
-
}
|
|
87
|
-
catch {
|
|
88
|
-
return [];
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
async getBalance() {
|
|
92
|
-
if (!this._apiKey)
|
|
93
|
-
throw new Error("Nado API key required. Set NADO_API_KEY.");
|
|
94
|
-
const data = await this._authGet("/account/balance");
|
|
95
|
-
return {
|
|
96
|
-
equity: String(data.equity ?? data.total ?? "0"),
|
|
97
|
-
available: String(data.available ?? data.free ?? "0"),
|
|
98
|
-
marginUsed: String(data.margin_used ?? "0"),
|
|
99
|
-
unrealizedPnl: String(data.unrealized_pnl ?? "0"),
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
async getPositions() {
|
|
103
|
-
if (!this._apiKey)
|
|
104
|
-
throw new Error("Nado API key required. Set NADO_API_KEY.");
|
|
105
|
-
const data = await this._authGet("/account/positions");
|
|
106
|
-
return (data ?? []).filter(p => Number(p.size ?? 0) !== 0).map(p => ({
|
|
107
|
-
symbol: String(p.symbol ?? ""), side: Number(p.size ?? 0) > 0 ? "long" : "short",
|
|
108
|
-
size: String(Math.abs(Number(p.size ?? 0))), entryPrice: String(p.entry_price ?? "0"),
|
|
109
|
-
markPrice: String(p.mark_price ?? "0"), liquidationPrice: String(p.liquidation_price ?? "N/A"),
|
|
110
|
-
unrealizedPnl: String(p.unrealized_pnl ?? "0"), leverage: Number(p.leverage ?? 1),
|
|
111
|
-
}));
|
|
112
|
-
}
|
|
113
|
-
async getOpenOrders() {
|
|
114
|
-
if (!this._apiKey)
|
|
115
|
-
throw new Error("Nado API key required. Set NADO_API_KEY.");
|
|
116
|
-
const data = await this._authGet("/account/orders");
|
|
117
|
-
return (data ?? []).map(o => ({
|
|
118
|
-
orderId: String(o.order_id ?? o.id ?? ""), symbol: String(o.symbol ?? ""),
|
|
119
|
-
side: String(o.side ?? "buy").toLowerCase(),
|
|
120
|
-
price: String(o.price ?? "0"), size: String(o.size ?? o.qty ?? "0"),
|
|
121
|
-
filled: String(o.filled ?? "0"), status: String(o.status ?? "open"), type: String(o.type ?? "limit"),
|
|
122
|
-
}));
|
|
123
|
-
}
|
|
124
|
-
async getOrderHistory(limit = 30) {
|
|
125
|
-
if (!this._apiKey)
|
|
126
|
-
throw new Error("Nado API key required. Set NADO_API_KEY.");
|
|
127
|
-
const data = await this._authGet(`/account/orders/history?limit=${limit}`);
|
|
128
|
-
return (data ?? []).map(o => ({
|
|
129
|
-
orderId: String(o.order_id ?? o.id ?? ""), symbol: String(o.symbol ?? ""),
|
|
130
|
-
side: String(o.side ?? "buy").toLowerCase(),
|
|
131
|
-
price: String(o.price ?? "0"), size: String(o.size ?? "0"),
|
|
132
|
-
filled: String(o.filled ?? "0"), status: String(o.status ?? "done"), type: String(o.type ?? "limit"),
|
|
133
|
-
}));
|
|
134
|
-
}
|
|
135
|
-
async getTradeHistory(limit = 30) {
|
|
136
|
-
if (!this._apiKey)
|
|
137
|
-
throw new Error("Nado API key required. Set NADO_API_KEY.");
|
|
138
|
-
const data = await this._authGet(`/account/trades?limit=${limit}`);
|
|
139
|
-
return (data ?? []).map(t => ({
|
|
140
|
-
time: Number(t.time ?? t.timestamp ?? 0), symbol: String(t.symbol ?? ""),
|
|
141
|
-
side: String(t.side ?? "buy").toLowerCase(),
|
|
142
|
-
price: String(t.price ?? "0"), size: String(t.size ?? "0"), fee: String(t.fee ?? "0"),
|
|
143
|
-
}));
|
|
144
|
-
}
|
|
145
|
-
async getFundingPayments(limit = 200) {
|
|
146
|
-
if (!this._apiKey)
|
|
147
|
-
throw new Error("Nado API key required. Set NADO_API_KEY.");
|
|
148
|
-
const data = await this._authGet(`/account/funding?limit=${limit}`);
|
|
149
|
-
return (data ?? []).map(f => ({
|
|
150
|
-
time: Number(f.time ?? 0), symbol: String(f.symbol ?? ""), payment: String(f.payment ?? f.amount ?? "0"),
|
|
151
|
-
}));
|
|
152
|
-
}
|
|
153
|
-
async marketOrder(symbol, side, size) {
|
|
154
|
-
return this._authPost("/orders", { symbol, side, size, type: "market" });
|
|
155
|
-
}
|
|
156
|
-
async limitOrder(symbol, side, price, size, opts) {
|
|
157
|
-
return this._authPost("/orders", { symbol, side, price, size, type: "limit", time_in_force: opts?.tif ?? "GTC", reduce_only: opts?.reduceOnly ?? false });
|
|
158
|
-
}
|
|
159
|
-
async editOrder(symbol, orderId, price, size) {
|
|
160
|
-
return this._authPost(`/orders/${orderId}`, { symbol, price, size });
|
|
161
|
-
}
|
|
162
|
-
async cancelOrder(symbol, orderId) {
|
|
163
|
-
return this._authDelete(`/orders/${orderId}?symbol=${symbol}`);
|
|
164
|
-
}
|
|
165
|
-
async cancelAllOrders(symbol) {
|
|
166
|
-
return this._authDelete(`/orders${symbol ? `?symbol=${symbol}` : ""}`);
|
|
167
|
-
}
|
|
168
|
-
async setLeverage(symbol, leverage, marginMode) {
|
|
169
|
-
return this._authPost("/leverage", { symbol, leverage, margin_mode: marginMode ?? "cross" });
|
|
170
|
-
}
|
|
171
|
-
async stopOrder(symbol, side, size, triggerPrice, opts) {
|
|
172
|
-
return this._authPost("/orders", {
|
|
173
|
-
symbol, side, size, type: opts?.limitPrice ? "stop_limit" : "stop_market",
|
|
174
|
-
trigger_price: triggerPrice, price: opts?.limitPrice, reduce_only: opts?.reduceOnly ?? true,
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
async withdraw(amount, destination) {
|
|
178
|
-
return this._authPost("/withdraw", { amount, destination });
|
|
179
|
-
}
|
|
180
|
-
async _get(path) {
|
|
181
|
-
const res = await fetch(`${this._baseUrl}${path}`, {
|
|
182
|
-
headers: { "Accept-Encoding": "gzip" },
|
|
183
|
-
});
|
|
184
|
-
if (!res.ok)
|
|
185
|
-
throw new Error(`GET ${path} failed (${res.status})`);
|
|
186
|
-
return res.json();
|
|
187
|
-
}
|
|
188
|
-
async _authGet(path) {
|
|
189
|
-
if (!this._apiKey)
|
|
190
|
-
throw new Error("Nado API key required. Set NADO_API_KEY.");
|
|
191
|
-
const res = await fetch(`${this._baseUrl}${path}`, {
|
|
192
|
-
headers: { "Accept-Encoding": "gzip", "Authorization": `Bearer ${this._apiKey}` },
|
|
193
|
-
});
|
|
194
|
-
if (!res.ok)
|
|
195
|
-
throw new Error(`GET ${path} failed (${res.status})`);
|
|
196
|
-
return res.json();
|
|
197
|
-
}
|
|
198
|
-
async _authPost(path, body) {
|
|
199
|
-
if (!this._apiKey)
|
|
200
|
-
throw new Error("Nado API key required. Set NADO_API_KEY.");
|
|
201
|
-
const res = await fetch(`${this._baseUrl}${path}`, {
|
|
202
|
-
method: "POST",
|
|
203
|
-
headers: { "Accept-Encoding": "gzip", "Authorization": `Bearer ${this._apiKey}`, "Content-Type": "application/json" },
|
|
204
|
-
body: JSON.stringify(body),
|
|
205
|
-
});
|
|
206
|
-
if (!res.ok)
|
|
207
|
-
throw new Error(`POST ${path} failed (${res.status})`);
|
|
208
|
-
return res.json();
|
|
209
|
-
}
|
|
210
|
-
async _authDelete(path) {
|
|
211
|
-
if (!this._apiKey)
|
|
212
|
-
throw new Error("Nado API key required. Set NADO_API_KEY.");
|
|
213
|
-
const res = await fetch(`${this._baseUrl}${path}`, {
|
|
214
|
-
method: "DELETE",
|
|
215
|
-
headers: { "Accept-Encoding": "gzip", "Authorization": `Bearer ${this._apiKey}` },
|
|
216
|
-
});
|
|
217
|
-
if (!res.ok)
|
|
218
|
-
throw new Error(`DELETE ${path} failed (${res.status})`);
|
|
219
|
-
if (res.status === 204)
|
|
220
|
-
return {};
|
|
221
|
-
return res.json();
|
|
222
|
-
}
|
|
223
|
-
}
|
package/dist/funding/index.d.ts
DELETED
package/dist/funding/index.js
DELETED
package/dist/retry.d.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Auto-retry middleware for exchange operations.
|
|
3
|
-
* Retries operations that fail with retryable error codes.
|
|
4
|
-
*/
|
|
5
|
-
import { type StructuredError } from "./errors.js";
|
|
6
|
-
import type { ExchangeAdapter } from "./exchanges/interface.js";
|
|
7
|
-
export interface RetryOptions {
|
|
8
|
-
maxRetries?: number;
|
|
9
|
-
baseDelayMs?: number;
|
|
10
|
-
maxDelayMs?: number;
|
|
11
|
-
backoffMultiplier?: number;
|
|
12
|
-
onRetry?: (attempt: number, error: StructuredError, delayMs: number) => void;
|
|
13
|
-
}
|
|
14
|
-
export interface RetryResult<T> {
|
|
15
|
-
data: T;
|
|
16
|
-
attempts: number;
|
|
17
|
-
totalDelayMs: number;
|
|
18
|
-
retries: {
|
|
19
|
-
attempt: number;
|
|
20
|
-
error: StructuredError;
|
|
21
|
-
delayMs: number;
|
|
22
|
-
}[];
|
|
23
|
-
}
|
|
24
|
-
/** Error thrown when all retries are exhausted */
|
|
25
|
-
export declare class RetriesExhaustedError extends Error {
|
|
26
|
-
readonly lastError: StructuredError;
|
|
27
|
-
readonly attempts: number;
|
|
28
|
-
readonly retries: {
|
|
29
|
-
attempt: number;
|
|
30
|
-
error: StructuredError;
|
|
31
|
-
delayMs: number;
|
|
32
|
-
}[];
|
|
33
|
-
constructor(lastError: StructuredError, attempts: number, retries: {
|
|
34
|
-
attempt: number;
|
|
35
|
-
error: StructuredError;
|
|
36
|
-
delayMs: number;
|
|
37
|
-
}[]);
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Apply jitter of +/-20% to a delay value.
|
|
41
|
-
* Returns a value in [delay * 0.8, delay * 1.2].
|
|
42
|
-
*/
|
|
43
|
-
export declare function applyJitter(delayMs: number): number;
|
|
44
|
-
/**
|
|
45
|
-
* Compute the delay for a given retry attempt.
|
|
46
|
-
* Uses exponential backoff, respects retryAfterMs from the error code,
|
|
47
|
-
* applies jitter, and caps at maxDelayMs.
|
|
48
|
-
*/
|
|
49
|
-
export declare function computeDelay(attempt: number, error: StructuredError, opts: Required<Omit<RetryOptions, "onRetry">>): number;
|
|
50
|
-
/**
|
|
51
|
-
* Execute `fn` with automatic retry on retryable errors.
|
|
52
|
-
*
|
|
53
|
-
* - On failure, classifies the error via `classifyError`.
|
|
54
|
-
* - If `retryable: true`, waits with exponential backoff and retries.
|
|
55
|
-
* - If `retryable: false`, throws immediately.
|
|
56
|
-
* - Uses `retryAfterMs` from the error code if available (e.g., rate limit = 1000ms).
|
|
57
|
-
* - Caps delay at `maxDelayMs`.
|
|
58
|
-
* - Adds jitter (+/-20%) to prevent thundering herd.
|
|
59
|
-
* - Returns the result with retry metadata.
|
|
60
|
-
*/
|
|
61
|
-
export declare function withRetry<T>(fn: () => Promise<T>, opts?: RetryOptions): Promise<RetryResult<T>>;
|
|
62
|
-
/**
|
|
63
|
-
* Simpler version of withRetry that just returns T (no metadata).
|
|
64
|
-
* For use in places where you just want automatic retry without caring about details.
|
|
65
|
-
*/
|
|
66
|
-
export declare function withRetrySimple<T>(fn: () => Promise<T>, maxRetries?: number): Promise<T>;
|
|
67
|
-
/**
|
|
68
|
-
* Wrap an ExchangeAdapter so every async method is automatically retried.
|
|
69
|
-
*
|
|
70
|
-
* Returns a Proxy that intercepts property access:
|
|
71
|
-
* - For non-function properties (like `name`), returns the value directly.
|
|
72
|
-
* - For function properties, returns a wrapper that calls `withRetry` around the original method.
|
|
73
|
-
*/
|
|
74
|
-
export declare function wrapAdapterWithRetry(adapter: ExchangeAdapter, opts?: RetryOptions): ExchangeAdapter;
|
package/dist/retry.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Auto-retry middleware for exchange operations.
|
|
3
|
-
* Retries operations that fail with retryable error codes.
|
|
4
|
-
*/
|
|
5
|
-
import { classifyError } from "./errors.js";
|
|
6
|
-
/** Error thrown when all retries are exhausted */
|
|
7
|
-
export class RetriesExhaustedError extends Error {
|
|
8
|
-
lastError;
|
|
9
|
-
attempts;
|
|
10
|
-
retries;
|
|
11
|
-
constructor(lastError, attempts, retries) {
|
|
12
|
-
super(`All ${attempts} attempts failed. Last error: [${lastError.code}] ${lastError.message}`);
|
|
13
|
-
this.name = "RetriesExhaustedError";
|
|
14
|
-
this.lastError = lastError;
|
|
15
|
-
this.attempts = attempts;
|
|
16
|
-
this.retries = retries;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
const DEFAULT_OPTIONS = {
|
|
20
|
-
maxRetries: 3,
|
|
21
|
-
baseDelayMs: 1000,
|
|
22
|
-
maxDelayMs: 30000,
|
|
23
|
-
backoffMultiplier: 2,
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* Apply jitter of +/-20% to a delay value.
|
|
27
|
-
* Returns a value in [delay * 0.8, delay * 1.2].
|
|
28
|
-
*/
|
|
29
|
-
export function applyJitter(delayMs) {
|
|
30
|
-
const jitterFactor = 0.8 + Math.random() * 0.4; // [0.8, 1.2]
|
|
31
|
-
return Math.round(delayMs * jitterFactor);
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Compute the delay for a given retry attempt.
|
|
35
|
-
* Uses exponential backoff, respects retryAfterMs from the error code,
|
|
36
|
-
* applies jitter, and caps at maxDelayMs.
|
|
37
|
-
*/
|
|
38
|
-
export function computeDelay(attempt, error, opts) {
|
|
39
|
-
// Start with exponential backoff: baseDelay * multiplier^(attempt-1)
|
|
40
|
-
let delay = opts.baseDelayMs * Math.pow(opts.backoffMultiplier, attempt - 1);
|
|
41
|
-
// If the error specifies a retryAfterMs, use the larger of the two
|
|
42
|
-
if (error.retryAfterMs !== undefined) {
|
|
43
|
-
delay = Math.max(delay, error.retryAfterMs);
|
|
44
|
-
}
|
|
45
|
-
// Cap at maxDelayMs
|
|
46
|
-
delay = Math.min(delay, opts.maxDelayMs);
|
|
47
|
-
// Apply jitter
|
|
48
|
-
return applyJitter(delay);
|
|
49
|
-
}
|
|
50
|
-
/** Internal sleep helper */
|
|
51
|
-
function sleep(ms) {
|
|
52
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Execute `fn` with automatic retry on retryable errors.
|
|
56
|
-
*
|
|
57
|
-
* - On failure, classifies the error via `classifyError`.
|
|
58
|
-
* - If `retryable: true`, waits with exponential backoff and retries.
|
|
59
|
-
* - If `retryable: false`, throws immediately.
|
|
60
|
-
* - Uses `retryAfterMs` from the error code if available (e.g., rate limit = 1000ms).
|
|
61
|
-
* - Caps delay at `maxDelayMs`.
|
|
62
|
-
* - Adds jitter (+/-20%) to prevent thundering herd.
|
|
63
|
-
* - Returns the result with retry metadata.
|
|
64
|
-
*/
|
|
65
|
-
export async function withRetry(fn, opts) {
|
|
66
|
-
const { maxRetries, baseDelayMs, maxDelayMs, backoffMultiplier } = {
|
|
67
|
-
...DEFAULT_OPTIONS,
|
|
68
|
-
...opts,
|
|
69
|
-
};
|
|
70
|
-
const resolvedOpts = { maxRetries, baseDelayMs, maxDelayMs, backoffMultiplier };
|
|
71
|
-
const retries = [];
|
|
72
|
-
let totalDelayMs = 0;
|
|
73
|
-
for (let attempt = 1; attempt <= maxRetries + 1; attempt++) {
|
|
74
|
-
try {
|
|
75
|
-
const data = await fn();
|
|
76
|
-
return { data, attempts: attempt, totalDelayMs, retries };
|
|
77
|
-
}
|
|
78
|
-
catch (err) {
|
|
79
|
-
const classified = classifyError(err);
|
|
80
|
-
// Non-retryable error: throw immediately
|
|
81
|
-
if (!classified.retryable) {
|
|
82
|
-
throw err;
|
|
83
|
-
}
|
|
84
|
-
// Out of retries: throw with exhaustion info
|
|
85
|
-
if (attempt > maxRetries) {
|
|
86
|
-
throw new RetriesExhaustedError(classified, attempt, retries);
|
|
87
|
-
}
|
|
88
|
-
const delayMs = computeDelay(attempt, classified, resolvedOpts);
|
|
89
|
-
// Call onRetry callback if provided
|
|
90
|
-
opts?.onRetry?.(attempt, classified, delayMs);
|
|
91
|
-
retries.push({ attempt, error: classified, delayMs });
|
|
92
|
-
totalDelayMs += delayMs;
|
|
93
|
-
await sleep(delayMs);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
// Unreachable, but TypeScript needs it
|
|
97
|
-
throw new Error("withRetry: unexpected exit from retry loop");
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Simpler version of withRetry that just returns T (no metadata).
|
|
101
|
-
* For use in places where you just want automatic retry without caring about details.
|
|
102
|
-
*/
|
|
103
|
-
export async function withRetrySimple(fn, maxRetries) {
|
|
104
|
-
const result = await withRetry(fn, maxRetries !== undefined ? { maxRetries } : undefined);
|
|
105
|
-
return result.data;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Wrap an ExchangeAdapter so every async method is automatically retried.
|
|
109
|
-
*
|
|
110
|
-
* Returns a Proxy that intercepts property access:
|
|
111
|
-
* - For non-function properties (like `name`), returns the value directly.
|
|
112
|
-
* - For function properties, returns a wrapper that calls `withRetry` around the original method.
|
|
113
|
-
*/
|
|
114
|
-
export function wrapAdapterWithRetry(adapter, opts) {
|
|
115
|
-
return new Proxy(adapter, {
|
|
116
|
-
get(target, prop, receiver) {
|
|
117
|
-
const value = Reflect.get(target, prop, receiver);
|
|
118
|
-
// Pass through non-function properties (e.g., `name` getter)
|
|
119
|
-
if (typeof value !== "function") {
|
|
120
|
-
return value;
|
|
121
|
-
}
|
|
122
|
-
// Wrap function in retry logic
|
|
123
|
-
return async function (...args) {
|
|
124
|
-
const result = await withRetry(() => value.apply(target, args), opts);
|
|
125
|
-
return result.data;
|
|
126
|
-
};
|
|
127
|
-
},
|
|
128
|
-
});
|
|
129
|
-
}
|
package/dist/ws/market-feed.d.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unified market data feeds for CLI streaming commands.
|
|
3
|
-
*
|
|
4
|
-
* - Hyperliquid: native WebSocket (allMids, l2Book, trades, candle)
|
|
5
|
-
* - Lighter: REST polling (no public market data WS)
|
|
6
|
-
* - Pacifica: handled via existing PacificaWSClient in stream.ts
|
|
7
|
-
*/
|
|
8
|
-
import { EventEmitter } from "events";
|
|
9
|
-
export interface PriceUpdate {
|
|
10
|
-
symbol: string;
|
|
11
|
-
mid: number;
|
|
12
|
-
funding?: number;
|
|
13
|
-
}
|
|
14
|
-
export interface BookUpdate {
|
|
15
|
-
bids: [string, string][];
|
|
16
|
-
asks: [string, string][];
|
|
17
|
-
}
|
|
18
|
-
export interface TradeUpdate {
|
|
19
|
-
side: string;
|
|
20
|
-
price: string;
|
|
21
|
-
size: string;
|
|
22
|
-
time: number;
|
|
23
|
-
}
|
|
24
|
-
export interface CandleUpdate {
|
|
25
|
-
o: string;
|
|
26
|
-
h: string;
|
|
27
|
-
l: string;
|
|
28
|
-
c: string;
|
|
29
|
-
v: string;
|
|
30
|
-
t: number;
|
|
31
|
-
}
|
|
32
|
-
export declare class HyperliquidMarketFeed extends EventEmitter {
|
|
33
|
-
private ws;
|
|
34
|
-
private closed;
|
|
35
|
-
private reconnectTimer;
|
|
36
|
-
private subs;
|
|
37
|
-
get wsUrl(): string;
|
|
38
|
-
connect(): Promise<void>;
|
|
39
|
-
private send;
|
|
40
|
-
private sub;
|
|
41
|
-
private scheduleReconnect;
|
|
42
|
-
subscribePrices(): void;
|
|
43
|
-
subscribeBook(symbol: string): void;
|
|
44
|
-
subscribeTrades(symbol: string): void;
|
|
45
|
-
subscribeCandle(symbol: string, interval: string): void;
|
|
46
|
-
private handleMessage;
|
|
47
|
-
close(): void;
|
|
48
|
-
}
|
|
49
|
-
export interface LighterFeedOpts {
|
|
50
|
-
/** Polling interval for prices in ms (default: 3000) */
|
|
51
|
-
pricesIntervalMs?: number;
|
|
52
|
-
/** Polling interval for book/trades in ms (default: 2000) */
|
|
53
|
-
bookIntervalMs?: number;
|
|
54
|
-
/** Polling interval for candles in ms (default: 5000) */
|
|
55
|
-
candleIntervalMs?: number;
|
|
56
|
-
}
|
|
57
|
-
export declare class LighterMarketFeed extends EventEmitter {
|
|
58
|
-
private closed;
|
|
59
|
-
private timers;
|
|
60
|
-
private marketMap;
|
|
61
|
-
private pricesMs;
|
|
62
|
-
private bookMs;
|
|
63
|
-
private candleMs;
|
|
64
|
-
constructor(opts?: LighterFeedOpts);
|
|
65
|
-
connect(): Promise<void>;
|
|
66
|
-
private getMarketId;
|
|
67
|
-
private poll;
|
|
68
|
-
subscribePrices(): void;
|
|
69
|
-
subscribeBook(symbol: string): void;
|
|
70
|
-
subscribeTrades(symbol: string): void;
|
|
71
|
-
subscribeCandle(symbol: string, interval: string): void;
|
|
72
|
-
close(): void;
|
|
73
|
-
}
|
|
74
|
-
export declare function createMarketFeed(exchange: string): HyperliquidMarketFeed | LighterMarketFeed;
|