@lightconexyz/lightcone-sdk 0.2.2 → 0.2.4

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 (153) hide show
  1. package/README.md +25 -14
  2. package/dist/auth/client.d.ts.map +1 -1
  3. package/dist/auth/client.js +3 -7
  4. package/dist/auth/client.js.map +1 -1
  5. package/dist/auth/index.d.ts +3 -0
  6. package/dist/auth/index.d.ts.map +1 -1
  7. package/dist/auth/index.js.map +1 -1
  8. package/dist/client.d.ts +17 -5
  9. package/dist/client.d.ts.map +1 -1
  10. package/dist/client.js +36 -10
  11. package/dist/client.js.map +1 -1
  12. package/dist/context.d.ts +14 -0
  13. package/dist/context.d.ts.map +1 -0
  14. package/dist/context.js +10 -0
  15. package/dist/context.js.map +1 -0
  16. package/dist/domain/admin/client.d.ts +15 -5
  17. package/dist/domain/admin/client.d.ts.map +1 -1
  18. package/dist/domain/admin/client.js +39 -0
  19. package/dist/domain/admin/client.js.map +1 -1
  20. package/dist/domain/index.d.ts +0 -1
  21. package/dist/domain/index.d.ts.map +1 -1
  22. package/dist/domain/index.js +1 -2
  23. package/dist/domain/index.js.map +1 -1
  24. package/dist/domain/market/client.d.ts +11 -5
  25. package/dist/domain/market/client.d.ts.map +1 -1
  26. package/dist/domain/market/client.js +76 -0
  27. package/dist/domain/market/client.js.map +1 -1
  28. package/dist/domain/order/client.d.ts +21 -5
  29. package/dist/domain/order/client.d.ts.map +1 -1
  30. package/dist/domain/order/client.js +89 -0
  31. package/dist/domain/order/client.js.map +1 -1
  32. package/dist/domain/order/index.d.ts +8 -2
  33. package/dist/domain/order/index.d.ts.map +1 -1
  34. package/dist/domain/order/index.js +23 -0
  35. package/dist/domain/order/index.js.map +1 -1
  36. package/dist/domain/orderbook/client.d.ts +7 -12
  37. package/dist/domain/orderbook/client.d.ts.map +1 -1
  38. package/dist/domain/orderbook/client.js +24 -4
  39. package/dist/domain/orderbook/client.js.map +1 -1
  40. package/dist/domain/orderbook/state.d.ts +2 -0
  41. package/dist/domain/orderbook/state.d.ts.map +1 -1
  42. package/dist/domain/orderbook/state.js +25 -2
  43. package/dist/domain/orderbook/state.js.map +1 -1
  44. package/dist/domain/position/client.d.ts +11 -5
  45. package/dist/domain/position/client.d.ts.map +1 -1
  46. package/dist/domain/position/client.js +38 -0
  47. package/dist/domain/position/client.js.map +1 -1
  48. package/dist/domain/position/index.d.ts +4 -1
  49. package/dist/domain/position/index.d.ts.map +1 -1
  50. package/dist/domain/position/index.js +20 -0
  51. package/dist/domain/position/index.js.map +1 -1
  52. package/dist/domain/position/wire.d.ts +6 -0
  53. package/dist/domain/position/wire.d.ts.map +1 -1
  54. package/dist/domain/position/wire.js.map +1 -1
  55. package/dist/domain/price_history/client.d.ts +25 -3
  56. package/dist/domain/price_history/client.d.ts.map +1 -1
  57. package/dist/domain/price_history/client.js +95 -6
  58. package/dist/domain/price_history/client.js.map +1 -1
  59. package/dist/domain/price_history/index.d.ts +4 -0
  60. package/dist/domain/price_history/index.d.ts.map +1 -1
  61. package/dist/domain/price_history/index.js.map +1 -1
  62. package/dist/domain/price_history/state.d.ts +16 -0
  63. package/dist/domain/price_history/state.d.ts.map +1 -1
  64. package/dist/domain/price_history/state.js +42 -1
  65. package/dist/domain/price_history/state.js.map +1 -1
  66. package/dist/domain/price_history/wire.d.ts +51 -21
  67. package/dist/domain/price_history/wire.d.ts.map +1 -1
  68. package/dist/domain/price_history/wire.js.map +1 -1
  69. package/dist/http/client.d.ts.map +1 -1
  70. package/dist/http/client.js +17 -36
  71. package/dist/http/client.js.map +1 -1
  72. package/dist/index.d.ts +4 -1
  73. package/dist/index.d.ts.map +1 -1
  74. package/dist/index.js +5 -1
  75. package/dist/index.js.map +1 -1
  76. package/dist/prelude.d.ts +5 -6
  77. package/dist/prelude.d.ts.map +1 -1
  78. package/dist/prelude.js +4 -5
  79. package/dist/prelude.js.map +1 -1
  80. package/dist/privy/client.d.ts +1 -0
  81. package/dist/privy/client.d.ts.map +1 -1
  82. package/dist/privy/client.js +10 -0
  83. package/dist/privy/client.js.map +1 -1
  84. package/dist/program/accounts.d.ts +2 -1
  85. package/dist/program/accounts.d.ts.map +1 -1
  86. package/dist/program/accounts.js +2 -1
  87. package/dist/program/accounts.js.map +1 -1
  88. package/dist/program/index.d.ts +1 -2
  89. package/dist/program/index.d.ts.map +1 -1
  90. package/dist/program/index.js +8 -6
  91. package/dist/program/index.js.map +1 -1
  92. package/dist/program/instructions.d.ts +1 -1
  93. package/dist/program/instructions.d.ts.map +1 -1
  94. package/dist/program/instructions.js +3 -3
  95. package/dist/program/instructions.js.map +1 -1
  96. package/dist/program/orders.d.ts +13 -1
  97. package/dist/program/orders.d.ts.map +1 -1
  98. package/dist/program/orders.js +53 -3
  99. package/dist/program/orders.js.map +1 -1
  100. package/dist/rpc.d.ts +19 -0
  101. package/dist/rpc.d.ts.map +1 -0
  102. package/dist/rpc.js +51 -0
  103. package/dist/rpc.js.map +1 -0
  104. package/dist/shared/fmt/decimal.d.ts +1 -1
  105. package/dist/shared/fmt/decimal.d.ts.map +1 -1
  106. package/dist/shared/fmt/decimal.js +2 -2
  107. package/dist/shared/fmt/decimal.js.map +1 -1
  108. package/dist/shared/index.d.ts +1 -1
  109. package/dist/shared/index.d.ts.map +1 -1
  110. package/dist/shared/index.js +2 -1
  111. package/dist/shared/index.js.map +1 -1
  112. package/dist/shared/scaling.d.ts.map +1 -1
  113. package/dist/shared/scaling.js +7 -3
  114. package/dist/shared/scaling.js.map +1 -1
  115. package/dist/shared/types.d.ts +1 -0
  116. package/dist/shared/types.d.ts.map +1 -1
  117. package/dist/shared/types.js +9 -1
  118. package/dist/shared/types.js.map +1 -1
  119. package/dist/ws/client.browser.d.ts +2 -0
  120. package/dist/ws/client.browser.d.ts.map +1 -1
  121. package/dist/ws/client.browser.js +43 -6
  122. package/dist/ws/client.browser.js.map +1 -1
  123. package/dist/ws/client.node.d.ts +2 -0
  124. package/dist/ws/client.node.d.ts.map +1 -1
  125. package/dist/ws/client.node.js +43 -6
  126. package/dist/ws/client.node.js.map +1 -1
  127. package/dist/ws/index.d.ts +1 -2
  128. package/dist/ws/index.d.ts.map +1 -1
  129. package/dist/ws/index.js.map +1 -1
  130. package/dist/ws/types.d.ts +2 -0
  131. package/dist/ws/types.d.ts.map +1 -1
  132. package/dist/ws/types.js.map +1 -1
  133. package/package.json +1 -1
  134. package/dist/domain/deposit_price/client.d.ts +0 -13
  135. package/dist/domain/deposit_price/client.d.ts.map +0 -1
  136. package/dist/domain/deposit_price/client.js +0 -28
  137. package/dist/domain/deposit_price/client.js.map +0 -1
  138. package/dist/domain/deposit_price/index.d.ts +0 -9
  139. package/dist/domain/deposit_price/index.d.ts.map +0 -1
  140. package/dist/domain/deposit_price/index.js +0 -20
  141. package/dist/domain/deposit_price/index.js.map +0 -1
  142. package/dist/domain/deposit_price/state.d.ts +0 -17
  143. package/dist/domain/deposit_price/state.d.ts.map +0 -1
  144. package/dist/domain/deposit_price/state.js +0 -45
  145. package/dist/domain/deposit_price/state.js.map +0 -1
  146. package/dist/domain/deposit_price/wire.d.ts +0 -36
  147. package/dist/domain/deposit_price/wire.d.ts.map +0 -1
  148. package/dist/domain/deposit_price/wire.js +0 -3
  149. package/dist/domain/deposit_price/wire.js.map +0 -1
  150. package/dist/program/client.d.ts +0 -96
  151. package/dist/program/client.d.ts.map +0 -1
  152. package/dist/program/client.js +0 -372
  153. package/dist/program/client.js.map +0 -1
