@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.
Files changed (86) hide show
  1. package/README.md +172 -43
  2. package/dist/auth/client.d.ts +1 -1
  3. package/dist/auth/client.d.ts.map +1 -1
  4. package/dist/auth/client.js +2 -7
  5. package/dist/auth/client.js.map +1 -1
  6. package/dist/domain/admin/client.d.ts +11 -8
  7. package/dist/domain/admin/client.d.ts.map +1 -1
  8. package/dist/domain/admin/client.js +33 -14
  9. package/dist/domain/admin/client.js.map +1 -1
  10. package/dist/domain/admin/index.d.ts +12 -3
  11. package/dist/domain/admin/index.d.ts.map +1 -1
  12. package/dist/domain/admin/index.js.map +1 -1
  13. package/dist/domain/admin/wire.d.ts +1 -2
  14. package/dist/domain/admin/wire.d.ts.map +1 -1
  15. package/dist/domain/admin/wire.js.map +1 -1
  16. package/dist/domain/market/tokens.js +4 -6
  17. package/dist/domain/market/tokens.js.map +1 -1
  18. package/dist/domain/market/wire.d.ts +1 -3
  19. package/dist/domain/market/wire.d.ts.map +1 -1
  20. package/dist/domain/market/wire.js.map +1 -1
  21. package/dist/domain/order/client.d.ts +1 -115
  22. package/dist/domain/order/client.d.ts.map +1 -1
  23. package/dist/domain/order/client.js +12 -71
  24. package/dist/domain/order/client.js.map +1 -1
  25. package/dist/domain/order/index.d.ts +2 -9
  26. package/dist/domain/order/index.d.ts.map +1 -1
  27. package/dist/domain/order/index.js +2 -9
  28. package/dist/domain/order/index.js.map +1 -1
  29. package/dist/domain/order/wire.d.ts +80 -2
  30. package/dist/domain/order/wire.d.ts.map +1 -1
  31. package/dist/domain/order/wire.js +141 -0
  32. package/dist/domain/order/wire.js.map +1 -1
  33. package/dist/error.d.ts +5 -2
  34. package/dist/error.d.ts.map +1 -1
  35. package/dist/error.js +10 -1
  36. package/dist/error.js.map +1 -1
  37. package/dist/http/client.d.ts +9 -1
  38. package/dist/http/client.d.ts.map +1 -1
  39. package/dist/http/client.js +126 -31
  40. package/dist/http/client.js.map +1 -1
  41. package/dist/prelude.d.ts +1 -1
  42. package/dist/prelude.d.ts.map +1 -1
  43. package/dist/prelude.js +4 -1
  44. package/dist/prelude.js.map +1 -1
  45. package/dist/privy/client.d.ts +3 -3
  46. package/dist/privy/client.d.ts.map +1 -1
  47. package/dist/privy/client.js.map +1 -1
  48. package/dist/privy/index.d.ts +1 -6
  49. package/dist/privy/index.d.ts.map +1 -1
  50. package/dist/privy/index.js.map +1 -1
  51. package/dist/program/accounts.d.ts +2 -1
  52. package/dist/program/accounts.d.ts.map +1 -1
  53. package/dist/program/accounts.js +6 -2
  54. package/dist/program/accounts.js.map +1 -1
  55. package/dist/program/instructions.d.ts +1 -1
  56. package/dist/program/instructions.d.ts.map +1 -1
  57. package/dist/program/instructions.js +2 -1
  58. package/dist/program/instructions.js.map +1 -1
  59. package/dist/program/types.d.ts +2 -0
  60. package/dist/program/types.d.ts.map +1 -1
  61. package/dist/program/types.js.map +1 -1
  62. package/dist/shared/api_response.d.ts +32 -0
  63. package/dist/shared/api_response.d.ts.map +1 -0
  64. package/dist/shared/api_response.js +61 -0
  65. package/dist/shared/api_response.js.map +1 -0
  66. package/dist/shared/index.d.ts +2 -0
  67. package/dist/shared/index.d.ts.map +1 -1
  68. package/dist/shared/index.js +6 -1
  69. package/dist/shared/index.js.map +1 -1
  70. package/dist/shared/rejection.d.ts +9 -0
  71. package/dist/shared/rejection.d.ts.map +1 -0
  72. package/dist/shared/rejection.js +48 -0
  73. package/dist/shared/rejection.js.map +1 -0
  74. package/dist/ws/client.browser.d.ts +2 -1
  75. package/dist/ws/client.browser.d.ts.map +1 -1
  76. package/dist/ws/client.browser.js +9 -3
  77. package/dist/ws/client.browser.js.map +1 -1
  78. package/dist/ws/client.node.d.ts +2 -1
  79. package/dist/ws/client.node.d.ts.map +1 -1
  80. package/dist/ws/client.node.js +9 -3
  81. package/dist/ws/client.node.js.map +1 -1
  82. package/dist/ws/index.d.ts +1 -1
  83. package/dist/ws/index.d.ts.map +1 -1
  84. package/dist/ws/index.js +9 -1
  85. package/dist/ws/index.js.map +1 -1
  86. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  import type { MarketEvent } from "../domain/market";
2
- import type { AuthUpdate, UserUpdate } from "../domain/order";
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";
@@ -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,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC9D,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,MAAM,SAAS,GACjB;IAAE,I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,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
- return parsed;
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
@@ -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;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I,CAAC,CAAC,SAAS,IAAI,GAAG,CAAC,IAAI,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC3D,MAAM,IAAI,eAAY,CAAC,eAAe,EAAE,wDAAwD,CAAC,CAAC;IACpG,CAAC;IACD,IAAI,CAAC,CAAC,MAAM,IAAI,GAAG,CAAC,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,IAAI,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,WAA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GAAG,CAAC,IAAI,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC3D,MAAM,IAAI,eAAY,CAAC,eAAe,EAAE,wDAAwD,CAAC,CAAC;IACpG,CAAC;IACD,IAAI,CAAC,CAAC,MAAM,IAAI,GAAG,CAAC,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,IAAI,GAAG,CAAC,IAAI,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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightconexyz/lightcone-sdk",
3
- "version": "0.4.15",
3
+ "version": "0.5.1",
4
4
  "description": "TypeScript SDK for Lightcone",
5
5
  "author": "Lightcone",
6
6
  "license": "MIT",