@pod-network/trade-sdk 0.1.0-rc.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 +113 -0
- package/dist/client.d.ts +93 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +168 -0
- package/dist/client.js.map +1 -0
- package/dist/codec/decode.d.ts +22 -0
- package/dist/codec/decode.d.ts.map +1 -0
- package/dist/codec/decode.js +251 -0
- package/dist/codec/decode.js.map +1 -0
- package/dist/codec/fixed.d.ts +11 -0
- package/dist/codec/fixed.d.ts.map +1 -0
- package/dist/codec/fixed.js +37 -0
- package/dist/codec/fixed.js.map +1 -0
- package/dist/codec/resolution.d.ts +14 -0
- package/dist/codec/resolution.d.ts.map +1 -0
- package/dist/codec/resolution.js +35 -0
- package/dist/codec/resolution.js.map +1 -0
- package/dist/codec/units.d.ts +35 -0
- package/dist/codec/units.d.ts.map +1 -0
- package/dist/codec/units.js +86 -0
- package/dist/codec/units.js.map +1 -0
- package/dist/datafeed.d.ts +4 -0
- package/dist/datafeed.d.ts.map +1 -0
- package/dist/datafeed.js +73 -0
- package/dist/datafeed.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/stores/resource.d.ts +50 -0
- package/dist/stores/resource.d.ts.map +1 -0
- package/dist/stores/resource.js +154 -0
- package/dist/stores/resource.js.map +1 -0
- package/dist/sync/account-metrics.d.ts +26 -0
- package/dist/sync/account-metrics.d.ts.map +1 -0
- package/dist/sync/account-metrics.js +41 -0
- package/dist/sync/account-metrics.js.map +1 -0
- package/dist/sync/candles.d.ts +68 -0
- package/dist/sync/candles.d.ts.map +1 -0
- package/dist/sync/candles.js +318 -0
- package/dist/sync/candles.js.map +1 -0
- package/dist/sync/order-preview.d.ts +74 -0
- package/dist/sync/order-preview.d.ts.map +1 -0
- package/dist/sync/order-preview.js +86 -0
- package/dist/sync/order-preview.js.map +1 -0
- package/dist/sync/orders.d.ts +49 -0
- package/dist/sync/orders.d.ts.map +1 -0
- package/dist/sync/orders.js +210 -0
- package/dist/sync/orders.js.map +1 -0
- package/dist/sync/positions-live.d.ts +3 -0
- package/dist/sync/positions-live.d.ts.map +1 -0
- package/dist/sync/positions-live.js +86 -0
- package/dist/sync/positions-live.js.map +1 -0
- package/dist/sync/sources.d.ts +40 -0
- package/dist/sync/sources.d.ts.map +1 -0
- package/dist/sync/sources.js +197 -0
- package/dist/sync/sources.js.map +1 -0
- package/dist/transport/rest.d.ts +83 -0
- package/dist/transport/rest.d.ts.map +1 -0
- package/dist/transport/rest.js +146 -0
- package/dist/transport/rest.js.map +1 -0
- package/dist/transport/ws.d.ts +60 -0
- package/dist/transport/ws.d.ts.map +1 -0
- package/dist/transport/ws.js +235 -0
- package/dist/transport/ws.js.map +1 -0
- package/dist/types/public.d.ts +292 -0
- package/dist/types/public.d.ts.map +1 -0
- package/dist/types/public.js +4 -0
- package/dist/types/public.js.map +1 -0
- package/dist/types/wire.d.ts +283 -0
- package/dist/types/wire.d.ts.map +1 -0
- package/dist/types/wire.js +6 -0
- package/dist/types/wire.js.map +1 -0
- package/dist/write/delegation.d.ts +54 -0
- package/dist/write/delegation.d.ts.map +1 -0
- package/dist/write/delegation.js +81 -0
- package/dist/write/delegation.js.map +1 -0
- package/dist/write/index.d.ts +261 -0
- package/dist/write/index.d.ts.map +1 -0
- package/dist/write/index.js +428 -0
- package/dist/write/index.js.map +1 -0
- package/package.json +43 -0
- package/src/client.ts +229 -0
- package/src/codec/decode.ts +277 -0
- package/src/codec/fixed.ts +41 -0
- package/src/codec/resolution.ts +39 -0
- package/src/codec/units.ts +100 -0
- package/src/datafeed.ts +94 -0
- package/src/index.ts +49 -0
- package/src/stores/resource.ts +172 -0
- package/src/sync/account-metrics.ts +71 -0
- package/src/sync/candles.ts +326 -0
- package/src/sync/order-preview.ts +152 -0
- package/src/sync/orders.ts +205 -0
- package/src/sync/positions-live.ts +102 -0
- package/src/sync/sources.ts +239 -0
- package/src/transport/rest.ts +213 -0
- package/src/transport/ws.ts +255 -0
- package/src/types/public.ts +335 -0
- package/src/types/wire.ts +301 -0
- package/src/write/delegation.ts +113 -0
- package/src/write/index.ts +642 -0
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
// Layer 1: one multiplexed WebSocket over the JSON-RPC `eth_subscribe` /
|
|
2
|
+
// `eth_subscription` / `eth_unsubscribe` protocol with `pod_*` sub-types.
|
|
3
|
+
// Ref-counted logical subscriptions, exponential backoff, idle-timeout
|
|
4
|
+
// reconnect, and automatic re-subscribe (with each sub's current `since`).
|
|
5
|
+
let nextReqId = 1;
|
|
6
|
+
export class PodWsClient {
|
|
7
|
+
url;
|
|
8
|
+
WS;
|
|
9
|
+
maxDelayMs;
|
|
10
|
+
idleTimeoutMs;
|
|
11
|
+
ws;
|
|
12
|
+
_state = "closed";
|
|
13
|
+
attempts = 0;
|
|
14
|
+
reconnectTimer;
|
|
15
|
+
idleTimer;
|
|
16
|
+
wantOpen = false;
|
|
17
|
+
subs = new Set();
|
|
18
|
+
bySubId = new Map();
|
|
19
|
+
pending = new Map();
|
|
20
|
+
listeners = new Map();
|
|
21
|
+
constructor(opts) {
|
|
22
|
+
this.url = opts.wsUrl;
|
|
23
|
+
const WS = opts.WebSocket ?? globalThis.WebSocket;
|
|
24
|
+
if (!WS)
|
|
25
|
+
throw new Error("No WebSocket implementation available; pass `WebSocket` in options.");
|
|
26
|
+
this.WS = WS;
|
|
27
|
+
this.maxDelayMs = opts.maxDelayMs ?? 30_000;
|
|
28
|
+
this.idleTimeoutMs = opts.idleTimeoutMs ?? 45_000;
|
|
29
|
+
}
|
|
30
|
+
get state() {
|
|
31
|
+
return this._state;
|
|
32
|
+
}
|
|
33
|
+
on(event, handler) {
|
|
34
|
+
let set = this.listeners.get(event);
|
|
35
|
+
if (!set)
|
|
36
|
+
this.listeners.set(event, (set = new Set()));
|
|
37
|
+
set.add(handler);
|
|
38
|
+
return () => set.delete(handler);
|
|
39
|
+
}
|
|
40
|
+
emit(event, e) {
|
|
41
|
+
this.listeners.get(event)?.forEach((h) => {
|
|
42
|
+
try {
|
|
43
|
+
h(e);
|
|
44
|
+
}
|
|
45
|
+
catch { /* ignore listener errors */ }
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
connect() {
|
|
49
|
+
this.wantOpen = true;
|
|
50
|
+
if (this._state === "closed")
|
|
51
|
+
this.open();
|
|
52
|
+
}
|
|
53
|
+
close() {
|
|
54
|
+
this.wantOpen = false;
|
|
55
|
+
this.clearTimers();
|
|
56
|
+
this.subs.clear();
|
|
57
|
+
this.bySubId.clear();
|
|
58
|
+
this.pending.clear();
|
|
59
|
+
if (this.ws) {
|
|
60
|
+
try {
|
|
61
|
+
this.ws.close();
|
|
62
|
+
}
|
|
63
|
+
catch { /* ignore */ }
|
|
64
|
+
this.ws = undefined;
|
|
65
|
+
}
|
|
66
|
+
this._state = "closed";
|
|
67
|
+
}
|
|
68
|
+
subscribe(channel, params, onMessage, onError) {
|
|
69
|
+
const sub = { channel, params: { ...params }, onMessage, onError };
|
|
70
|
+
this.subs.add(sub);
|
|
71
|
+
this.connect();
|
|
72
|
+
if (this._state === "open")
|
|
73
|
+
this.sendSubscribe(sub);
|
|
74
|
+
return {
|
|
75
|
+
unsubscribe: () => this.removeSub(sub),
|
|
76
|
+
update: (p) => { sub.params = { ...sub.params, ...p }; },
|
|
77
|
+
resubscribe: () => {
|
|
78
|
+
if (this._state !== "open")
|
|
79
|
+
return;
|
|
80
|
+
if (sub.subId) {
|
|
81
|
+
this.bySubId.delete(sub.subId);
|
|
82
|
+
sub.subId = undefined;
|
|
83
|
+
}
|
|
84
|
+
this.sendSubscribe(sub);
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
// --- connection lifecycle ---
|
|
89
|
+
open() {
|
|
90
|
+
this.clearReconnect();
|
|
91
|
+
this._state = "connecting";
|
|
92
|
+
const ws = new this.WS(this.url);
|
|
93
|
+
this.ws = ws;
|
|
94
|
+
ws.onopen = () => {
|
|
95
|
+
this._state = "open";
|
|
96
|
+
this.attempts = 0;
|
|
97
|
+
this.emit("open");
|
|
98
|
+
this.armIdle();
|
|
99
|
+
for (const sub of this.subs) {
|
|
100
|
+
sub.subId = undefined;
|
|
101
|
+
this.sendSubscribe(sub);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
ws.onmessage = (ev) => this.onMessage(ev.data);
|
|
105
|
+
ws.onerror = (ev) => this.emit("error", ev);
|
|
106
|
+
ws.onclose = () => {
|
|
107
|
+
this.ws = undefined;
|
|
108
|
+
this.bySubId.clear();
|
|
109
|
+
for (const s of this.subs)
|
|
110
|
+
s.subId = undefined;
|
|
111
|
+
if (this.wantOpen)
|
|
112
|
+
this.scheduleReconnect();
|
|
113
|
+
else
|
|
114
|
+
this._state = "closed";
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
scheduleReconnect() {
|
|
118
|
+
this._state = "connecting";
|
|
119
|
+
const base = Math.min(this.maxDelayMs, 1000 * 2 ** this.attempts);
|
|
120
|
+
const delay = base / 2 + Math.random() * (base / 2); // jittered
|
|
121
|
+
this.attempts++;
|
|
122
|
+
this.clearTimers();
|
|
123
|
+
this.reconnectTimer = setTimeout(() => {
|
|
124
|
+
this.emit("reconnect");
|
|
125
|
+
this.open();
|
|
126
|
+
}, delay);
|
|
127
|
+
}
|
|
128
|
+
armIdle() {
|
|
129
|
+
if (this.idleTimer)
|
|
130
|
+
clearTimeout(this.idleTimer);
|
|
131
|
+
this.idleTimer = setTimeout(() => {
|
|
132
|
+
// No traffic for too long; force a reconnect.
|
|
133
|
+
if (this.ws) {
|
|
134
|
+
try {
|
|
135
|
+
this.ws.close();
|
|
136
|
+
}
|
|
137
|
+
catch { /* ignore */ }
|
|
138
|
+
}
|
|
139
|
+
}, this.idleTimeoutMs);
|
|
140
|
+
}
|
|
141
|
+
clearReconnect() {
|
|
142
|
+
if (this.reconnectTimer) {
|
|
143
|
+
clearTimeout(this.reconnectTimer);
|
|
144
|
+
this.reconnectTimer = undefined;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
clearTimers() {
|
|
148
|
+
this.clearReconnect();
|
|
149
|
+
if (this.idleTimer) {
|
|
150
|
+
clearTimeout(this.idleTimer);
|
|
151
|
+
this.idleTimer = undefined;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
// --- protocol ---
|
|
155
|
+
send(method, params, onReply) {
|
|
156
|
+
if (!this.ws || this._state !== "open")
|
|
157
|
+
return;
|
|
158
|
+
const id = nextReqId++;
|
|
159
|
+
if (onReply)
|
|
160
|
+
this.pending.set(id, onReply);
|
|
161
|
+
this.ws.send(JSON.stringify({ jsonrpc: "2.0", id, method, params }));
|
|
162
|
+
}
|
|
163
|
+
wireParams(p) {
|
|
164
|
+
const out = {};
|
|
165
|
+
if (p.clobIds && p.clobIds.length)
|
|
166
|
+
out.clob_ids = p.clobIds;
|
|
167
|
+
if (p.account)
|
|
168
|
+
out.account = p.account; // server aliases to `bidder`
|
|
169
|
+
if (p.depth !== undefined)
|
|
170
|
+
out.depth = p.depth;
|
|
171
|
+
if (p.since !== undefined)
|
|
172
|
+
out.since = p.since;
|
|
173
|
+
return out;
|
|
174
|
+
}
|
|
175
|
+
sendSubscribe(sub) {
|
|
176
|
+
this.send("eth_subscribe", [sub.channel, this.wireParams(sub.params)], (result, error) => {
|
|
177
|
+
if (error || typeof result !== "string") {
|
|
178
|
+
const err = error ?? new Error("eth_subscribe failed");
|
|
179
|
+
if (sub.onError)
|
|
180
|
+
sub.onError(err); // owner can re-seed + resubscribe (e.g. `since` too old)
|
|
181
|
+
else
|
|
182
|
+
this.emit("error", err);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
// Unsubscribed while the ack was in flight (removeSub had no subId to
|
|
186
|
+
// cancel yet): registering it now would resurrect a dead subscription
|
|
187
|
+
// that keeps pushing into its owner's stale state — tell the server to
|
|
188
|
+
// drop it instead.
|
|
189
|
+
if (!this.subs.has(sub)) {
|
|
190
|
+
this.send("eth_unsubscribe", [result]);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
sub.subId = result;
|
|
194
|
+
this.bySubId.set(result, sub);
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
removeSub(sub) {
|
|
198
|
+
this.subs.delete(sub);
|
|
199
|
+
if (sub.subId) {
|
|
200
|
+
this.bySubId.delete(sub.subId);
|
|
201
|
+
this.send("eth_unsubscribe", [sub.subId]);
|
|
202
|
+
sub.subId = undefined;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
onMessage(data) {
|
|
206
|
+
this.armIdle();
|
|
207
|
+
const handle = (text) => {
|
|
208
|
+
let msg;
|
|
209
|
+
try {
|
|
210
|
+
msg = JSON.parse(text);
|
|
211
|
+
}
|
|
212
|
+
catch {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
if (msg && msg.method === "eth_subscription" && msg.params) {
|
|
216
|
+
const sub = this.bySubId.get(msg.params.subscription);
|
|
217
|
+
if (sub)
|
|
218
|
+
sub.onMessage(msg.params.result);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
if (msg && msg.id !== undefined && this.pending.has(msg.id)) {
|
|
222
|
+
const cb = this.pending.get(msg.id);
|
|
223
|
+
this.pending.delete(msg.id);
|
|
224
|
+
cb(msg.result, msg.error);
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
if (typeof data === "string")
|
|
228
|
+
handle(data);
|
|
229
|
+
else if (data instanceof Blob)
|
|
230
|
+
data.text().then(handle).catch(() => { });
|
|
231
|
+
else if (data instanceof ArrayBuffer)
|
|
232
|
+
handle(new TextDecoder().decode(data));
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
//# sourceMappingURL=ws.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ws.js","sourceRoot":"","sources":["../../src/trans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D,IAAI,GAAG,IAAI,GAAG,CAAC,EAAE,KAAK,SAAS,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;gBAC5D,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAE,CAAC;gBACrC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;gBAC5B,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC;YAC5B,CAAC;QACH,CAAC,CAAC;QACF,IAAI,OAAO,IAAI,KAAK,QAAQ;YAAE,MAAM,CAAC,IAAI,CAAC,CAAC;aACtC,IAAI,IAAI,YAAY,IAAI;YAAE,IAAI,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;aACnE,IAAI,IAAI,YAAY,WAAW;YAAE,MAAM,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IAC/E,CAAC;CACF"}
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
export type Hex = `0x${string}`;
|
|
2
|
+
export type MarketId = Hex;
|
|
3
|
+
export type Address = Hex;
|
|
4
|
+
export type Hash = Hex;
|
|
5
|
+
export type Resolution = "1m" | "5m" | "15m" | "30m" | "1h" | "4h" | "1d" | "1W" | "1M";
|
|
6
|
+
/** Inclusive-from, exclusive-to time window in milliseconds. `to` defaults to now. */
|
|
7
|
+
export interface TimeRange {
|
|
8
|
+
from: number;
|
|
9
|
+
to?: number;
|
|
10
|
+
}
|
|
11
|
+
export type MarketType = "spot" | "perp";
|
|
12
|
+
export type OrderSide = "buy" | "sell";
|
|
13
|
+
export type OrderType = "limit" | "market";
|
|
14
|
+
export type OrderStatus = "pending" | "active" | "filled" | "expired" | "canceled" | "margin_canceled" | "invalid";
|
|
15
|
+
export type OrderKind = "user_signed" | "liquidation" | "triggered" | "adl" | "adl_counterparty"
|
|
16
|
+
/** A backstop transfer merged into the order feed as a synthetic terminal row. */
|
|
17
|
+
| "backstop_transfer";
|
|
18
|
+
export type TriggerType = "take_profit" | "stop_loss";
|
|
19
|
+
export type OrderDirection = "buy" | "sell" | "open_long" | "add_long" | "reduce_long" | "close_long" | "open_short" | "add_short" | "reduce_short" | "close_short" | "long_to_short" | "short_to_long" | "liquidation";
|
|
20
|
+
export interface TokenInfo {
|
|
21
|
+
address: Address;
|
|
22
|
+
symbol: string;
|
|
23
|
+
name: string;
|
|
24
|
+
}
|
|
25
|
+
export interface Market {
|
|
26
|
+
id: MarketId;
|
|
27
|
+
name: string;
|
|
28
|
+
type: MarketType;
|
|
29
|
+
base: TokenInfo;
|
|
30
|
+
quote: TokenInfo;
|
|
31
|
+
tickPrecision: bigint;
|
|
32
|
+
lotSize: bigint;
|
|
33
|
+
maxLeverage: number;
|
|
34
|
+
fundingWindowUs: number;
|
|
35
|
+
makerFee: bigint;
|
|
36
|
+
takerFee: bigint;
|
|
37
|
+
auctionIntervalMs: number;
|
|
38
|
+
lastClearingPrice?: bigint;
|
|
39
|
+
volume24h?: bigint;
|
|
40
|
+
high24h?: bigint;
|
|
41
|
+
low24h?: bigint;
|
|
42
|
+
priceChange24hBps?: number;
|
|
43
|
+
oraclePrice?: bigint;
|
|
44
|
+
markPrice?: bigint;
|
|
45
|
+
fundingRate?: bigint;
|
|
46
|
+
fundingIndex?: bigint;
|
|
47
|
+
fundingLastUpdatedMs?: number;
|
|
48
|
+
openInterest?: bigint;
|
|
49
|
+
}
|
|
50
|
+
export interface Bar {
|
|
51
|
+
time: number;
|
|
52
|
+
open: bigint;
|
|
53
|
+
high: bigint;
|
|
54
|
+
low: bigint;
|
|
55
|
+
close: bigint;
|
|
56
|
+
volume: bigint;
|
|
57
|
+
quoteVolume: bigint;
|
|
58
|
+
}
|
|
59
|
+
export interface OrderbookLevel {
|
|
60
|
+
price: bigint;
|
|
61
|
+
volume: bigint;
|
|
62
|
+
total: bigint;
|
|
63
|
+
/** `total` as a 0..1 fraction of this side's full depth (deepest level → 1).
|
|
64
|
+
* Use directly as a depth-bar width. */
|
|
65
|
+
depth: number;
|
|
66
|
+
}
|
|
67
|
+
export interface Orderbook {
|
|
68
|
+
id: MarketId;
|
|
69
|
+
timeMs: number;
|
|
70
|
+
clearingPrice?: bigint;
|
|
71
|
+
bids: OrderbookLevel[];
|
|
72
|
+
asks: OrderbookLevel[];
|
|
73
|
+
/** (bestBid + bestAsk) / 2; undefined if a side is empty. */
|
|
74
|
+
mid?: bigint;
|
|
75
|
+
/** bestAsk − bestBid (absolute). */
|
|
76
|
+
spread?: bigint;
|
|
77
|
+
/** spread as a percentage of mid. */
|
|
78
|
+
spreadPct?: number;
|
|
79
|
+
bidCount: number;
|
|
80
|
+
askCount: number;
|
|
81
|
+
groupingPrecision: bigint;
|
|
82
|
+
oraclePrice?: bigint;
|
|
83
|
+
fundingRate?: bigint;
|
|
84
|
+
fundingIndex?: bigint;
|
|
85
|
+
fundingLastUpdatedMs?: number;
|
|
86
|
+
}
|
|
87
|
+
export interface PartialFill {
|
|
88
|
+
base: bigint;
|
|
89
|
+
quote: bigint;
|
|
90
|
+
price: bigint;
|
|
91
|
+
time: number;
|
|
92
|
+
}
|
|
93
|
+
export interface Order {
|
|
94
|
+
id: Hash;
|
|
95
|
+
txHash: Hash;
|
|
96
|
+
orderbookId?: MarketId;
|
|
97
|
+
marketType?: MarketType;
|
|
98
|
+
/** Token-address pair (base/quote); present on WS stream orders. */
|
|
99
|
+
pair?: {
|
|
100
|
+
base: Address;
|
|
101
|
+
quote: Address;
|
|
102
|
+
};
|
|
103
|
+
side: OrderSide;
|
|
104
|
+
orderType: OrderType;
|
|
105
|
+
status: OrderStatus;
|
|
106
|
+
kind: OrderKind;
|
|
107
|
+
nonce: number;
|
|
108
|
+
bidder: Address;
|
|
109
|
+
price: bigint;
|
|
110
|
+
initialSize: bigint;
|
|
111
|
+
filledBase: bigint;
|
|
112
|
+
filledQuote: bigint;
|
|
113
|
+
fee: bigint;
|
|
114
|
+
effectivePrice?: bigint;
|
|
115
|
+
deadlineMs: number;
|
|
116
|
+
endMs: number;
|
|
117
|
+
/** Batch-inclusion time (ms) — when the order entered the book. REST history only. */
|
|
118
|
+
includedMs?: number;
|
|
119
|
+
fills: PartialFill[];
|
|
120
|
+
reduceOnly?: boolean;
|
|
121
|
+
ioc?: boolean;
|
|
122
|
+
direction?: OrderDirection;
|
|
123
|
+
triggerType?: TriggerType;
|
|
124
|
+
}
|
|
125
|
+
export type Position = SpotPosition | PerpPosition;
|
|
126
|
+
export interface SpotPosition {
|
|
127
|
+
kind: "spot";
|
|
128
|
+
orderbookId?: MarketId;
|
|
129
|
+
token: Address;
|
|
130
|
+
balance: bigint;
|
|
131
|
+
freeBalance: bigint;
|
|
132
|
+
lockedBalance: bigint;
|
|
133
|
+
costBasis: bigint;
|
|
134
|
+
markPrice: bigint;
|
|
135
|
+
unrealizedPnl: bigint;
|
|
136
|
+
realizedPnl: bigint;
|
|
137
|
+
}
|
|
138
|
+
export interface PerpPosition {
|
|
139
|
+
kind: "perp";
|
|
140
|
+
orderbookId: MarketId;
|
|
141
|
+
side: "long" | "short";
|
|
142
|
+
size: bigint;
|
|
143
|
+
notional: bigint;
|
|
144
|
+
entryPrice: bigint;
|
|
145
|
+
markPrice: bigint;
|
|
146
|
+
margin: bigint;
|
|
147
|
+
leverage: number;
|
|
148
|
+
fundingAccrued: bigint;
|
|
149
|
+
/** Funding accumulator at entry; with the live fundingIndex + fundingWindowUs, recompute fundingAccrued. */
|
|
150
|
+
entryFunding: bigint;
|
|
151
|
+
liquidationPrice: bigint;
|
|
152
|
+
unrealizedPnl: bigint;
|
|
153
|
+
realizedPnl: bigint;
|
|
154
|
+
}
|
|
155
|
+
export interface PositionsSnapshot {
|
|
156
|
+
positions: Position[];
|
|
157
|
+
totalUnrealizedPnl: bigint;
|
|
158
|
+
totalRealizedPnl: bigint;
|
|
159
|
+
perpsEquity: bigint;
|
|
160
|
+
accountValue: bigint;
|
|
161
|
+
cash: bigint;
|
|
162
|
+
withdrawableCash: bigint;
|
|
163
|
+
}
|
|
164
|
+
export interface Trigger {
|
|
165
|
+
orderbookId: MarketId;
|
|
166
|
+
orderId: Hash;
|
|
167
|
+
txHash: Hash;
|
|
168
|
+
bidder: Address;
|
|
169
|
+
nonce: number;
|
|
170
|
+
size: bigint;
|
|
171
|
+
limitPrice: bigint;
|
|
172
|
+
triggerPrice: bigint;
|
|
173
|
+
triggerType: TriggerType;
|
|
174
|
+
reduceOnly: boolean;
|
|
175
|
+
ioc: boolean;
|
|
176
|
+
deadlineMs: number;
|
|
177
|
+
endMs: number;
|
|
178
|
+
}
|
|
179
|
+
export interface BackstopTransfer {
|
|
180
|
+
orderbookId?: MarketId;
|
|
181
|
+
size: bigint;
|
|
182
|
+
cash: bigint;
|
|
183
|
+
markPrice: bigint;
|
|
184
|
+
equity: bigint;
|
|
185
|
+
time: number;
|
|
186
|
+
}
|
|
187
|
+
export interface Status {
|
|
188
|
+
/** Newest indexed solution time (the settled watermark), in ms. */
|
|
189
|
+
solutionNow: number;
|
|
190
|
+
}
|
|
191
|
+
export interface TxAttestation {
|
|
192
|
+
validator_address: string;
|
|
193
|
+
sequence_number: number;
|
|
194
|
+
batch_index?: number;
|
|
195
|
+
timestamp: number;
|
|
196
|
+
signature: string;
|
|
197
|
+
}
|
|
198
|
+
/** Pre-decoded calldata: `{contract, function, args}` plus curation
|
|
199
|
+
* (order_id, submitBatch sub-intents, ERC20 symbol …). */
|
|
200
|
+
export interface TxDecoded {
|
|
201
|
+
contract: string;
|
|
202
|
+
function: string;
|
|
203
|
+
args: Record<string, unknown>;
|
|
204
|
+
order_id?: string;
|
|
205
|
+
[k: string]: unknown;
|
|
206
|
+
}
|
|
207
|
+
/** Flat explorer view of a transaction. Hex fields are raw RPC encodings —
|
|
208
|
+
* format them at the edge. Extra fields are tolerated (index signature). */
|
|
209
|
+
export interface TxExplorer {
|
|
210
|
+
hash: string;
|
|
211
|
+
type: string;
|
|
212
|
+
nonce: string;
|
|
213
|
+
from: string;
|
|
214
|
+
to: string | null;
|
|
215
|
+
value: string;
|
|
216
|
+
gas: string;
|
|
217
|
+
gasUsed: string;
|
|
218
|
+
status: string;
|
|
219
|
+
input: string;
|
|
220
|
+
logs: unknown[];
|
|
221
|
+
decoded?: TxDecoded | null;
|
|
222
|
+
attestations: TxAttestation[];
|
|
223
|
+
committee_epoch?: number;
|
|
224
|
+
chainId?: string;
|
|
225
|
+
maxFeePerGas?: string;
|
|
226
|
+
effectiveGasPrice?: string;
|
|
227
|
+
blockNumber?: string;
|
|
228
|
+
transactionIndex?: string;
|
|
229
|
+
contractAddress?: string | null;
|
|
230
|
+
[k: string]: unknown;
|
|
231
|
+
}
|
|
232
|
+
/** A spot token holding (`/clob/balances`). Like SpotPosition but identified by
|
|
233
|
+
* market + symbols rather than token address. */
|
|
234
|
+
export interface SpotHolding {
|
|
235
|
+
orderbookId: MarketId;
|
|
236
|
+
baseSymbol: string;
|
|
237
|
+
quoteSymbol: string;
|
|
238
|
+
balance: bigint;
|
|
239
|
+
freeBalance: bigint;
|
|
240
|
+
lockedBalance: bigint;
|
|
241
|
+
costBasis: bigint;
|
|
242
|
+
markPrice: bigint;
|
|
243
|
+
unrealizedPnl: bigint;
|
|
244
|
+
realizedPnl: bigint;
|
|
245
|
+
}
|
|
246
|
+
/** Spot holdings + native cash for an account (`/clob/balances`). Perp positions
|
|
247
|
+
* and their aggregates live in {@link PositionsSnapshot}. */
|
|
248
|
+
export interface Balances {
|
|
249
|
+
holdings: SpotHolding[];
|
|
250
|
+
cash: bigint;
|
|
251
|
+
withdrawableCash: bigint;
|
|
252
|
+
netDeposits: bigint;
|
|
253
|
+
}
|
|
254
|
+
/** One ranked account from the leaderboard (`/clob/leaderboard`). */
|
|
255
|
+
export interface LeaderboardEntry {
|
|
256
|
+
rank: number;
|
|
257
|
+
account: Address;
|
|
258
|
+
accountValue: bigint;
|
|
259
|
+
unrealizedPnl: bigint;
|
|
260
|
+
realizedPnl: bigint;
|
|
261
|
+
/** Net PnL = unrealized + realized — the key the board is ranked by. */
|
|
262
|
+
pnl: bigint;
|
|
263
|
+
/** pnl / (accountValue − unrealized) × 100; 0 when the basis is dust. */
|
|
264
|
+
pnlPercent: number;
|
|
265
|
+
}
|
|
266
|
+
export interface LeaderboardPage {
|
|
267
|
+
entries: LeaderboardEntry[];
|
|
268
|
+
/** Full count of ranked accounts (before paging) — for page math. */
|
|
269
|
+
total: number;
|
|
270
|
+
}
|
|
271
|
+
export interface LeaderboardQuery {
|
|
272
|
+
limit?: number;
|
|
273
|
+
offset?: number;
|
|
274
|
+
/** When set, the response also locates this account's own rank. */
|
|
275
|
+
account?: Address;
|
|
276
|
+
}
|
|
277
|
+
export interface CandleQuery {
|
|
278
|
+
resolution: Resolution;
|
|
279
|
+
from?: number;
|
|
280
|
+
to?: number;
|
|
281
|
+
limit?: number;
|
|
282
|
+
}
|
|
283
|
+
export interface OrdersQuery {
|
|
284
|
+
status?: OrderStatus;
|
|
285
|
+
orderbookId?: MarketId;
|
|
286
|
+
limit?: number;
|
|
287
|
+
}
|
|
288
|
+
export interface TriggersQuery {
|
|
289
|
+
orderbookId?: MarketId;
|
|
290
|
+
limit?: number;
|
|
291
|
+
}
|
|
292
|
+
//# sourceMappingURL=public.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../../src/types/public.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,GAAG,GAAG,KAAK,MAAM,EAAE,CAAC;AAChC,MAAM,MAAM,QAAQ,GAAG,GAAG,CAAC;AAC3B,MAAM,MAAM,OAAO,GAAG,GAAG,CAAC;AAC1B,MAAM,MAAM,IAAI,GAAG,GAAG,CAAC;AAEvB,MAAM,MAAM,UAAU,GAClB,IAAI,GAAG,IAAI,G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