@@ -10,12 +10,18 @@ export interface GlobalDeposit {
10
10
  symbol: string;
11
11
  balance: string;
12
12
  }
13
+ export interface VaultBalance {
14
+ deposit_mint: string;
15
+ vault: string;
16
+ balance: string;
17
+ }
13
18
  export interface PositionEntry {
14
19
  id: number;
15
20
  position_pubkey: string;
16
21
  owner: string;
17
22
  market_pubkey: string;
18
23
  outcomes: OutcomeBalance[];
24
+ vault_balances?: VaultBalance[];
19
25
  created_at: string;
20
26
  updated_at: string;
21
27
  }
@@ -1 +1 @@
1
- {"version":3,"file":"wire.d.ts","sourceRoot":"","sources":["../../../src/domain/position/wire.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,aAAa;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,eAAe,EAAE,MAAM,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,cAAc,EAAE,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,aAAa,EAAE,CAAC;IAC3B,eAAe,EAAE,aAAa,EAAE,CAAC;IACjC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,aAAa,EAAE,CAAC;IAC3B,eAAe,EAAE,aAAa,EAAE,CAAC;IACjC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC"}
1
+ {"version":3,"file":"wire.d.ts","sourceRoot":"","sources":["../../../src/domain/position/wire.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,aAAa;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,YAAY;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,eAAe,EAAE,MAAM,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,cAAc,EAAE,CAAC;IAC3B,cAAc,CAAC,EAAE,YAAY,EAAE,CAAC;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,aAAa,EAAE,CAAC;IAC3B,eAAe,EAAE,aAAa,EAAE,CAAC;IACjC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,aAAa,EAAE,CAAC;IAC3B,eAAe,EAAE,aAAa,EAAE,CAAC;IACjC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC"}
@@ -1 +1 @@
1
- {"version":3,"file":"wire.js","sourceRoot":"","sources":["../../../src/domain/position/wire.ts"],"names":[],"mappings":"","sourcesContent":["export interface OutcomeBalance {\n outcome_index: number;\n conditional_token: string;\n balance: string;\n balance_idle: string;\n balance_on_book: string;\n}\n\nexport interface GlobalDeposit {\n deposit_mint: string;\n symbol: string;\n balance: string;\n}\n\nexport interface PositionEntry {\n id: number;\n position_pubkey: string;\n owner: string;\n market_pubkey: string;\n outcomes: OutcomeBalance[];\n created_at: string;\n updated_at: string;\n}\n\nexport interface PositionsResponse {\n owner: string;\n total_markets: number;\n positions: PositionEntry[];\n global_deposits: GlobalDeposit[];\n decimals: Record<string, number>;\n}\n\nexport interface MarketPositionsResponse {\n owner: string;\n market_pubkey: string;\n positions: PositionEntry[];\n global_deposits: GlobalDeposit[];\n decimals: Record<string, number>;\n}\n"]}
1
+ {"version":3,"file":"wire.js","sourceRoot":"","sources":["../../../src/domain/position/wire.ts"],"names":[],"mappings":"","sourcesContent":["export interface OutcomeBalance {\n outcome_index: number;\n conditional_token: string;\n balance: string;\n balance_idle: string;\n balance_on_book: string;\n}\n\nexport interface GlobalDeposit {\n deposit_mint: string;\n symbol: string;\n balance: string;\n}\n\nexport interface VaultBalance {\n deposit_mint: string;\n vault: string;\n balance: string;\n}\n\nexport interface PositionEntry {\n id: number;\n position_pubkey: string;\n owner: string;\n market_pubkey: string;\n outcomes: OutcomeBalance[];\n vault_balances?: VaultBalance[];\n created_at: string;\n updated_at: string;\n}\n\nexport interface PositionsResponse {\n owner: string;\n total_markets: number;\n positions: PositionEntry[];\n global_deposits: GlobalDeposit[];\n decimals: Record<string, number>;\n}\n\nexport interface MarketPositionsResponse {\n owner: string;\n market_pubkey: string;\n positions: PositionEntry[];\n global_deposits: GlobalDeposit[];\n decimals: Record<string, number>;\n}\n"]}
@@ -1,13 +1,35 @@
1
- import type { Resolution } from "../../shared";
1
+ import { Resolution } from "../../shared";
2
2
  import { type LightconeHttp } from "../../http";
3
- import type { PriceHistoryRestResponse } from "./wire";
3
+ import type { DepositTokenPriceHistoryResponse, OrderbookPriceHistoryResponse } from "./wire";
4
4
  interface ClientContext {
5
5
  http: LightconeHttp;
6
6
  }
7
+ export interface OrderbookPriceHistoryQuery {
8
+ resolution?: Resolution;
9
+ from?: number;
10
+ to?: number;
11
+ cursor?: number;
12
+ limit?: number;
13
+ includeOhlcv?: boolean;
14
+ }
15
+ export interface DepositPriceHistoryQuery {
16
+ resolution?: Resolution;
17
+ from?: number;
18
+ to?: number;
19
+ cursor?: number;
20
+ limit?: number;
21
+ }
7
22
  export declare class PriceHistoryClient {
8
23
  private readonly client;
9
24
  constructor(client: ClientContext);
10
- get(orderbookId: string, resolution: Resolution, from?: number, to?: number): Promise<PriceHistoryRestResponse>;
25
+ get(orderbookId: string, resolution?: Resolution, from?: number, to?: number): Promise<OrderbookPriceHistoryResponse>;
26
+ get(orderbookId: string, query?: OrderbookPriceHistoryQuery): Promise<OrderbookPriceHistoryResponse>;
27
+ getDepositAsset(depositAsset: string, resolution?: Resolution, from?: number, to?: number, cursor?: number, limit?: number): Promise<DepositTokenPriceHistoryResponse>;
28
+ getDepositAsset(depositAsset: string, query?: DepositPriceHistoryQuery): Promise<DepositTokenPriceHistoryResponse>;
29
+ getLineData(orderbookId: string, resolution?: Resolution, from?: number, to?: number, cursor?: number, limit?: number): Promise<{
30
+ time: number;
31
+ value: string;
32
+ }[]>;
11
33
  }
12
34
  export {};
13
35
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/domain/price_history/client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAe,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAC7D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,QAAQ,CAAC;AAEvD,UAAU,aAAa;IACrB,IAAI,EAAE,aAAa,CAAC;CACrB;AAED,qBAAa,kBAAkB;IACjB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,aAAa;IAG5C,GAAG,CACP,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,UAAU,EACtB,IAAI,CAA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UAAU,CAAC,EAAE,UAAU,EACvB,IAAI,CAAC,EAAE,MAAM,EACb,EAAE,CAAC,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,gCAAgC,CAAC;IAEtC,eAAe,CACnB,YAAY,EAAE,MAAM,EACpB,KAAK,CAAC,EAAE,wBAAwB,GAC/B,OAAO,CAAC,gCAAgC,CAAC;IAsCtC,WAAW,CACf,WAAW,EAAE,MAAM,EACnB,UAAU,GAAE,UAA+B,EAC3C,IAAI,CAAC,EAAE,MAAM,EACb,EAAE,CAAC,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAc9C"}
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PriceHistoryClient = void 0;
4
4
  const error_1 = require("../../error");
5
+ const shared_1 = require("../../shared");
5
6
  const http_1 = require("../../http");
6
7
  class PriceHistoryClient {
7
8
  client;
@@ -9,20 +10,102 @@ class PriceHistoryClient {
9
10
  this.client = client;
10
11
  }
11
12
  // `from`/`to` are Unix timestamps in milliseconds.
12
- async get(orderbookId, resolution, from, to) {
13
+ async get(orderbookId, resolutionOrQuery = shared_1.Resolution.Minute1, from, to) {
14
+ const query = normalizeOrderbookPriceHistoryQuery(resolutionOrQuery, from, to);
13
15
  const params = new URLSearchParams({
14
16
  orderbook_id: orderbookId,
15
- resolution,
17
+ resolution: query.resolution,
18
+ });
19
+ if (query.from !== undefined) {
20
+ params.set("from", String(ensureUnixMilliseconds("from", query.from)));
21
+ }
22
+ if (query.to !== undefined) {
23
+ params.set("to", String(ensureUnixMilliseconds("to", query.to)));
24
+ }
25
+ if (query.cursor !== undefined) {
26
+ params.set("cursor", String(ensureUnixMilliseconds("cursor", query.cursor)));
27
+ }
28
+ if (query.limit !== undefined) {
29
+ params.set("limit", String(ensurePageLimit(query.limit)));
30
+ }
31
+ if (query.includeOhlcv !== undefined) {
32
+ params.set("include_ohlcv", String(query.includeOhlcv));
33
+ }
34
+ const url = `${this.client.http.baseUrl()}/api/price-history?${params.toString()}`;
35
+ return this.client.http.get(url, http_1.RetryPolicy.Idempotent);
36
+ }
37
+ async getDepositAsset(depositAsset, resolutionOrQuery = shared_1.Resolution.Minute1, from, to, cursor, limit) {
38
+ const query = normalizeDepositPriceHistoryQuery(resolutionOrQuery, from, to, cursor, limit);
39
+ const params = new URLSearchParams({
40
+ deposit_asset: depositAsset,
41
+ resolution: query.resolution,
16
42
  });
17
- if (from !== undefined)
18
- params.set("from", String(ensureUnixMilliseconds("from", from)));
19
- if (to !== undefined)
20
- params.set("to", String(ensureUnixMilliseconds("to", to)));
43
+ if (query.from !== undefined) {
44
+ params.set("from", String(ensureUnixMilliseconds("from", query.from)));
45
+ }
46
+ if (query.to !== undefined) {
47
+ params.set("to", String(ensureUnixMilliseconds("to", query.to)));
48
+ }
49
+ if (query.cursor !== undefined) {
50
+ params.set("cursor", String(ensureUnixMilliseconds("cursor", query.cursor)));
51
+ }
52
+ if (query.limit !== undefined) {
53
+ params.set("limit", String(ensurePageLimit(query.limit)));
54
+ }
21
55
  const url = `${this.client.http.baseUrl()}/api/price-history?${params.toString()}`;
22
56
  return this.client.http.get(url, http_1.RetryPolicy.Idempotent);
23
57
  }
58
+ async getLineData(orderbookId, resolution = shared_1.Resolution.Minute1, from, to, cursor, limit) {
59
+ const response = await this.get(orderbookId, {
60
+ resolution,
61
+ from,
62
+ to,
63
+ cursor,
64
+ limit,
65
+ includeOhlcv: false,
66
+ });
67
+ return response.prices.map((c) => ({
68
+ time: c.t,
69
+ value: c.m ?? "",
70
+ }));
71
+ }
24
72
  }
25
73
  exports.PriceHistoryClient = PriceHistoryClient;
74
+ function normalizeOrderbookPriceHistoryQuery(resolutionOrQuery, from, to) {
75
+ if (typeof resolutionOrQuery === "string") {
76
+ return {
77
+ resolution: resolutionOrQuery,
78
+ from,
79
+ to,
80
+ };
81
+ }
82
+ return {
83
+ resolution: resolutionOrQuery.resolution ?? shared_1.Resolution.Minute1,
84
+ from: resolutionOrQuery.from,
85
+ to: resolutionOrQuery.to,
86
+ cursor: resolutionOrQuery.cursor,
87
+ limit: resolutionOrQuery.limit,
88
+ includeOhlcv: resolutionOrQuery.includeOhlcv,
89
+ };
90
+ }
91
+ function normalizeDepositPriceHistoryQuery(resolutionOrQuery, from, to, cursor, limit) {
92
+ if (typeof resolutionOrQuery === "string") {
93
+ return {
94
+ resolution: resolutionOrQuery,
95
+ from,
96
+ to,
97
+ cursor,
98
+ limit,
99
+ };
100
+ }
101
+ return {
102
+ resolution: resolutionOrQuery.resolution ?? shared_1.Resolution.Minute1,
103
+ from: resolutionOrQuery.from,
104
+ to: resolutionOrQuery.to,
105
+ cursor: resolutionOrQuery.cursor,
106
+ limit: resolutionOrQuery.limit,
107
+ };
108
+ }
26
109
  function ensureUnixMilliseconds(name, value) {
27
110
  if (!Number.isFinite(value) || !Number.isInteger(value) || value < 0) {
28
111
  throw error_1.SdkError.validation(`${name} must be a non-negative Unix timestamp in milliseconds`);
@@ -32,4 +115,10 @@ function ensureUnixMilliseconds(name, value) {
32
115
  }
33
116
  return value;
34
117
  }
118
+ function ensurePageLimit(value) {
119
+ if (!Number.isFinite(value) || !Number.isInteger(value) || value < 1 || value > 1_000) {
120
+ throw error_1.SdkError.validation("limit must be an integer between 1 and 1000");
121
+ }
122
+ return value;
123
+ }
35
124
  //# sourceMappingURL=client.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/domain/price_history/client.ts"],"names":[],"mappings":";;;AAAA,uCAAuC;AAEvC,qCAA6D;AAO7D,MAAa,kBAAkB;IACA;IAA7B,YAA6B,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;IAAG,CAAC;IAEtD,mDAAmD;IACnD,KAAK,CAAC,GAAG,CACP,WAAmB,EACnB,UAAsB,EACtB,IAAa,EACb,EAAW;QAEX,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC;YACjC,YAAY,EAAE,WAAW;YACzB,UAAU;SACX,CAAC,CAAC;QACH,IAAI,IAAI,KAAK,SAAS;YAAE,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,sBAAsB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;QACzF,IAAI,EAAE,KAAK,SAAS;YAAE,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,sBAAsB,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;QAEjF,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,sBAAsB,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC;QACnF,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAA2B,GAAG,EAAE,kBAAW,CAAC,UAAU,CAAC,CAAC;IACrF,CAAC;CACF;AApBD,gDAoBC;AAED,SAAS,sBAAsB,CAAC,IAAY,EAAE,KAAa;IACzD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACrE,MAAM,gBAAQ,CAAC,UAAU,CAAC,GAAG,IAAI,wDAAwD,CAAC,CAAC;IAC7F,CAAC;IACD,IAAI,KAAK,GAAG,cAAc,EAAE,CAAC;QAC3B,MAAM,gBAAQ,CAAC,UAAU,CAAC,GAAG,IAAI,wDAAwD,CAAC,CAAC;IAC7F,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { SdkError } from \"../../error\";\nimport type { Resolution } from \"../../shared\";\nimport { RetryPolicy, type LightconeHttp } from \"../../http\";\nimport type { PriceHistoryRestResponse } from \"./wire\";\n\ninterface ClientContext {\n http: LightconeHttp;\n}\n\nexport class PriceHistoryClient {\n constructor(private readonly client: ClientContext) {}\n\n // `from`/`to` are Unix timestamps in milliseconds.\n async get(\n orderbookId: string,\n resolution: Resolution,\n from?: number,\n to?: number\n ): Promise<PriceHistoryRestResponse> {\n const params = new URLSearchParams({\n orderbook_id: orderbookId,\n resolution,\n });\n if (from !== undefined) params.set(\"from\", String(ensureUnixMilliseconds(\"from\", from)));\n if (to !== undefined) params.set(\"to\", String(ensureUnixMilliseconds(\"to\", to)));\n\n const url = `${this.client.http.baseUrl()}/api/price-history?${params.toString()}`;\n return this.client.http.get<PriceHistoryRestResponse>(url, RetryPolicy.Idempotent);\n }\n}\n\nfunction ensureUnixMilliseconds(name: string, value: number): number {\n if (!Number.isFinite(value) || !Number.isInteger(value) || value < 0) {\n throw SdkError.validation(`${name} must be a non-negative Unix timestamp in milliseconds`);\n }\n if (value < 10_000_000_000) {\n throw SdkError.validation(`${name} must be a Unix timestamp in milliseconds, not seconds`);\n }\n return value;\n}\n"]}
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/domain/price_history/client.ts"],"names":[],"mappings":";;;AAAA,uCAAuC;AACvC,yCAA0C;AAC1C,qCAA6D;AA4B7D,MAAa,kBAAkB;IACA;IAA7B,YAA6B,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;IAAG,CAAC;IActD,mDAAmD;IACnD,KAAK,CAAC,GAAG,CACP,WAAmB,EACnB,oBAA6D,mBAAU,CAAC,OAAO,EAC/E,IAAa,EACb,EAAW;QAEX,MAAM,KAAK,GAAG,mCAAmC,CAAC,iBAAiB,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;QAC/E,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC;YACjC,YAAY,EAAE,WAAW;YACzB,UAAU,EAAE,KAAK,CAAC,UAAU;SAC7B,CAAC,CAAC;QACH,IAAI,KAAK,CAAC,IAAI,KAAK,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AE,iBAAiB,CAAC,UAAU,IAAI,mBAAU,CAAC,OAAO;QAC9D,IAAI,EAAE,iBAAiB,CAAC,IAAI;QAC5B,EAAE,EAAE,iBAAiB,CAAC,EAAE;QACxB,MAAM,EAAE,iBAAiB,CAAC,MAAM;QAChC,KAAK,EAAE,iBAAiB,CAAC,KAAK;KAC/B,CAAC;AACJ,CAAC;AAED,SAAS,sBAAsB,CAAC,IAAY,EAAE,KAAa;IACzD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACrE,MAAM,gBAAQ,CAAC,UAAU,CAAC,GAAG,IAAI,wDAAwD,CAAC,CAAC;IAC7F,CAAC;IACD,IAAI,KAAK,GAAG,cAAc,EAAE,CAAC;QAC3B,MAAM,gBAAQ,CAAC,UAAU,CAAC,GAAG,IAAI,wDAAwD,CAAC,CAAC;IAC7F,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,eAAe,CAAC,KAAa;IACpC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,KAAK,EAAE,CAAC;QACtF,MAAM,gBAAQ,CAAC,UAAU,CAAC,6CAA6C,CAAC,CAAC;IAC3E,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { SdkError } from \"../../error\";\nimport { Resolution } from \"../../shared\";\nimport { RetryPolicy, type LightconeHttp } from \"../../http\";\nimport type {\n DepositTokenPriceHistoryResponse,\n OrderbookPriceHistoryResponse,\n PriceCandle,\n} from \"./wire\";\n\ninterface ClientContext {\n http: LightconeHttp;\n}\n\nexport interface OrderbookPriceHistoryQuery {\n resolution?: Resolution;\n from?: number;\n to?: number;\n cursor?: number;\n limit?: number;\n includeOhlcv?: boolean;\n}\n\nexport interface DepositPriceHistoryQuery {\n resolution?: Resolution;\n from?: number;\n to?: number;\n cursor?: number;\n limit?: number;\n}\n\nexport class PriceHistoryClient {\n constructor(private readonly client: ClientContext) {}\n\n async get(\n orderbookId: string,\n resolution?: Resolution,\n from?: number,\n to?: number\n ): Promise<OrderbookPriceHistoryResponse>;\n\n async get(\n orderbookId: string,\n query?: OrderbookPriceHistoryQuery\n ): Promise<OrderbookPriceHistoryResponse>;\n\n // `from`/`to` are Unix timestamps in milliseconds.\n async get(\n orderbookId: string,\n resolutionOrQuery: Resolution | OrderbookPriceHistoryQuery = Resolution.Minute1,\n from?: number,\n to?: number\n ): Promise<OrderbookPriceHistoryResponse> {\n const query = normalizeOrderbookPriceHistoryQuery(resolutionOrQuery, from, to);\n const params = new URLSearchParams({\n orderbook_id: orderbookId,\n resolution: query.resolution,\n });\n if (query.from !== undefined) {\n params.set(\"from\", String(ensureUnixMilliseconds(\"from\", query.from)));\n }\n if (query.to !== undefined) {\n params.set(\"to\", String(ensureUnixMilliseconds(\"to\", query.to)));\n }\n if (query.cursor !== undefined) {\n params.set(\"cursor\", String(ensureUnixMilliseconds(\"cursor\", query.cursor)));\n }\n if (query.limit !== undefined) {\n params.set(\"limit\", String(ensurePageLimit(query.limit)));\n }\n if (query.includeOhlcv !== undefined) {\n params.set(\"include_ohlcv\", String(query.includeOhlcv));\n }\n\n const url = `${this.client.http.baseUrl()}/api/price-history?${params.toString()}`;\n return this.client.http.get<OrderbookPriceHistoryResponse>(url, RetryPolicy.Idempotent);\n }\n\n async getDepositAsset(\n depositAsset: string,\n resolution?: Resolution,\n from?: number,\n to?: number,\n cursor?: number,\n limit?: number\n ): Promise<DepositTokenPriceHistoryResponse>;\n\n async getDepositAsset(\n depositAsset: string,\n query?: DepositPriceHistoryQuery\n ): Promise<DepositTokenPriceHistoryResponse>;\n\n async getDepositAsset(\n depositAsset: string,\n resolutionOrQuery: Resolution | DepositPriceHistoryQuery = Resolution.Minute1,\n from?: number,\n to?: number,\n cursor?: number,\n limit?: number\n ): Promise<DepositTokenPriceHistoryResponse> {\n const query = normalizeDepositPriceHistoryQuery(\n resolutionOrQuery,\n from,\n to,\n cursor,\n limit\n );\n const params = new URLSearchParams({\n deposit_asset: depositAsset,\n resolution: query.resolution,\n });\n if (query.from !== undefined) {\n params.set(\"from\", String(ensureUnixMilliseconds(\"from\", query.from)));\n }\n if (query.to !== undefined) {\n params.set(\"to\", String(ensureUnixMilliseconds(\"to\", query.to)));\n }\n if (query.cursor !== undefined) {\n params.set(\"cursor\", String(ensureUnixMilliseconds(\"cursor\", query.cursor)));\n }\n if (query.limit !== undefined) {\n params.set(\"limit\", String(ensurePageLimit(query.limit)));\n }\n\n const url = `${this.client.http.baseUrl()}/api/price-history?${params.toString()}`;\n return this.client.http.get<DepositTokenPriceHistoryResponse>(url, RetryPolicy.Idempotent);\n }\n\n async getLineData(\n orderbookId: string,\n resolution: Resolution = Resolution.Minute1,\n from?: number,\n to?: number,\n cursor?: number,\n limit?: number\n ): Promise<{ time: number; value: string }[]> {\n const response = await this.get(orderbookId, {\n resolution,\n from,\n to,\n cursor,\n limit,\n includeOhlcv: false,\n });\n return response.prices.map((c: PriceCandle) => ({\n time: c.t,\n value: c.m ?? \"\",\n }));\n }\n}\n\nfunction normalizeOrderbookPriceHistoryQuery(\n resolutionOrQuery: Resolution | OrderbookPriceHistoryQuery,\n from?: number,\n to?: number\n): Required<Pick<OrderbookPriceHistoryQuery, \"resolution\">> & Omit<OrderbookPriceHistoryQuery, \"resolution\"> {\n if (typeof resolutionOrQuery === \"string\") {\n return {\n resolution: resolutionOrQuery,\n from,\n to,\n };\n }\n\n return {\n resolution: resolutionOrQuery.resolution ?? Resolution.Minute1,\n from: resolutionOrQuery.from,\n to: resolutionOrQuery.to,\n cursor: resolutionOrQuery.cursor,\n limit: resolutionOrQuery.limit,\n includeOhlcv: resolutionOrQuery.includeOhlcv,\n };\n}\n\nfunction normalizeDepositPriceHistoryQuery(\n resolutionOrQuery: Resolution | DepositPriceHistoryQuery,\n from?: number,\n to?: number,\n cursor?: number,\n limit?: number\n): Required<Pick<DepositPriceHistoryQuery, \"resolution\">> & Omit<DepositPriceHistoryQuery, \"resolution\"> {\n if (typeof resolutionOrQuery === \"string\") {\n return {\n resolution: resolutionOrQuery,\n from,\n to,\n cursor,\n limit,\n };\n }\n\n return {\n resolution: resolutionOrQuery.resolution ?? Resolution.Minute1,\n from: resolutionOrQuery.from,\n to: resolutionOrQuery.to,\n cursor: resolutionOrQuery.cursor,\n limit: resolutionOrQuery.limit,\n };\n}\n\nfunction ensureUnixMilliseconds(name: string, value: number): number {\n if (!Number.isFinite(value) || !Number.isInteger(value) || value < 0) {\n throw SdkError.validation(`${name} must be a non-negative Unix timestamp in milliseconds`);\n }\n if (value < 10_000_000_000) {\n throw SdkError.validation(`${name} must be a Unix timestamp in milliseconds, not seconds`);\n }\n return value;\n}\n\nfunction ensurePageLimit(value: number): number {\n if (!Number.isFinite(value) || !Number.isInteger(value) || value < 1 || value > 1_000) {\n throw SdkError.validation(\"limit must be an integer between 1 and 1000\");\n }\n return value;\n}\n"]}
@@ -11,4 +11,8 @@ export interface PriceHistoryKey {
11
11
  orderbookId: OrderBookId;
12
12
  resolution: Resolution;
13
13
  }
14
+ export interface DepositPriceKey {
15
+ depositAsset: string;
16
+ resolution: Resolution;
17
+ }
14
18
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/domain/price_history/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE5D,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AAEvB,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,QAAQ,EAAE,WAAW,GAAG,QAAQ,CAKjF;AAED,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,WAAW,CAAC;IACzB,UAAU,EAAE,UAAU,CAAC;CACxB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/domain/price_history/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE5D,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AAEvB,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,QAAQ,EAAE,WAAW,GAAG,QAAQ,CAKjF;AAED,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,WAAW,CAAC;IACzB,UAAU,EAAE,UAAU,CAAC;CACxB;AAED,MAAM,WAAW,eAAe;IAC9B,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,UAAU,CAAC;CACxB"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/domain/price_history/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAWA,gDAKC;AAdD,2CAAyB;AACzB,0CAAwB;AACxB,yCAAuB;AAOvB,SAAgB,kBAAkB,CAAC,MAAoC;IACrE,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,CAAC;QACd,KAAK,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE;KACtB,CAAC;AACJ,CAAC","sourcesContent":["import type { OrderBookId, Resolution } from \"../../shared\";\n\nexport * from \"./client\";\nexport * from \"./state\";\nexport * from \"./wire\";\n\nexport interface LineData {\n time: number;\n value: string;\n}\n\nexport function lineDataFromCandle(candle: import(\"./wire\").PriceCandle): LineData {\n return {\n time: candle.t,\n value: candle.m ?? \"\",\n };\n}\n\nexport interface PriceHistoryKey {\n orderbookId: OrderBookId;\n resolution: Resolution;\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/domain/price_history/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAWA,gDAKC;AAdD,2CAAyB;AACzB,0CAAwB;AACxB,yCAAuB;AAOvB,SAAgB,kBAAkB,CAAC,MAAoC;IACrE,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,CAAC;QACd,KAAK,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE;KACtB,CAAC;AACJ,CAAC","sourcesContent":["import type { OrderBookId, Resolution } from \"../../shared\";\n\nexport * from \"./client\";\nexport * from \"./state\";\nexport * from \"./wire\";\n\nexport interface LineData {\n time: number;\n value: string;\n}\n\nexport function lineDataFromCandle(candle: import(\"./wire\").PriceCandle): LineData {\n return {\n time: candle.t,\n value: candle.m ?? \"\",\n };\n}\n\nexport interface PriceHistoryKey {\n orderbookId: OrderBookId;\n resolution: Resolution;\n}\n\nexport interface DepositPriceKey {\n depositAsset: string;\n resolution: Resolution;\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  import type { OrderBookId, Resolution } from "../../shared";
2
2
  import type { LineData } from "./index";
3
+ import type { DepositTokenCandle } from "./wire";
3
4
  export declare class PriceHistoryState {
4
5
  private readonly data;
5
6
  constructor();
@@ -8,4 +9,19 @@ export declare class PriceHistoryState {
8
9
  get(orderbookId: OrderBookId, resolution: Resolution): readonly LineData[] | undefined;
9
10
  clear(): void;
10
11
  }
12
+ export interface LatestDepositPrice {
13
+ price: string;
14
+ eventTime: number;
15
+ }
16
+ export declare class DepositPriceState {
17
+ private readonly candles;
18
+ private readonly latestPrice;
19
+ constructor();
20
+ applySnapshot(depositAsset: string, resolution: Resolution, prices: DepositTokenCandle[]): void;
21
+ applyCandleUpdate(depositAsset: string, resolution: Resolution, candle: DepositTokenCandle): void;
22
+ applyPriceTick(depositAsset: string, price: string, eventTime: number): void;
23
+ getCandles(depositAsset: string, resolution: Resolution): readonly DepositTokenCandle[] | undefined;
24
+ getLatestPrice(depositAsset: string): LatestDepositPrice | undefined;
25
+ clear(): void;
26
+ }
11
27
  //# sourceMappingURL=state.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/domain/price_history/state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA0B;;IAM/C,aAAa,CAAC,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI;IAIzF,WAAW,CAAC,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,GAAG,IAAI;IAepF,GAAG,CAAC,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,GAAG,SAAS,QAAQ,EAAE,GAAG,SAAS;IAItF,KAAK,IAAI,IAAI;CAGd"}
1
+ {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/domain/price_history/state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AAEjD,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA0B;;IAM/C,aAAa,CAAC,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI;IAIzF,WAAW,CAAC,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,GAAG,IAAI;IAepF,GAAG,CAAC,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,GAAG,SAAS,QAAQ,EAAE,GAAG,SAAS;IAItF,KAAK,IAAI,IAAI;CAGd;AAMD,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoC;IAC5D,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAkC;;IAO9D,aAAa,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,kBAAkB,EAAE,GAAG,IAAI;IAI/F,iBAAiB,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,kBAAkB,GAAG,IAAI;IAgBjG,cAAc,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI;IAI5E,UAAU,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,SAAS,kBAAkB,EAAE,GAAG,SAAS;IAInG,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS;IAIpE,KAAK,IAAI,IAAI;CAId"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PriceHistoryState = void 0;
3
+ exports.DepositPriceState = exports.PriceHistoryState = void 0;
4
4
  class PriceHistoryState {
5
5
  data;
6
6
  constructor() {
@@ -32,4 +32,45 @@ exports.PriceHistoryState = PriceHistoryState;
32
32
  function keyFor(orderbookId, resolution) {
33
33
  return `${orderbookId}:${resolution}`;
34
34
  }
35
+ class DepositPriceState {
36
+ candles;
37
+ latestPrice;
38
+ constructor() {
39
+ this.candles = new Map();
40
+ this.latestPrice = new Map();
41
+ }
42
+ applySnapshot(depositAsset, resolution, prices) {
43
+ this.candles.set(depositKeyFor(depositAsset, resolution), prices);
44
+ }
45
+ applyCandleUpdate(depositAsset, resolution, candle) {
46
+ const key = depositKeyFor(depositAsset, resolution);
47
+ const existing = this.candles.get(key) ?? [];
48
+ const last = existing.at(-1);
49
+ if (last && last.t === candle.t) {
50
+ last.c = candle.c;
51
+ last.tc = candle.tc;
52
+ this.candles.set(key, existing);
53
+ return;
54
+ }
55
+ existing.push(candle);
56
+ this.candles.set(key, existing);
57
+ }
58
+ applyPriceTick(depositAsset, price, eventTime) {
59
+ this.latestPrice.set(depositAsset, { price, eventTime });
60
+ }
61
+ getCandles(depositAsset, resolution) {
62
+ return this.candles.get(depositKeyFor(depositAsset, resolution));
63
+ }
64
+ getLatestPrice(depositAsset) {
65
+ return this.latestPrice.get(depositAsset);
66
+ }
67
+ clear() {
68
+ this.candles.clear();
69
+ this.latestPrice.clear();
70
+ }
71
+ }
72
+ exports.DepositPriceState = DepositPriceState;
73
+ function depositKeyFor(depositAsset, resolution) {
74
+ return `${depositAsset}:${resolution}`;
75
+ }
35
76
  //# sourceMappingURL=state.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"state.js","sourceRoot":"","sources":["../../../src/domain/price_history/state.ts"],"names":[],"mappings":";;;AAGA,MAAa,iBAAiB;IACX,IAAI,CAA0B;IAE/C;QACE,IAAI,CAAC,IAAI,GAAG,IAAI,GAAG,EAAE,CAAC;IACxB,CAAC;IAED,aAAa,CAAC,WAAwB,EAAE,UAAsB,EAAE,MAAkB;QAChF,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,WAAW,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,CAAC;IACzD,CAAC;IAED,WAAW,CAAC,WAAwB,EAAE,UAAsB,EAAE,KAAe;QAC3E,MAAM,GAAG,GAAG,MAAM,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;QAC5C,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;QAE1C,MAAM,IAAI,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7B,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,EAAE,CAAC;YACrC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;YACzB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;YAC7B,OAAO;QACT,CAAC;QAED,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACrB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IAC/B,CAAC;IAED,GAAG,CAAC,WAAwB,EAAE,UAAsB;QAClD,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC;IACxD,CAAC;IAED,KAAK;QACH,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC;CACF;AAjCD,8CAiCC;AAED,SAAS,MAAM,CAAC,WAAwB,EAAE,UAAsB;IAC9D,OAAO,GAAG,WAAW,IAAI,UAAU,EAAE,CAAC;AACxC,CAAC","sourcesContent":["import type { OrderBookId, Resolution } from \"../../shared\";\nimport type { LineData } from \"./index\";\n\nexport class PriceHistoryState {\n private readonly data: Map<string, LineData[]>;\n\n constructor() {\n this.data = new Map();\n }\n\n applySnapshot(orderbookId: OrderBookId, resolution: Resolution, prices: LineData[]): void {\n this.data.set(keyFor(orderbookId, resolution), prices);\n }\n\n applyUpdate(orderbookId: OrderBookId, resolution: Resolution, point: LineData): void {\n const key = keyFor(orderbookId, resolution);\n const existing = this.data.get(key) ?? [];\n\n const last = existing.at(-1);\n if (last && last.time === point.time) {\n last.value = point.value;\n this.data.set(key, existing);\n return;\n }\n\n existing.push(point);\n this.data.set(key, existing);\n }\n\n get(orderbookId: OrderBookId, resolution: Resolution): readonly LineData[] | undefined {\n return this.data.get(keyFor(orderbookId, resolution));\n }\n\n clear(): void {\n this.data.clear();\n }\n}\n\nfunction keyFor(orderbookId: OrderBookId, resolution: Resolution): string {\n return `${orderbookId}:${resolution}`;\n}\n"]}
1
+ {"version":3,"file":"state.js","sourceRoot":"","sources":["../../../src/domain/price_history/state.ts"],"names":[],"mappings":";;;AAIA,MAAa,iBAAiB;IACX,IAAI,CAA0B;IAE/C;QACE,IAAI,CAAC,IAAI,GAAG,IAAI,GAAG,EAAE,CAAC;IACxB,CAAC;IAED,aAAa,CAAC,WAAwB,EAAE,UAAsB,EAAE,MAAkB;QAChF,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,WAAW,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,CAAC;IACzD,CAAC;IAED,WAAW,CAAC,WAAwB,EAAE,UAAsB,EAAE,KAAe;QAC3E,MAAM,GAAG,GAAG,MAAM,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;QAC5C,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;QAE1C,MAAM,IAAI,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7B,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,EAAE,CAAC;YACrC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;YACzB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;YAC7B,OAAO;QACT,CAAC;QAED,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACrB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CA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AE,QAAQ,CAAC,CAAC;YAChC,OAAO;QACT,CAAC;QAED,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACtB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IAClC,CAAC;IAED,cAAc,CAAC,YAAoB,EAAE,KAAa,EAAE,SAAiB;QACnE,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,YAAY,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;IAC3D,CAAC;IAED,UAAU,CAAC,YAAoB,EAAE,UAAsB;QACrD,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC,CAAC;IACnE,CAAC;IAED,cAAc,CAAC,YAAoB;QACjC,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IAC5C,CAAC;IAED,KAAK;QACH,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACrB,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;IAC3B,CAAC;CACF;AA7CD,8CA6CC;AAED,SAAS,aAAa,CAAC,YAAoB,EAAE,UAAsB;IACjE,OAAO,GAAG,YAAY,IAAI,UAAU,EAAE,CAAC;AACzC,CAAC","sourcesContent":["import type { OrderBookId, Resolution } from \"../../shared\";\nimport type { LineData } from \"./index\";\nimport type { DepositTokenCandle } from \"./wire\";\n\nexport class PriceHistoryState {\n private readonly data: Map<string, LineData[]>;\n\n constructor() {\n this.data = new Map();\n }\n\n applySnapshot(orderbookId: OrderBookId, resolution: Resolution, prices: LineData[]): void {\n this.data.set(keyFor(orderbookId, resolution), prices);\n }\n\n applyUpdate(orderbookId: OrderBookId, resolution: Resolution, point: LineData): void {\n const key = keyFor(orderbookId, resolution);\n const existing = this.data.get(key) ?? [];\n\n const last = existing.at(-1);\n if (last && last.time === point.time) {\n last.value = point.value;\n this.data.set(key, existing);\n return;\n }\n\n existing.push(point);\n this.data.set(key, existing);\n }\n\n get(orderbookId: OrderBookId, resolution: Resolution): readonly LineData[] | undefined {\n return this.data.get(keyFor(orderbookId, resolution));\n }\n\n clear(): void {\n this.data.clear();\n }\n}\n\nfunction keyFor(orderbookId: OrderBookId, resolution: Resolution): string {\n return `${orderbookId}:${resolution}`;\n}\n\nexport interface LatestDepositPrice {\n price: string;\n eventTime: number;\n}\n\nexport class DepositPriceState {\n private readonly candles: Map<string, DepositTokenCandle[]>;\n private readonly latestPrice: Map<string, LatestDepositPrice>;\n\n constructor() {\n this.candles = new Map();\n this.latestPrice = new Map();\n }\n\n applySnapshot(depositAsset: string, resolution: Resolution, prices: DepositTokenCandle[]): void {\n this.candles.set(depositKeyFor(depositAsset, resolution), prices);\n }\n\n applyCandleUpdate(depositAsset: string, resolution: Resolution, candle: DepositTokenCandle): void {\n const key = depositKeyFor(depositAsset, resolution);\n const existing = this.candles.get(key) ?? [];\n\n const last = existing.at(-1);\n if (last && last.t === candle.t) {\n last.c = candle.c;\n last.tc = candle.tc;\n this.candles.set(key, existing);\n return;\n }\n\n existing.push(candle);\n this.candles.set(key, existing);\n }\n\n applyPriceTick(depositAsset: string, price: string, eventTime: number): void {\n this.latestPrice.set(depositAsset, { price, eventTime });\n }\n\n getCandles(depositAsset: string, resolution: Resolution): readonly DepositTokenCandle[] | undefined {\n return this.candles.get(depositKeyFor(depositAsset, resolution));\n }\n\n getLatestPrice(depositAsset: string): LatestDepositPrice | undefined {\n return this.latestPrice.get(depositAsset);\n }\n\n clear(): void {\n this.candles.clear();\n this.latestPrice.clear();\n }\n}\n\nfunction depositKeyFor(depositAsset: string, resolution: Resolution): string {\n return `${depositAsset}:${resolution}`;\n}\n"]}
@@ -1,15 +1,18 @@
1
1
  import type { OrderBookId, Resolution } from "../../shared";
2
- export interface PriceCandle {
2
+ export interface MidpointPriceCandle {
3
3
  t: number;
4
- m?: string;
5
- o?: string;
6
- h?: string;
7
- l?: string;
8
- c?: string;
9
- v?: string;
10
- bb?: string;
11
- ba?: string;
4
+ m: string | null;
12
5
  }
6
+ export interface OhlcvPriceCandle extends MidpointPriceCandle {
7
+ o: string | null;
8
+ h: string | null;
9
+ l: string | null;
10
+ c: string | null;
11
+ v: string;
12
+ bb: string | null;
13
+ ba: string | null;
14
+ }
15
+ export type PriceCandle = MidpointPriceCandle | OhlcvPriceCandle;
13
16
  export interface PriceHistorySnapshot {
14
17
  orderbook_id: OrderBookId;
15
18
  resolution: Resolution;
@@ -42,11 +45,36 @@ export type PriceHistory = ({
42
45
  } & PriceHistoryUpdate) | ({
43
46
  event_type: "heartbeat";
44
47
  } & PriceHistoryHeartbeat);
45
- export interface PriceHistoryRestResponse {
48
+ export interface DepositTokenCandle {
49
+ t: number;
50
+ tc: number;
51
+ c: string;
52
+ }
53
+ export interface DepositPriceSnapshot {
54
+ event_type: "snapshot";
55
+ deposit_asset: string;
56
+ resolution: Resolution;
57
+ prices: DepositTokenCandle[];
58
+ }
59
+ export interface DepositPriceTick {
60
+ event_type: "price";
61
+ deposit_asset: string;
62
+ price: string;
63
+ event_time: number;
64
+ }
65
+ export interface DepositPriceCandleUpdate {
66
+ event_type: "candle";
67
+ deposit_asset: string;
68
+ resolution: Resolution;
69
+ t: number;
70
+ tc: number;
71
+ c: string;
72
+ }
73
+ export type DepositPrice = DepositPriceSnapshot | DepositPriceTick | DepositPriceCandleUpdate;
74
+ interface OrderbookPriceHistoryResponseBase<TCandle extends PriceCandle> {
46
75
  orderbook_id: string;
47
- resolution: string;
48
- include_ohlcv: boolean;
49
- prices: PriceCandle[];
76
+ resolution: Resolution;
77
+ prices: TCandle[];
50
78
  next_cursor: number | null;
51
79
  has_more: boolean;
52
80
  decimals: {
@@ -54,17 +82,19 @@ export interface PriceHistoryRestResponse {
54
82
  volume: number;
55
83
  };
56
84
  }
57
- export interface DepositPriceCandle {
58
- t: number;
59
- tc?: number;
60
- c: string;
61
- }
62
- export interface DepositPriceRestResponse {
85
+ export type OrderbookPriceHistoryResponse = (OrderbookPriceHistoryResponseBase<MidpointPriceCandle> & {
86
+ include_ohlcv: false;
87
+ }) | (OrderbookPriceHistoryResponseBase<OhlcvPriceCandle> & {
88
+ include_ohlcv: true;
89
+ });
90
+ export type PriceHistoryRestResponse = OrderbookPriceHistoryResponse;
91
+ export interface DepositTokenPriceHistoryResponse {
63
92
  deposit_asset: string;
64
93
  binance_symbol: string;
65
- resolution: string;
66
- prices: DepositPriceCandle[];
94
+ resolution: Resolution;
95
+ prices: DepositTokenCandle[];
67
96
  next_cursor: number | null;
68
97
  has_more: boolean;
69
98
  }
99
+ export {};
70
100
  //# sourceMappingURL=wire.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"wire.d.ts","sourceRoot":"","sources":["../../../src/domain/price_history/wire.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE5D,MAAM,WAAW,WAAW;IAC1B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,oBAAoB;IACnC,YAAY,EAAE,WAAW,CAAC;IAC1B,UAAU,EAAE,UAAU,CAAC;IACvB,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,kBAAkB;IACjC,YAAY,EAAE,WAAW,CAAC;IAC1B,UAAU,EAAE,UAAU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CAAC,OAAO,SAAS,WAAW;IACrE,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,UAAU,CAAC;IACvB,MAAM,EAAE,OAAO,EAAE,CAAC;IAClB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CAC7C;AAED,MAAM,MAAM,6BAA6B,GACrC,CAAC,iCAAiC,CAAC,mBAAmB,CAAC,GAAG;IAAE,aAAa,EAAE,KAAK,CAAA;CAAE,CAAC,GACnF,CAAC,iCAAiC,CAAC,gBAAgB,CAAC,GAAG;IAAE,aAAa,EAAE,IAAI,CAAA;CAAE,CAAC,CAAC;AAEpF,MAAM,MAAM,wBAAwB,GAAG,6BAA6B,CAAC;AAErE,MAAM,WAAW,gCAAgC;IAC/C,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,UAAU,CAAC;IACvB,MAAM,EAAE,kBAAkB,EAAE,CAAC;IAC7B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,QAAQ,EAAE,OAAO,CAAC;CACnB"}
@@ -1 +1 @@
1
- {"version":3,"file":"wire.js","sourceRoot":"","sources":["../../../src/domain/price_history/wire.ts"],"names":[],"mappings":"","sourcesContent":["import type { OrderBookId, Resolution } from \"../../shared\";\n\nexport interface PriceCandle {\n t: number;\n m?: string;\n o?: string;\n h?: string;\n l?: string;\n c?: string;\n v?: string;\n bb?: string;\n ba?: string;\n}\n\nexport interface PriceHistorySnapshot {\n orderbook_id: OrderBookId;\n resolution: Resolution;\n prices: PriceCandle[];\n last_timestamp?: number;\n server_time?: number;\n include_ohlcv?: boolean;\n}\n\nexport interface PriceHistoryUpdate {\n orderbook_id: OrderBookId;\n resolution: Resolution;\n t: number;\n m?: string;\n o?: string;\n h?: string;\n l?: string;\n c?: string;\n v?: string;\n bb?: string;\n ba?: string;\n}\n\nexport interface PriceHistoryHeartbeat {\n server_time: number;\n last_processed?: number;\n}\n\nexport type PriceHistory =\n | ({ event_type: \"snapshot\" } & PriceHistorySnapshot)\n | ({ event_type: \"update\" } & PriceHistoryUpdate)\n | ({ event_type: \"heartbeat\" } & PriceHistoryHeartbeat);\n\nexport interface PriceHistoryRestResponse {\n orderbook_id: string;\n resolution: string;\n include_ohlcv: boolean;\n prices: PriceCandle[];\n next_cursor: number | null;\n has_more: boolean;\n decimals: { price: number; volume: number };\n}\n\nexport interface DepositPriceCandle {\n t: number;\n tc?: number;\n c: string;\n}\n\nexport interface DepositPriceRestResponse {\n deposit_asset: string;\n binance_symbol: string;\n resolution: string;\n prices: DepositPriceCandle[];\n next_cursor: number | null;\n has_more: boolean;\n}\n"]}
1
+ {"version":3,"file":"wire.js","sourceRoot":"","sources":["../../../src/domain/price_history/wire.ts"],"names":[],"mappings":"","sourcesContent":["import type { OrderBookId, Resolution } from \"../../shared\";\n\nexport interface MidpointPriceCandle {\n t: number;\n m: string | null;\n}\n\nexport interface OhlcvPriceCandle extends MidpointPriceCandle {\n o: string | null;\n h: string | null;\n l: string | null;\n c: string | null;\n v: string;\n bb: string | null;\n ba: string | null;\n}\n\nexport type PriceCandle = MidpointPriceCandle | OhlcvPriceCandle;\n\nexport interface PriceHistorySnapshot {\n orderbook_id: OrderBookId;\n resolution: Resolution;\n prices: PriceCandle[];\n last_timestamp?: number;\n server_time?: number;\n include_ohlcv?: boolean;\n}\n\nexport interface PriceHistoryUpdate {\n orderbook_id: OrderBookId;\n resolution: Resolution;\n t: number;\n m?: string;\n o?: string;\n h?: string;\n l?: string;\n c?: string;\n v?: string;\n bb?: string;\n ba?: string;\n}\n\nexport interface PriceHistoryHeartbeat {\n server_time: number;\n last_processed?: number;\n}\n\nexport type PriceHistory =\n | ({ event_type: \"snapshot\" } & PriceHistorySnapshot)\n | ({ event_type: \"update\" } & PriceHistoryUpdate)\n | ({ event_type: \"heartbeat\" } & PriceHistoryHeartbeat);\n\nexport interface DepositTokenCandle {\n t: number;\n tc: number;\n c: string;\n}\n\nexport interface DepositPriceSnapshot {\n event_type: \"snapshot\";\n deposit_asset: string;\n resolution: Resolution;\n prices: DepositTokenCandle[];\n}\n\nexport interface DepositPriceTick {\n event_type: \"price\";\n deposit_asset: string;\n price: string;\n event_time: number;\n}\n\nexport interface DepositPriceCandleUpdate {\n event_type: \"candle\";\n deposit_asset: string;\n resolution: Resolution;\n t: number;\n tc: number;\n c: string;\n}\n\nexport type DepositPrice =\n | DepositPriceSnapshot\n | DepositPriceTick\n | DepositPriceCandleUpdate;\n\ninterface OrderbookPriceHistoryResponseBase<TCandle extends PriceCandle> {\n orderbook_id: string;\n resolution: Resolution;\n prices: TCandle[];\n next_cursor: number | null;\n has_more: boolean;\n decimals: { price: number; volume: number };\n}\n\nexport type OrderbookPriceHistoryResponse =\n | (OrderbookPriceHistoryResponseBase<MidpointPriceCandle> & { include_ohlcv: false })\n | (OrderbookPriceHistoryResponseBase<OhlcvPriceCandle> & { include_ohlcv: true });\n\nexport type PriceHistoryRestResponse = OrderbookPriceHistoryResponse;\n\nexport interface DepositTokenPriceHistoryResponse {\n deposit_asset: string;\n binance_symbol: string;\n resolution: Resolution;\n prices: DepositTokenCandle[];\n next_cursor: number | null;\n has_more: boolean;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/http/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAyC,KAAK,WAAW,EAAE,MAAM,SAAS,CAAC;AAElF,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAS;IAC3C,OAAO,CAAC,SAAS,CAAqB;gBAE1B,OAAO,EAAE,MAAM;IAI3B,OAAO,IAAI,MAAM;IAIX,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAItD,cAAc,IAAI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48
  lastError = error;
49
- const delay = error.variant === "RateLimited" && error.retryAfterMs !== undefined
50
- ? error.retryAfterMs
51
- : (0, retry_1.delayForAttempt)(config, attempt);
49
+ const delay = (0, retry_1.delayForAttempt)(config, attempt);
52
50
  await sleep(delay);
53
51
  }
54
52
  }
@@ -83,7 +81,7 @@ class LightconeHttp {
83
81
  headers,
84
82
  body: body ? JSON.stringify(body) : undefined,
85
83
  signal: controller.signal,
86
- credentials: "include",
84
+ ...(hasBrowserWindow() ? { credentials: "include" } : {}),
87
85
  });
88
86
  }
89
87
  catch (error) {
@@ -98,44 +96,27 @@ class LightconeHttp {
98
96
  }
99
97
  if (response.ok) {
100
98
  const text = await response.text();
101
- if (!text) {
102
- throw error_1.HttpError.request("Empty response body");
99
+ try {
100
+ return JSON.parse(text);
101
+ }
102
+ catch (e) {
103
+ throw error_1.HttpError.request(e instanceof Error ? e.message : "JSON parse failed");
103
104
  }
104
- return JSON.parse(text);
105
105
  }
106
106
  const bodyText = await response.text().catch(() => "");
107
- switch (response.status) {
108
- case 400:
109
- throw error_1.HttpError.badRequest(bodyText);
110
- case 401:
111
- throw error_1.HttpError.unauthorized();
112
- case 404:
113
- throw error_1.HttpError.notFound(bodyText);
114
- case 429:
115
- throw error_1.HttpError.rateLimited(parseRetryAfterMs(response.headers.get("retry-after")));
116
- default:
117
- if (response.status >= 500) {
118
- throw error_1.HttpError.serverError(response.status, bodyText);
119
- }
120
- throw error_1.HttpError.badRequest(bodyText || `HTTP ${response.status}`);
121
- }
107
+ const statusCode = response.status;
108
+ if (statusCode === 401)
109
+ throw error_1.HttpError.unauthorized();
110
+ if (statusCode === 404)
111
+ throw error_1.HttpError.notFound(bodyText);
112
+ if (statusCode === 429)
113
+ throw error_1.HttpError.rateLimited();
114
+ if (statusCode >= 400 && statusCode < 500)
115
+ throw error_1.HttpError.badRequest(bodyText);
116
+ throw error_1.HttpError.serverError(statusCode, bodyText);
122
117
  }
123
118
  }
124
119
  exports.LightconeHttp = LightconeHttp;
125
- function parseRetryAfterMs(header) {
126
- if (!header) {
127
- return undefined;
128
- }
129
- const seconds = Number.parseFloat(header);
130
- if (Number.isFinite(seconds) && seconds >= 0) {
131
- return Math.floor(seconds * 1000);
132
- }
133
- const retryDate = Date.parse(header);
134
- if (Number.isFinite(retryDate)) {
135
- return Math.max(0, retryDate - Date.now());
136
- }
137
- return undefined;
138
- }
139
120
  function sleep(ms) {
140
121
  return new Promise((resolve) => {
141
122
  setTimeout(resolve, ms);