@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,255 @@
|
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useMemo, useState } from "react";
|
|
3
|
+
import { Box, Text, render, useApp, useInput } from "ink";
|
|
4
|
+
import { getContext, getOutputOptions, getSelectedExchange } from "../../cli/program.js";
|
|
5
|
+
import { output, outputError } from "../../cli/output.js";
|
|
6
|
+
import { AppShell, MetricStrip, Panel, Table, colors, toBar, } from "../../cli/ink/index.js";
|
|
7
|
+
import { getExchangeAdapter } from "../../lib/exchange.js";
|
|
8
|
+
import { getExchangeCredentials } from "../../lib/config.js";
|
|
9
|
+
import { parsePositiveInt } from "../../lib/validate.js";
|
|
10
|
+
import { withJsonContract } from "../../lib/contracts.js";
|
|
11
|
+
const DEFAULT_INTERVAL_MS = 1_500;
|
|
12
|
+
const MIN_INTERVAL_MS = 200;
|
|
13
|
+
const ROW_LIMIT = 12;
|
|
14
|
+
function toFiniteNumber(input) {
|
|
15
|
+
const parsed = Number.parseFloat(input);
|
|
16
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
17
|
+
}
|
|
18
|
+
function formatCurrency(value, decimals = 2) {
|
|
19
|
+
return value.toLocaleString("en-US", {
|
|
20
|
+
minimumFractionDigits: decimals,
|
|
21
|
+
maximumFractionDigits: decimals,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
function rowSignal(changePct, fundingPct) {
|
|
25
|
+
if (changePct > 1 && fundingPct < 0.025)
|
|
26
|
+
return "LONG";
|
|
27
|
+
if (changePct < -1 && fundingPct > -0.025)
|
|
28
|
+
return "SHORT";
|
|
29
|
+
return "FLAT";
|
|
30
|
+
}
|
|
31
|
+
function signalColor(signal) {
|
|
32
|
+
if (signal === "LONG")
|
|
33
|
+
return colors.profit;
|
|
34
|
+
if (signal === "SHORT")
|
|
35
|
+
return colors.loss;
|
|
36
|
+
return colors.muted;
|
|
37
|
+
}
|
|
38
|
+
function parseTickerRow(ticker) {
|
|
39
|
+
const price = toFiniteNumber(ticker.markPrice) ?? toFiniteNumber(ticker.lastPrice);
|
|
40
|
+
if (!price || price <= 0) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const changePct = toFiniteNumber(ticker.change24h) ?? 0;
|
|
44
|
+
const fundingRate = toFiniteNumber(ticker.fundingRate) ?? 0;
|
|
45
|
+
const volume24h = toFiniteNumber(ticker.volume24h) ?? 0;
|
|
46
|
+
const bid = toFiniteNumber(ticker.bid);
|
|
47
|
+
const ask = toFiniteNumber(ticker.ask);
|
|
48
|
+
const spreadBps = bid && ask && bid > 0 && ask > 0 ? ((ask - bid) / ((ask + bid) / 2)) * 10_000 : null;
|
|
49
|
+
const fundingPct = fundingRate * 100;
|
|
50
|
+
return {
|
|
51
|
+
market: ticker.market,
|
|
52
|
+
price,
|
|
53
|
+
changePct,
|
|
54
|
+
fundingPct,
|
|
55
|
+
volumeM: volume24h / 1_000_000,
|
|
56
|
+
spreadBps,
|
|
57
|
+
signal: rowSignal(changePct, fundingPct),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function sortRows(rows) {
|
|
61
|
+
return rows
|
|
62
|
+
.sort((left, right) => right.volumeM - left.volumeM)
|
|
63
|
+
.slice(0, ROW_LIMIT);
|
|
64
|
+
}
|
|
65
|
+
function TerminalDashboard({ intervalMs, exchangeId, networkLabel, pollSnapshot, }) {
|
|
66
|
+
const [state, setState] = useState({
|
|
67
|
+
startedAt: Date.now(),
|
|
68
|
+
rows: [],
|
|
69
|
+
latencyMs: 0,
|
|
70
|
+
lastUpdated: null,
|
|
71
|
+
polls: 0,
|
|
72
|
+
lastError: null,
|
|
73
|
+
});
|
|
74
|
+
const { exit } = useApp();
|
|
75
|
+
useInput((input, key) => {
|
|
76
|
+
if (input.toLowerCase() === "q" || key.escape || (key.ctrl && input.toLowerCase() === "c")) {
|
|
77
|
+
exit();
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
let cancelled = false;
|
|
82
|
+
const poll = async () => {
|
|
83
|
+
try {
|
|
84
|
+
const snapshot = await pollSnapshot();
|
|
85
|
+
if (cancelled)
|
|
86
|
+
return;
|
|
87
|
+
setState((previous) => ({
|
|
88
|
+
...previous,
|
|
89
|
+
rows: snapshot.rows,
|
|
90
|
+
latencyMs: snapshot.latencyMs,
|
|
91
|
+
lastUpdated: snapshot.updatedAt,
|
|
92
|
+
polls: previous.polls + 1,
|
|
93
|
+
lastError: null,
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
catch (err) {
|
|
97
|
+
if (cancelled)
|
|
98
|
+
return;
|
|
99
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
100
|
+
setState((previous) => ({
|
|
101
|
+
...previous,
|
|
102
|
+
polls: previous.polls + 1,
|
|
103
|
+
lastError: message,
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
void poll();
|
|
108
|
+
const timer = setInterval(() => {
|
|
109
|
+
void poll();
|
|
110
|
+
}, intervalMs);
|
|
111
|
+
return () => {
|
|
112
|
+
cancelled = true;
|
|
113
|
+
clearInterval(timer);
|
|
114
|
+
};
|
|
115
|
+
}, [intervalMs, pollSnapshot]);
|
|
116
|
+
const uptimeSec = Math.floor((Date.now() - state.startedAt) / 1_000);
|
|
117
|
+
const activeSignals = state.rows.filter((row) => row.signal !== "FLAT").length;
|
|
118
|
+
const metrics = [
|
|
119
|
+
{ label: "Exchange", value: exchangeId, tone: "neutral" },
|
|
120
|
+
{ label: "Network", value: networkLabel, tone: networkLabel === "testnet" ? "warning" : "info" },
|
|
121
|
+
{ label: "Markets", value: String(state.rows.length), tone: "neutral" },
|
|
122
|
+
{ label: "Signals", value: String(activeSignals), tone: activeSignals > 0 ? "info" : "neutral" },
|
|
123
|
+
{
|
|
124
|
+
label: "Latency",
|
|
125
|
+
value: state.latencyMs > 0 ? `${state.latencyMs}ms` : "--",
|
|
126
|
+
tone: state.latencyMs > 1_800 ? "danger" : state.latencyMs > 900 ? "warning" : "success",
|
|
127
|
+
},
|
|
128
|
+
{ label: "Uptime", value: `${uptimeSec}s`, tone: "neutral" },
|
|
129
|
+
];
|
|
130
|
+
const columns = useMemo(() => [
|
|
131
|
+
{ key: "market", header: "Market" },
|
|
132
|
+
{
|
|
133
|
+
key: "price",
|
|
134
|
+
header: "Price",
|
|
135
|
+
align: "right",
|
|
136
|
+
render: (value) => _jsxs(Text, { children: ["$", formatCurrency(value)] }),
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
key: "changePct",
|
|
140
|
+
header: "24h %",
|
|
141
|
+
align: "right",
|
|
142
|
+
render: (value) => {
|
|
143
|
+
const change = value;
|
|
144
|
+
const sign = change >= 0 ? "+" : "";
|
|
145
|
+
return (_jsxs(Text, { color: change >= 0 ? colors.profit : colors.loss, children: [sign, change.toFixed(2), "%"] }));
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
key: "fundingPct",
|
|
150
|
+
header: "Funding",
|
|
151
|
+
align: "right",
|
|
152
|
+
render: (value) => {
|
|
153
|
+
const funding = value;
|
|
154
|
+
const sign = funding >= 0 ? "+" : "";
|
|
155
|
+
return (_jsxs(Text, { color: funding >= 0 ? colors.profit : colors.loss, children: [sign, funding.toFixed(4), "%"] }));
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
key: "volumeM",
|
|
160
|
+
header: "Vol(M)",
|
|
161
|
+
align: "right",
|
|
162
|
+
render: (value) => _jsx(Text, { children: formatCurrency(value, 1) }),
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
key: "spreadBps",
|
|
166
|
+
header: "Spread(bps)",
|
|
167
|
+
align: "right",
|
|
168
|
+
render: (value) => {
|
|
169
|
+
const spread = value;
|
|
170
|
+
if (spread === null) {
|
|
171
|
+
return _jsx(Text, { color: colors.muted, children: "--" });
|
|
172
|
+
}
|
|
173
|
+
return _jsx(Text, { children: spread.toFixed(2) });
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
key: "signal",
|
|
178
|
+
header: "Signal",
|
|
179
|
+
align: "right",
|
|
180
|
+
render: (value) => {
|
|
181
|
+
const signal = value;
|
|
182
|
+
return _jsx(Text, { color: signalColor(signal), children: signal });
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
], []);
|
|
186
|
+
const movers = useMemo(() => [...state.rows]
|
|
187
|
+
.sort((left, right) => Math.abs(right.changePct) - Math.abs(left.changePct))
|
|
188
|
+
.slice(0, 3), [state.rows]);
|
|
189
|
+
const maxMove = Math.max(1, ...movers.map((row) => Math.abs(row.changePct)));
|
|
190
|
+
return (_jsxs(AppShell, { title: "Perps Terminal", subtitle: "Live market tape and signal monitor", status: [
|
|
191
|
+
{ label: "LIVE", tone: "success" },
|
|
192
|
+
{ label: `POLL ${state.polls}`, tone: "neutral" },
|
|
193
|
+
], lastUpdated: state.lastUpdated ?? undefined, shortcuts: [
|
|
194
|
+
{ key: "q", label: "quit" },
|
|
195
|
+
{ key: "esc", label: "quit" },
|
|
196
|
+
], children: [_jsx(MetricStrip, { metrics: metrics }), _jsx(Box, { flexDirection: "column", marginBottom: 1, children: _jsx(Panel, { title: "Momentum", subtitle: "Top absolute movers from live tape", tone: "info", children: movers.length === 0 ? (_jsx(Text, { color: colors.muted, children: "Waiting for market snapshot..." })) : (movers.map((row) => (_jsxs(Box, { children: [_jsx(Text, { color: colors.muted, children: row.market.padEnd(10) }), _jsx(Text, { children: " " }), _jsx(Text, { children: toBar(Math.abs(row.changePct), maxMove, 18, row.changePct >= 0 ? "+" : "-", ".") }), _jsxs(Text, { color: row.changePct >= 0 ? colors.profit : colors.loss, children: [" ", row.changePct >= 0 ? "+" : "", row.changePct.toFixed(2), "%"] })] }, row.market)))) }) }), _jsx(Panel, { title: "Market Tape", subtitle: "Top markets by 24h volume", children: state.rows.length === 0 ? (_jsx(Text, { color: colors.muted, children: "Waiting for market snapshot..." })) : (_jsx(Table, { data: state.rows, columns: columns })) }), state.lastError && (_jsx(Box, { marginTop: 1, children: _jsx(Panel, { title: "Last Error", tone: "danger", children: _jsx(Text, { color: colors.loss, children: state.lastError }) }) }))] }));
|
|
197
|
+
}
|
|
198
|
+
export function registerUITerminalCommand(ui) {
|
|
199
|
+
ui
|
|
200
|
+
.command("terminal")
|
|
201
|
+
.alias("live")
|
|
202
|
+
.description("Run a live terminal dashboard (market data by default)")
|
|
203
|
+
.option("-i, --interval <ms>", "Refresh interval in milliseconds", String(DEFAULT_INTERVAL_MS))
|
|
204
|
+
.action(async function (options) {
|
|
205
|
+
const ctx = getContext(this);
|
|
206
|
+
const outputOpts = getOutputOptions(this);
|
|
207
|
+
const exchangeId = getSelectedExchange(this);
|
|
208
|
+
try {
|
|
209
|
+
const intervalMs = parsePositiveInt(options.interval, "interval", DEFAULT_INTERVAL_MS);
|
|
210
|
+
if (intervalMs < MIN_INTERVAL_MS) {
|
|
211
|
+
throw new Error(`interval must be >= ${MIN_INTERVAL_MS}ms`);
|
|
212
|
+
}
|
|
213
|
+
if (outputOpts.json) {
|
|
214
|
+
output(withJsonContract("ui.terminal.preview", {
|
|
215
|
+
command: "ui terminal",
|
|
216
|
+
exchange: exchangeId,
|
|
217
|
+
network: ctx.config.testnet ? "testnet" : "mainnet",
|
|
218
|
+
intervalMs,
|
|
219
|
+
interactive: false,
|
|
220
|
+
}), outputOpts);
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
const adapter = getExchangeAdapter();
|
|
224
|
+
const credentials = getExchangeCredentials(ctx.config, exchangeId);
|
|
225
|
+
await adapter.connect({
|
|
226
|
+
testnet: ctx.config.testnet,
|
|
227
|
+
rpcUrl: credentials.fullnodeUrl,
|
|
228
|
+
wsUrl: credentials.wsUrl,
|
|
229
|
+
credentials,
|
|
230
|
+
});
|
|
231
|
+
const pollSnapshot = async () => {
|
|
232
|
+
const startedAt = Date.now();
|
|
233
|
+
const tickers = await adapter.getTickers();
|
|
234
|
+
const rows = sortRows(tickers.map(parseTickerRow).filter((row) => !!row));
|
|
235
|
+
return {
|
|
236
|
+
rows,
|
|
237
|
+
latencyMs: Date.now() - startedAt,
|
|
238
|
+
updatedAt: new Date(),
|
|
239
|
+
};
|
|
240
|
+
};
|
|
241
|
+
try {
|
|
242
|
+
const { waitUntilExit, unmount } = render(_jsx(TerminalDashboard, { intervalMs: intervalMs, exchangeId: exchangeId, networkLabel: ctx.config.testnet ? "testnet" : "mainnet", pollSnapshot: pollSnapshot }));
|
|
243
|
+
await waitUntilExit();
|
|
244
|
+
unmount();
|
|
245
|
+
}
|
|
246
|
+
finally {
|
|
247
|
+
await adapter.disconnect();
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
catch (err) {
|
|
251
|
+
outputError(err instanceof Error ? err.message : String(err));
|
|
252
|
+
process.exit(1);
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { createRequire } from "module";
|
|
2
|
+
import { getOutputOptions } from "../cli/program.js";
|
|
3
|
+
import { output, outputSuccess } from "../cli/output.js";
|
|
4
|
+
const require = createRequire(import.meta.url);
|
|
5
|
+
const pkg = require("../../package.json");
|
|
6
|
+
async function fetchLatestVersion(packageName) {
|
|
7
|
+
const response = await fetch(`https://registry.npmjs.org/${encodeURIComponent(packageName)}`);
|
|
8
|
+
if (response.status === 404) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
if (!response.ok) {
|
|
12
|
+
throw new Error(`Failed to fetch package info: ${response.statusText}`);
|
|
13
|
+
}
|
|
14
|
+
const data = (await response.json());
|
|
15
|
+
return data["dist-tags"]?.latest ?? null;
|
|
16
|
+
}
|
|
17
|
+
function compareVersions(current, latest) {
|
|
18
|
+
const currentParts = current.split(".").map(Number);
|
|
19
|
+
const latestParts = latest.split(".").map(Number);
|
|
20
|
+
for (let i = 0; i < Math.max(currentParts.length, latestParts.length); i++) {
|
|
21
|
+
const currentPart = currentParts[i] ?? 0;
|
|
22
|
+
const latestPart = latestParts[i] ?? 0;
|
|
23
|
+
if (latestPart > currentPart)
|
|
24
|
+
return true;
|
|
25
|
+
if (latestPart < currentPart)
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
export function registerUpgradeCommand(program) {
|
|
31
|
+
program
|
|
32
|
+
.command("upgrade")
|
|
33
|
+
.description("Check for updates and show upgrade instructions")
|
|
34
|
+
.action(async function () {
|
|
35
|
+
const outputOpts = getOutputOptions(this);
|
|
36
|
+
const current = pkg.version;
|
|
37
|
+
const packageName = pkg.name;
|
|
38
|
+
let latest;
|
|
39
|
+
try {
|
|
40
|
+
latest = await fetchLatestVersion(packageName);
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
if (outputOpts.json) {
|
|
44
|
+
output({ error: err instanceof Error ? err.message : String(err) }, outputOpts);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
console.error("Failed to check for updates:", err instanceof Error ? err.message : String(err));
|
|
48
|
+
}
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
if (!latest) {
|
|
52
|
+
const unpublishedResult = {
|
|
53
|
+
current,
|
|
54
|
+
latest: null,
|
|
55
|
+
updateAvailable: false,
|
|
56
|
+
packagePublished: false,
|
|
57
|
+
packageName,
|
|
58
|
+
};
|
|
59
|
+
if (outputOpts.json) {
|
|
60
|
+
output(unpublishedResult, outputOpts);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
console.log(`Current version: ${current}`);
|
|
64
|
+
outputSuccess(`Package "${packageName}" is not published to npm yet.`);
|
|
65
|
+
console.log("");
|
|
66
|
+
console.log("To publish the first release, run:");
|
|
67
|
+
console.log(` npm publish --access public`);
|
|
68
|
+
}
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const updateAvailable = compareVersions(current, latest);
|
|
72
|
+
const result = {
|
|
73
|
+
current,
|
|
74
|
+
latest,
|
|
75
|
+
updateAvailable,
|
|
76
|
+
packagePublished: true,
|
|
77
|
+
packageName,
|
|
78
|
+
};
|
|
79
|
+
if (outputOpts.json) {
|
|
80
|
+
output(result, outputOpts);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
console.log(`Current version: ${current}`);
|
|
84
|
+
console.log(`Latest version: ${latest}`);
|
|
85
|
+
if (updateAvailable) {
|
|
86
|
+
console.log(``);
|
|
87
|
+
outputSuccess("Update available!");
|
|
88
|
+
console.log(``);
|
|
89
|
+
console.log(`To upgrade, run:`);
|
|
90
|
+
console.log(` npm install -g ${packageName}@latest`);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
console.log(``);
|
|
94
|
+
outputSuccess("You are running the latest version.");
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface AgentAuditEvent {
|
|
2
|
+
action: string;
|
|
3
|
+
status: "ok" | "error";
|
|
4
|
+
exchange?: string;
|
|
5
|
+
market?: string;
|
|
6
|
+
idempotencyKey?: string;
|
|
7
|
+
paymentId?: string;
|
|
8
|
+
requestHash?: string;
|
|
9
|
+
traceId?: string;
|
|
10
|
+
details?: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
export declare function appendAgentAuditEvent(event: AgentAuditEvent): void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { appendFileSync } from "node:fs";
|
|
2
|
+
import { dirname } from "node:path";
|
|
3
|
+
import { AGENT_AUDIT_LOG_PATH } from "../paths.js";
|
|
4
|
+
import { ensurePrivateDir, hardenPrivateFile, PRIVATE_FILE_MODE } from "../fs-security.js";
|
|
5
|
+
export function appendAgentAuditEvent(event) {
|
|
6
|
+
ensurePrivateDir(dirname(AGENT_AUDIT_LOG_PATH));
|
|
7
|
+
const line = JSON.stringify({
|
|
8
|
+
timestamp: Date.now(),
|
|
9
|
+
...event,
|
|
10
|
+
});
|
|
11
|
+
appendFileSync(AGENT_AUDIT_LOG_PATH, `${line}\n`, { encoding: "utf8", mode: PRIVATE_FILE_MODE });
|
|
12
|
+
hardenPrivateFile(AGENT_AUDIT_LOG_PATH);
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Server } from "node:http";
|
|
2
|
+
export interface AgentGatewayOptions {
|
|
3
|
+
host: string;
|
|
4
|
+
port: number;
|
|
5
|
+
defaultExchange: string;
|
|
6
|
+
defaultTestnet: boolean;
|
|
7
|
+
allowMainnetExecution: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function createAgentGateway(options: AgentGatewayOptions): {
|
|
10
|
+
server: Server;
|
|
11
|
+
start: () => Promise<void>;
|
|
12
|
+
stop: () => Promise<void>;
|
|
13
|
+
};
|