@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,166 @@
|
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
import WebSocket from "ws";
|
|
3
|
+
import { createLogger } from "../../lib/logger.js";
|
|
4
|
+
import { isRecord } from "../utils.js";
|
|
5
|
+
const log = createLogger("decibel:ws");
|
|
6
|
+
export class DecibelWsFeed extends EventEmitter {
|
|
7
|
+
ws = null;
|
|
8
|
+
wsUrl;
|
|
9
|
+
bearerToken;
|
|
10
|
+
subscriptions = new Set();
|
|
11
|
+
reconnectDelay;
|
|
12
|
+
pingInterval;
|
|
13
|
+
pingTimer = null;
|
|
14
|
+
reconnectTimer = null;
|
|
15
|
+
shouldReconnect = true;
|
|
16
|
+
constructor(wsUrl, bearerToken, opts = {}) {
|
|
17
|
+
super();
|
|
18
|
+
this.wsUrl = wsUrl;
|
|
19
|
+
this.bearerToken = bearerToken;
|
|
20
|
+
this.reconnectDelay = opts.reconnectDelayMs ?? 3_000;
|
|
21
|
+
this.pingInterval = opts.pingIntervalMs ?? 25_000;
|
|
22
|
+
}
|
|
23
|
+
connect() {
|
|
24
|
+
this.shouldReconnect = true;
|
|
25
|
+
this.clearReconnectTimer();
|
|
26
|
+
this.doConnect();
|
|
27
|
+
}
|
|
28
|
+
subscribe(topic) {
|
|
29
|
+
this.subscriptions.add(topic);
|
|
30
|
+
if (this.ws?.readyState === WebSocket.OPEN) {
|
|
31
|
+
this.sendSubscribe(topic);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
unsubscribe(topic) {
|
|
35
|
+
this.subscriptions.delete(topic);
|
|
36
|
+
if (this.ws?.readyState === WebSocket.OPEN) {
|
|
37
|
+
this.ws.send(JSON.stringify({ method: "unsubscribe", topic }));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
close() {
|
|
41
|
+
this.shouldReconnect = false;
|
|
42
|
+
this.clearReconnectTimer();
|
|
43
|
+
this.stopPing();
|
|
44
|
+
this.ws?.removeAllListeners();
|
|
45
|
+
this.ws?.close();
|
|
46
|
+
this.ws = null;
|
|
47
|
+
}
|
|
48
|
+
isConnected() {
|
|
49
|
+
return this.ws?.readyState === WebSocket.OPEN;
|
|
50
|
+
}
|
|
51
|
+
doConnect() {
|
|
52
|
+
if (!this.shouldReconnect) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
log.info(`WebSocket connecting: ${this.wsUrl}`);
|
|
56
|
+
const options = this.bearerToken
|
|
57
|
+
? { headers: { "Sec-WebSocket-Protocol": `decibel, ${this.bearerToken}` } }
|
|
58
|
+
: undefined;
|
|
59
|
+
this.ws = options ? new WebSocket(this.wsUrl, options) : new WebSocket(this.wsUrl);
|
|
60
|
+
this.ws.on("open", () => {
|
|
61
|
+
log.info("WebSocket connected");
|
|
62
|
+
this.startPing();
|
|
63
|
+
for (const topic of this.subscriptions) {
|
|
64
|
+
this.sendSubscribe(topic);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
this.ws.on("message", (data) => {
|
|
68
|
+
try {
|
|
69
|
+
const msg = JSON.parse(data.toString());
|
|
70
|
+
this.handleMessage(msg);
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
log.warn("WebSocket parse error");
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
this.ws.on("close", (code, reason) => {
|
|
77
|
+
log.warn(`WebSocket closed (${code}): ${reason.toString()}`);
|
|
78
|
+
this.stopPing();
|
|
79
|
+
if (this.shouldReconnect) {
|
|
80
|
+
this.clearReconnectTimer();
|
|
81
|
+
this.reconnectTimer = setTimeout(() => {
|
|
82
|
+
this.reconnectTimer = null;
|
|
83
|
+
this.doConnect();
|
|
84
|
+
}, this.reconnectDelay);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
this.ws.on("error", (err) => {
|
|
88
|
+
log.error("WebSocket error", err);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
sendSubscribe(topic) {
|
|
92
|
+
this.ws?.send(JSON.stringify({ method: "subscribe", topic }));
|
|
93
|
+
}
|
|
94
|
+
startPing() {
|
|
95
|
+
this.stopPing();
|
|
96
|
+
this.pingTimer = setInterval(() => {
|
|
97
|
+
if (this.ws?.readyState === WebSocket.OPEN) {
|
|
98
|
+
this.ws.ping();
|
|
99
|
+
}
|
|
100
|
+
}, this.pingInterval);
|
|
101
|
+
}
|
|
102
|
+
stopPing() {
|
|
103
|
+
if (this.pingTimer) {
|
|
104
|
+
clearInterval(this.pingTimer);
|
|
105
|
+
this.pingTimer = null;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
clearReconnectTimer() {
|
|
109
|
+
if (this.reconnectTimer) {
|
|
110
|
+
clearTimeout(this.reconnectTimer);
|
|
111
|
+
this.reconnectTimer = null;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
handleMessage(msg) {
|
|
115
|
+
const payload = isRecord(msg) ? msg : {};
|
|
116
|
+
const topicSource = payload.topic ?? payload.channel;
|
|
117
|
+
const topic = typeof topicSource === "string" ? topicSource : "";
|
|
118
|
+
if (topic.startsWith("depth:")) {
|
|
119
|
+
this.emit("depth", { marketAddr: topic.split(":")[1], data: payload });
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (topic.startsWith("market_price:")) {
|
|
123
|
+
const pricePayload = isRecord(payload.price) ? payload.price : payload;
|
|
124
|
+
this.emit("price", { marketAddr: topic.split(":")[1], data: pricePayload });
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (topic === "all_market_prices") {
|
|
128
|
+
this.emit("all_market_prices", { data: payload });
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (topic.startsWith("trades:")) {
|
|
132
|
+
this.emit("trades", { marketAddr: topic.split(":")[1], data: payload });
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (topic.startsWith("market_candlestick:")) {
|
|
136
|
+
const parts = topic.split(":");
|
|
137
|
+
this.emit("candlestick", { marketAddr: parts[1], interval: parts[2], data: payload });
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (topic.startsWith("account_overview:")) {
|
|
141
|
+
this.emit("account_overview", { accountAddr: topic.split(":")[1], data: payload });
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if (topic.startsWith("account_positions:")) {
|
|
145
|
+
this.emit("account_positions", { accountAddr: topic.split(":")[1], data: payload });
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
if (topic.startsWith("account_open_orders:")) {
|
|
149
|
+
this.emit("account_open_orders", { accountAddr: topic.split(":")[1], data: payload });
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (topic.startsWith("order_updates:")) {
|
|
153
|
+
this.emit("order_updates", { accountAddr: topic.split(":")[1], data: payload });
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (topic.startsWith("user_trades:")) {
|
|
157
|
+
this.emit("user_trades", { accountAddr: topic.split(":")[1], data: payload });
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (topic.startsWith("notifications:")) {
|
|
161
|
+
this.emit("notifications", { accountAddr: topic.split(":")[1], data: payload });
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
this.emit("raw", payload);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decibel Adapter
|
|
3
|
+
* Implements PerpDEXAdapter interface for Decibel (Aptos)
|
|
4
|
+
*/
|
|
5
|
+
import { type Balance, type CancelOrderParams, type ExchangeConfig, type ExchangeInfo, type FundingPayment, type FundingRate, type MarginType, type Market, type ModifyOrderParams, type Order, type OrderBook, type OrderParams, type PerpDEXAdapter, type Position, type PublicTrade, type SubscriptionCallbacks, type Ticker, type Trade, type Unsubscribe, type MMPConfig, type MMPStatus, type TWAPParams, type TWAPStatus } from "./interface.js";
|
|
6
|
+
export declare class DecibelAdapter implements PerpDEXAdapter {
|
|
7
|
+
readonly info: ExchangeInfo;
|
|
8
|
+
private config;
|
|
9
|
+
private connected;
|
|
10
|
+
private restClient;
|
|
11
|
+
private wsFeed;
|
|
12
|
+
private orderManager;
|
|
13
|
+
private accountAddress;
|
|
14
|
+
private subaccountAddress;
|
|
15
|
+
private readonly marketsBySymbol;
|
|
16
|
+
private readonly marketsByAddr;
|
|
17
|
+
private readonly pricesByMarketAddr;
|
|
18
|
+
private readonly booksByMarketAddr;
|
|
19
|
+
private readonly assetContextsByMarketAddr;
|
|
20
|
+
private assetContextsTimestamp;
|
|
21
|
+
private readonly trackedMarketAddrs;
|
|
22
|
+
private readonly tickerSubscribers;
|
|
23
|
+
private readonly orderBookSubscribers;
|
|
24
|
+
private readonly globalSubscribers;
|
|
25
|
+
private readonly accountPollers;
|
|
26
|
+
private backfillTimer;
|
|
27
|
+
connect(config: ExchangeConfig): Promise<void>;
|
|
28
|
+
disconnect(): Promise<void>;
|
|
29
|
+
isConnected(): boolean;
|
|
30
|
+
getMarkets(): Promise<Market[]>;
|
|
31
|
+
getMarket(symbol: string): Promise<Market | null>;
|
|
32
|
+
getTicker(market: string): Promise<Ticker>;
|
|
33
|
+
getTickers(): Promise<Ticker[]>;
|
|
34
|
+
getOrderBook(market: string, depth?: number): Promise<OrderBook>;
|
|
35
|
+
getFundingRate(market: string): Promise<FundingRate>;
|
|
36
|
+
getFundingRates(): Promise<FundingRate[]>;
|
|
37
|
+
getPositions(): Promise<Position[]>;
|
|
38
|
+
getPosition(market: string): Promise<Position | null>;
|
|
39
|
+
getOrders(market?: string): Promise<Order[]>;
|
|
40
|
+
getOrder(orderId: string): Promise<Order | null>;
|
|
41
|
+
getBalances(): Promise<Balance[]>;
|
|
42
|
+
getTrades(market?: string, limit?: number): Promise<Trade[]>;
|
|
43
|
+
placeOrder(params: OrderParams): Promise<Order>;
|
|
44
|
+
cancelOrder(params: CancelOrderParams): Promise<boolean>;
|
|
45
|
+
cancelAllOrders(market?: string): Promise<number>;
|
|
46
|
+
setLeverage(market: string, leverage: number): Promise<void>;
|
|
47
|
+
setMarginType(market: string, type: MarginType): Promise<void>;
|
|
48
|
+
modifyOrder(_params: ModifyOrderParams): Promise<Order>;
|
|
49
|
+
batchPlaceOrders(paramsList: OrderParams[]): Promise<Order[]>;
|
|
50
|
+
batchCancelOrders(paramsList: CancelOrderParams[]): Promise<boolean[]>;
|
|
51
|
+
cancelAllAfter(_timeoutMs: number): Promise<void>;
|
|
52
|
+
getOrderHistory(market?: string, limit?: number): Promise<Order[]>;
|
|
53
|
+
getFundingHistory(_market?: string, _limit?: number): Promise<FundingPayment[]>;
|
|
54
|
+
getPublicTrades(market: string, limit?: number): Promise<PublicTrade[]>;
|
|
55
|
+
setMMP(_config: MMPConfig): Promise<void>;
|
|
56
|
+
getMMP(_market: string): Promise<MMPStatus>;
|
|
57
|
+
resetMMP(_market: string): Promise<void>;
|
|
58
|
+
placeTWAP(_params: TWAPParams): Promise<TWAPStatus>;
|
|
59
|
+
cancelTWAP(_twapId: string): Promise<boolean>;
|
|
60
|
+
getTWAPStatus(_twapId: string): Promise<TWAPStatus | null>;
|
|
61
|
+
updateIsolatedMargin(_market: string, _amount: string): Promise<void>;
|
|
62
|
+
subscribe(callbacks: SubscriptionCallbacks): Unsubscribe;
|
|
63
|
+
subscribeOrderBook(market: string, callback: (book: OrderBook) => void): Unsubscribe;
|
|
64
|
+
subscribeTicker(market: string, callback: (ticker: Ticker) => void): Unsubscribe;
|
|
65
|
+
private loadAssetContexts;
|
|
66
|
+
private isAssetContextsStale;
|
|
67
|
+
private handleWsAllMarketPrices;
|
|
68
|
+
private handleWsAccountOverview;
|
|
69
|
+
private handleWsAccountPositions;
|
|
70
|
+
private handleWsAccountOpenOrders;
|
|
71
|
+
private handleWsUserTrades;
|
|
72
|
+
private handleWsOrderUpdate;
|
|
73
|
+
private handleWsNotification;
|
|
74
|
+
private resolveNetwork;
|
|
75
|
+
private loadMarkets;
|
|
76
|
+
private mapMarket;
|
|
77
|
+
private ensureConnected;
|
|
78
|
+
private ensureAccountReadAuth;
|
|
79
|
+
private ensureOrderManager;
|
|
80
|
+
private requireMarket;
|
|
81
|
+
private normalizeSymbol;
|
|
82
|
+
private toTicker;
|
|
83
|
+
private toPosition;
|
|
84
|
+
private toOrder;
|
|
85
|
+
private toTrade;
|
|
86
|
+
private resolveMarketSymbol;
|
|
87
|
+
private mapOrderStatus;
|
|
88
|
+
private mapOrderType;
|
|
89
|
+
private matchesOrderId;
|
|
90
|
+
private getCurrentMarginSettings;
|
|
91
|
+
private normalizeDepth;
|
|
92
|
+
private toOrderBook;
|
|
93
|
+
private trackMarket;
|
|
94
|
+
private handleWsPrice;
|
|
95
|
+
private handleWsDepth;
|
|
96
|
+
private handleWsTrades;
|
|
97
|
+
private startBackfillLoop;
|
|
98
|
+
private startAccountPollingIfNeeded;
|
|
99
|
+
private stopAccountPolling;
|
|
100
|
+
private stopAllAccountPollers;
|
|
101
|
+
private pollAccountCallbacks;
|
|
102
|
+
private stopBackfillLoop;
|
|
103
|
+
private backfillTrackedMarkets;
|
|
104
|
+
private isBookStale;
|
|
105
|
+
private isPriceStale;
|
|
106
|
+
private resolveReferenceExecutionPrice;
|
|
107
|
+
}
|
|
108
|
+
export default DecibelAdapter;
|