@lightconexyz/lightcone-sdk 0.4.15 → 0.5.1
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 +172 -43
- package/dist/auth/client.d.ts +1 -1
- package/dist/auth/client.d.ts.map +1 -1
- package/dist/auth/client.js +2 -7
- package/dist/auth/client.js.map +1 -1
- package/dist/domain/admin/client.d.ts +11 -8
- package/dist/domain/admin/client.d.ts.map +1 -1
- package/dist/domain/admin/client.js +33 -14
- package/dist/domain/admin/client.js.map +1 -1
- package/dist/domain/admin/index.d.ts +12 -3
- package/dist/domain/admin/index.d.ts.map +1 -1
- package/dist/domain/admin/index.js.map +1 -1
- package/dist/domain/admin/wire.d.ts +1 -2
- package/dist/domain/admin/wire.d.ts.map +1 -1
- package/dist/domain/admin/wire.js.map +1 -1
- package/dist/domain/market/tokens.js +4 -6
- package/dist/domain/market/tokens.js.map +1 -1
- package/dist/domain/market/wire.d.ts +1 -3
- package/dist/domain/market/wire.d.ts.map +1 -1
- package/dist/domain/market/wire.js.map +1 -1
- package/dist/domain/order/client.d.ts +1 -115
- package/dist/domain/order/client.d.ts.map +1 -1
- package/dist/domain/order/client.js +12 -71
- package/dist/domain/order/client.js.map +1 -1
- package/dist/domain/order/index.d.ts +2 -9
- package/dist/domain/order/index.d.ts.map +1 -1
- package/dist/domain/order/index.js +2 -9
- package/dist/domain/order/index.js.map +1 -1
- package/dist/domain/order/wire.d.ts +80 -2
- package/dist/domain/order/wire.d.ts.map +1 -1
- package/dist/domain/order/wire.js +141 -0
- package/dist/domain/order/wire.js.map +1 -1
- package/dist/error.d.ts +5 -2
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +10 -1
- package/dist/error.js.map +1 -1
- package/dist/http/client.d.ts +9 -1
- package/dist/http/client.d.ts.map +1 -1
- package/dist/http/client.js +126 -31
- package/dist/http/client.js.map +1 -1
- package/dist/prelude.d.ts +1 -1
- package/dist/prelude.d.ts.map +1 -1
- package/dist/prelude.js +4 -1
- package/dist/prelude.js.map +1 -1
- package/dist/privy/client.d.ts +3 -3
- package/dist/privy/client.d.ts.map +1 -1
- package/dist/privy/client.js.map +1 -1
- package/dist/privy/index.d.ts +1 -6
- package/dist/privy/index.d.ts.map +1 -1
- package/dist/privy/index.js.map +1 -1
- package/dist/program/accounts.d.ts +2 -1
- package/dist/program/accounts.d.ts.map +1 -1
- package/dist/program/accounts.js +6 -2
- package/dist/program/accounts.js.map +1 -1
- package/dist/program/instructions.d.ts +1 -1
- package/dist/program/instructions.d.ts.map +1 -1
- package/dist/program/instructions.js +2 -1
- package/dist/program/instructions.js.map +1 -1
- package/dist/program/types.d.ts +2 -0
- package/dist/program/types.d.ts.map +1 -1
- package/dist/program/types.js.map +1 -1
- package/dist/shared/api_response.d.ts +32 -0
- package/dist/shared/api_response.d.ts.map +1 -0
- package/dist/shared/api_response.js +61 -0
- package/dist/shared/api_response.js.map +1 -0
- package/dist/shared/index.d.ts +2 -0
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +6 -1
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/rejection.d.ts +9 -0
- package/dist/shared/rejection.d.ts.map +1 -0
- package/dist/shared/rejection.js +48 -0
- package/dist/shared/rejection.js.map +1 -0
- package/dist/ws/client.browser.d.ts +2 -1
- package/dist/ws/client.browser.d.ts.map +1 -1
- package/dist/ws/client.browser.js +9 -3
- package/dist/ws/client.browser.js.map +1 -1
- package/dist/ws/client.node.d.ts +2 -1
- package/dist/ws/client.node.d.ts.map +1 -1
- package/dist/ws/client.node.js +9 -3
- package/dist/ws/client.node.js.map +1 -1
- package/dist/ws/index.d.ts +1 -1
- package/dist/ws/index.d.ts.map +1 -1
- package/dist/ws/index.js +9 -1
- package/dist/ws/index.js.map +1 -1
- package/package.json +1 -1
package/dist/ws/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { MarketEvent } from "../domain/market";
|
|
2
|
-
import type
|
|
2
|
+
import { type AuthUpdate, type UserUpdate } from "../domain/order/wire";
|
|
3
3
|
import type { OrderBook, WsTickerData } from "../domain/orderbook";
|
|
4
4
|
import type { DepositPrice, PriceHistory } from "../domain/price_history";
|
|
5
5
|
import type { WsTrade } from "../domain/trade";
|
package/dist/ws/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ws/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ws/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAuB,KAAK,UAAU,EAAE,KAAK,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC7F,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC1E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAG/C,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEpE,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC,MAAM,MAAM,UAAU,GAClB;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,MAAM,EAAE,OAAO,iBAAiB,EAAE,eAAe,CAAA;CAAE,GAC1E;IAAE,MAAM,EAAE,aAAa,CAAC;IAAC,MAAM,EAAE,OAAO,iBAAiB,EAAE,iBAAiB,CAAA;CAAE,GAC9E;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvB,MAAM,M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E,WAAW,EAAE,GAAG,UAAU,CAQzE;AAED,wBAAgB,aAAa,CAAC,aAAa,EAAE,SAAS,GAAG,UAAU,CAQlE;AAED,wBAAgB,eAAe,CAAC,aAAa,EAAE,SAAS,GAAG,UAAU,CAQpE;AAED,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,GAAG,UAAU,CAUlG;AAED,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,GAAG,UAAU,CASpG;AAED,wBAAgB,eAAe,CAAC,YAAY,EAAE,WAAW,EAAE,GAAG,UAAU,CAQvE;AAED,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,WAAW,EAAE,GAAG,UAAU,CAQzE;AAED,wBAAgB,eAAe,CAAC,YAAY,EAAE,SAAS,GAAG,UAAU,CAQnE;AAED,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,SAAS,GAAG,UAAU,CAQrE;AAED,wBAAgB,qBAAqB,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,UAAU,CAS9F;AAED,wBAAgB,uBAAuB,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,UAAU,CAShG;AAeD,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAuBvD"}
|
package/dist/ws/index.js
CHANGED
|
@@ -32,6 +32,7 @@ exports.unsubscribeMarket = unsubscribeMarket;
|
|
|
32
32
|
exports.subscribeDepositPrice = subscribeDepositPrice;
|
|
33
33
|
exports.unsubscribeDepositPrice = unsubscribeDepositPrice;
|
|
34
34
|
exports.parseMessageIn = parseMessageIn;
|
|
35
|
+
const wire_1 = require("../domain/order/wire");
|
|
35
36
|
const error_1 = require("../error");
|
|
36
37
|
const env_1 = require("../env");
|
|
37
38
|
__exportStar(require("./client.node"), exports);
|
|
@@ -225,6 +226,13 @@ function parseMessageIn(input) {
|
|
|
225
226
|
if (!("data" in obj) || typeof obj.data !== "object" || obj.data === null) {
|
|
226
227
|
throw new error_1.WsError("ProtocolError", `Invalid WS message: missing or invalid "data" field`);
|
|
227
228
|
}
|
|
228
|
-
|
|
229
|
+
const message = parsed;
|
|
230
|
+
if (message.type === "user") {
|
|
231
|
+
return {
|
|
232
|
+
...message,
|
|
233
|
+
data: (0, wire_1.normalizeUserUpdate)(message.data),
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
return message;
|
|
229
237
|
}
|
|
230
238
|
//# sourceMappingURL=index.js.map
|
package/dist/ws/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ws/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AA0EA,wCAYC;AAED,oBAEC;AAED,wCAQC;AAED,4CAQC;AAED,0CAQC;AAED,8CAQC;AAED,sCAQC;AAED,0CAQC;AAED,sDAUC;AAED,0DASC;AAED,0CAQC;AAED,8CAQC;AAED,0CAQC;AAED,8CAQC;AAED,sDASC;AAED,0DASC;AAeD,wCAgBC;AArQD,oCAAmD;AACnD,gCAA6C;AAG7C,gDAA8B;AAC9B,kDAAgC;AAgDnB,QAAA,iBAAiB,GAAa;IACzC,GAAG,EAAE,IAAA,WAAK,EAAC,kBAAY,CAAC,IAAI,CAAC;IAC7B,SAAS,EAAE,IAAI;IACf,oBAAoB,EAAE,EAAE;IACxB,oBAAoB,EAAE,KAAK;IAC3B,cAAc,EAAE,MAAM;IACtB,aAAa,EAAE,MAAM;CACtB,CAAC;AAEF,IAAY,UAKX;AALD,WAAY,UAAU;IACpB,uDAAc,CAAA;IACd,2CAAQ,CAAA;IACR,iDAAW,CAAA;IACX,+CAAU,CAAA;AACZ,CAAC,EALW,UAAU,0BAAV,UAAU,QAKrB;AAED,SAAgB,cAAc,CAAC,KAAa;IAC1C,QAAQ,KAAK,EAAE,CAAC;QACd,KAAK,CAAC;YACJ,OAAO,UAAU,CAAC,UAAU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AAI,GAAG,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;QAC1E,MAAM,IAAI,eAAY,CAAC,eAAe,EAAE,qDAAqD,CAAC,CAAC;IACjG,CAAC;IACD,OAAO,MAAmB,CAAC;AAC7B,CAAC","sourcesContent":["import type { MarketEvent } from \"../domain/market\";\nimport type { AuthUpdate, UserUpdate } from \"../domain/order\";\nimport type { OrderBook, WsTickerData } from \"../domain/orderbook\";\nimport type { DepositPrice, PriceHistory } from \"../domain/price_history\";\nimport type { WsTrade } from \"../domain/trade\";\nimport { WsError as WsErrorClass } from \"../error\";\nimport { LightconeEnv, wsUrl } from \"../env\";\nimport type { OrderBookId, PubkeyStr, Resolution } from \"../shared\";\n\nexport * from \"./client.node\";\nexport * from \"./subscriptions\";\nexport type { IWsClient } from \"./types\";\n\nexport type MessageOut =\n | { method: \"subscribe\"; params: import(\"./subscriptions\").SubscribeParams }\n | { method: \"unsubscribe\"; params: import(\"./subscriptions\").UnsubscribeParams }\n | { method: \"ping\" };\n\nexport type MessageIn =\n | { type: \"book_update\"; version: number; data: OrderBook }\n | { type: \"pong\"; version: number; data: Record<string, never> }\n | { type: \"user\"; version: number; data: UserUpdate }\n | { type: \"error\"; version: number; data: WsError }\n | { type: \"price_history\"; version: number; data: PriceHistory }\n | { type: \"trades\"; version: number; data: WsTrade }\n | { type: \"auth\"; version: number; data: AuthUpdate }\n | { type: \"ticker\"; version: number; data: WsTickerData }\n | { type: \"market\"; version: number; data: MarketEvent }\n | { type: \"deposit_price\"; version: number; data: DepositPrice };\n\nexport type Kind = MessageIn;\n\nexport interface WsError {\n error: string;\n code?: string;\n orderbook_id?: string;\n wallet_address?: string;\n deposit_asset?: string;\n hint?: string;\n details?: string;\n}\n\nexport type WsEvent =\n | { type: \"Message\"; message: MessageIn }\n | { type: \"Connected\" }\n | { type: \"Disconnected\"; code?: number; reason: string }\n | { type: \"Error\"; error: string }\n | { type: \"MaxReconnectReached\" };\n\nexport interface WsConfig {\n url: string;\n reconnect: boolean;\n maxReconnectAttempts: number;\n baseReconnectDelayMs: number;\n pingIntervalMs: number;\n pongTimeoutMs: number;\n}\n\nexport const WS_DEFAULT_CONFIG: WsConfig = {\n url: wsUrl(LightconeEnv.Prod),\n reconnect: true,\n maxReconnectAttempts: 10,\n baseReconnectDelayMs: 1_000,\n pingIntervalMs: 30_000,\n pongTimeoutMs: 10_000,\n};\n\nexport enum ReadyState {\n Connecting = 0,\n Open = 1,\n Closing = 2,\n Closed = 3,\n}\n\nexport function readyStateFrom(value: number): ReadyState {\n switch (value) {\n case 0:\n return ReadyState.Connecting;\n case 1:\n return ReadyState.Open;\n case 2:\n return ReadyState.Closing;\n case 3:\n default:\n return ReadyState.Closed;\n }\n}\n\nexport function ping(): MessageOut {\n return { method: \"ping\" };\n}\n\nexport function subscribeBooks(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"book_update\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function unsubscribeBooks(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"book_update\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function subscribeTrades(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"trades\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function unsubscribeTrades(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"trades\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function subscribeUser(walletAddress: PubkeyStr): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"user\",\n wallet_address: walletAddress,\n },\n };\n}\n\nexport function unsubscribeUser(walletAddress: PubkeyStr): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"user\",\n wallet_address: walletAddress,\n },\n };\n}\n\nexport function subscribePriceHistory(orderbookId: OrderBookId, resolution: Resolution): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"price_history\",\n orderbook_id: orderbookId,\n resolution,\n include_ohlcv: false,\n },\n };\n}\n\nexport function unsubscribePriceHistory(orderbookId: OrderBookId, resolution: Resolution): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"price_history\",\n orderbook_id: orderbookId,\n resolution,\n },\n };\n}\n\nexport function subscribeTicker(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"ticker\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function unsubscribeTicker(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"ticker\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function subscribeMarket(marketPubkey: PubkeyStr): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"market\",\n market_pubkey: marketPubkey,\n },\n };\n}\n\nexport function unsubscribeMarket(marketPubkey: PubkeyStr): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"market\",\n market_pubkey: marketPubkey,\n },\n };\n}\n\nexport function subscribeDepositPrice(depositAsset: string, resolution: Resolution): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"deposit_price\",\n deposit_asset: depositAsset,\n resolution,\n },\n };\n}\n\nexport function unsubscribeDepositPrice(depositAsset: string, resolution: Resolution): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"deposit_price\",\n deposit_asset: depositAsset,\n resolution,\n },\n };\n}\n\nconst VALID_MESSAGE_TYPES = new Set([\n \"book_update\",\n \"pong\",\n \"user\",\n \"error\",\n \"price_history\",\n \"trades\",\n \"auth\",\n \"ticker\",\n \"market\",\n \"deposit_price\",\n]);\n\nexport function parseMessageIn(input: string): MessageIn {\n const parsed: unknown = JSON.parse(input);\n if (typeof parsed !== \"object\" || parsed === null || !(\"type\" in parsed)) {\n throw new WsErrorClass(\"ProtocolError\", `Invalid WS message: missing \"type\" field`);\n }\n const obj = parsed as Record<string, unknown>;\n if (typeof obj.type !== \"string\" || !VALID_MESSAGE_TYPES.has(obj.type)) {\n throw new WsErrorClass(\"ProtocolError\", `Invalid WS message type: \"${String(obj.type)}\"`);\n }\n if (!(\"version\" in obj) || typeof obj.version !== \"number\") {\n throw new WsErrorClass(\"ProtocolError\", `Invalid WS message: missing or invalid \"version\" field`);\n }\n if (!(\"data\" in obj) || typeof obj.data !== \"object\" || obj.data === null) {\n throw new WsErrorClass(\"ProtocolError\", `Invalid WS message: missing or invalid \"data\" field`);\n }\n return parsed as MessageIn;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ws/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AA0EA,wCAYC;AAED,oBAEC;AAED,wCAQC;AAED,4CAQC;AAED,0CAQC;AAED,8CAQC;AAED,sCAQC;AAED,0CAQC;AAED,sDAUC;AAED,0DASC;AAED,0CAQC;AAED,8CAQC;AAED,0CAQC;AAED,8CAQC;AAED,sDASC;AAED,0DASC;AAeD,wCAuBC;AAhRD,+CAA6F;AAI7F,oCAAmD;AACnD,gCAA6C;AAG7C,gDAA8B;AAC9B,kDAAgC;AAgDnB,QAAA,iBAAiB,GAAa;IACzC,GAAG,EAAE,IAAA,WAAK,EAAC,kBAAY,CAAC,IAAI,CAAC;IAC7B,SAAS,EAAE,IAAI;IACf,oBAAoB,EAAE,EAAE;IACxB,oBAAoB,EAAE,KAAK;IAC3B,cAAc,EAAE,MAAM;IACtB,aAAa,EAAE,MAAM;CACtB,CAAC;AAEF,IAAY,UAKX;AALD,WAAY,UAAU;IACpB,uDAAc,CAAA;IACd,2CAAQ,CAAA;IACR,iDAAW,CAAA;IACX,+CAAU,CAAA;AACZ,CAAC,EALW,UAAU,0BAAV,UAAU,QAKrB;AAED,SAAgB,cAAc,CAAC,KAAa;IAC1C,QAAQ,KAAK,EAAE,CAAC;QACd,KAAK,CAAC;YACJ,OAAO,UAAU,CAAC,UAAU,CAAC;QAC/B,KAAK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AI,KAAK,IAAI,EAAE,CAAC;QAC1E,MAAM,IAAI,eAAY,CAAC,eAAe,EAAE,qDAAqD,CAAC,CAAC;IACjG,CAAC;IACD,MAAM,OAAO,GAAG,MAAmB,CAAC;IACpC,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QAC5B,OAAO;YACL,GAAG,OAAO;YACV,IAAI,EAAE,IAAA,0BAAmB,EAAC,OAAO,CAAC,IAAiD,CAAC;SACrF,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type { MarketEvent } from \"../domain/market\";\nimport { normalizeUserUpdate, type AuthUpdate, type UserUpdate } from \"../domain/order/wire\";\nimport type { OrderBook, WsTickerData } from \"../domain/orderbook\";\nimport type { DepositPrice, PriceHistory } from \"../domain/price_history\";\nimport type { WsTrade } from \"../domain/trade\";\nimport { WsError as WsErrorClass } from \"../error\";\nimport { LightconeEnv, wsUrl } from \"../env\";\nimport type { OrderBookId, PubkeyStr, Resolution } from \"../shared\";\n\nexport * from \"./client.node\";\nexport * from \"./subscriptions\";\nexport type { IWsClient } from \"./types\";\n\nexport type MessageOut =\n | { method: \"subscribe\"; params: import(\"./subscriptions\").SubscribeParams }\n | { method: \"unsubscribe\"; params: import(\"./subscriptions\").UnsubscribeParams }\n | { method: \"ping\" };\n\nexport type MessageIn =\n | { type: \"book_update\"; version: number; data: OrderBook }\n | { type: \"pong\"; version: number; data: Record<string, never> }\n | { type: \"user\"; version: number; data: UserUpdate }\n | { type: \"error\"; version: number; data: WsError }\n | { type: \"price_history\"; version: number; data: PriceHistory }\n | { type: \"trades\"; version: number; data: WsTrade }\n | { type: \"auth\"; version: number; data: AuthUpdate }\n | { type: \"ticker\"; version: number; data: WsTickerData }\n | { type: \"market\"; version: number; data: MarketEvent }\n | { type: \"deposit_price\"; version: number; data: DepositPrice };\n\nexport type Kind = MessageIn;\n\nexport interface WsError {\n error: string;\n code?: string;\n orderbook_id?: string;\n wallet_address?: string;\n deposit_asset?: string;\n hint?: string;\n details?: string;\n}\n\nexport type WsEvent =\n | { type: \"Message\"; message: MessageIn }\n | { type: \"Connected\" }\n | { type: \"Disconnected\"; code?: number; reason: string }\n | { type: \"Error\"; error: string }\n | { type: \"MaxReconnectReached\" };\n\nexport interface WsConfig {\n url: string;\n reconnect: boolean;\n maxReconnectAttempts: number;\n baseReconnectDelayMs: number;\n pingIntervalMs: number;\n pongTimeoutMs: number;\n}\n\nexport const WS_DEFAULT_CONFIG: WsConfig = {\n url: wsUrl(LightconeEnv.Prod),\n reconnect: true,\n maxReconnectAttempts: 10,\n baseReconnectDelayMs: 1_000,\n pingIntervalMs: 30_000,\n pongTimeoutMs: 10_000,\n};\n\nexport enum ReadyState {\n Connecting = 0,\n Open = 1,\n Closing = 2,\n Closed = 3,\n}\n\nexport function readyStateFrom(value: number): ReadyState {\n switch (value) {\n case 0:\n return ReadyState.Connecting;\n case 1:\n return ReadyState.Open;\n case 2:\n return ReadyState.Closing;\n case 3:\n default:\n return ReadyState.Closed;\n }\n}\n\nexport function ping(): MessageOut {\n return { method: \"ping\" };\n}\n\nexport function subscribeBooks(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"book_update\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function unsubscribeBooks(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"book_update\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function subscribeTrades(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"trades\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function unsubscribeTrades(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"trades\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function subscribeUser(walletAddress: PubkeyStr): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"user\",\n wallet_address: walletAddress,\n },\n };\n}\n\nexport function unsubscribeUser(walletAddress: PubkeyStr): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"user\",\n wallet_address: walletAddress,\n },\n };\n}\n\nexport function subscribePriceHistory(orderbookId: OrderBookId, resolution: Resolution): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"price_history\",\n orderbook_id: orderbookId,\n resolution,\n include_ohlcv: false,\n },\n };\n}\n\nexport function unsubscribePriceHistory(orderbookId: OrderBookId, resolution: Resolution): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"price_history\",\n orderbook_id: orderbookId,\n resolution,\n },\n };\n}\n\nexport function subscribeTicker(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"ticker\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function unsubscribeTicker(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"ticker\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function subscribeMarket(marketPubkey: PubkeyStr): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"market\",\n market_pubkey: marketPubkey,\n },\n };\n}\n\nexport function unsubscribeMarket(marketPubkey: PubkeyStr): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"market\",\n market_pubkey: marketPubkey,\n },\n };\n}\n\nexport function subscribeDepositPrice(depositAsset: string, resolution: Resolution): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"deposit_price\",\n deposit_asset: depositAsset,\n resolution,\n },\n };\n}\n\nexport function unsubscribeDepositPrice(depositAsset: string, resolution: Resolution): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"deposit_price\",\n deposit_asset: depositAsset,\n resolution,\n },\n };\n}\n\nconst VALID_MESSAGE_TYPES = new Set([\n \"book_update\",\n \"pong\",\n \"user\",\n \"error\",\n \"price_history\",\n \"trades\",\n \"auth\",\n \"ticker\",\n \"market\",\n \"deposit_price\",\n]);\n\nexport function parseMessageIn(input: string): MessageIn {\n const parsed: unknown = JSON.parse(input);\n if (typeof parsed !== \"object\" || parsed === null || !(\"type\" in parsed)) {\n throw new WsErrorClass(\"ProtocolError\", `Invalid WS message: missing \"type\" field`);\n }\n const obj = parsed as Record<string, unknown>;\n if (typeof obj.type !== \"string\" || !VALID_MESSAGE_TYPES.has(obj.type)) {\n throw new WsErrorClass(\"ProtocolError\", `Invalid WS message type: \"${String(obj.type)}\"`);\n }\n if (!(\"version\" in obj) || typeof obj.version !== \"number\") {\n throw new WsErrorClass(\"ProtocolError\", `Invalid WS message: missing or invalid \"version\" field`);\n }\n if (!(\"data\" in obj) || typeof obj.data !== \"object\" || obj.data === null) {\n throw new WsErrorClass(\"ProtocolError\", `Invalid WS message: missing or invalid \"data\" field`);\n }\n const message = parsed as MessageIn;\n if (message.type === \"user\") {\n return {\n ...message,\n data: normalizeUserUpdate(message.data as Parameters<typeof normalizeUserUpdate>[0]),\n };\n }\n return message;\n}\n"]}
|