@polymarket/clob-client 4.22.2 → 4.22.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 (52) hide show
  1. package/package.json +3 -3
  2. package/dist/client.d.ts +0 -105
  3. package/dist/client.js +0 -812
  4. package/dist/client.js.map +0 -1
  5. package/dist/config.d.ts +0 -12
  6. package/dist/config.js +0 -33
  7. package/dist/config.js.map +0 -1
  8. package/dist/constants.d.ts +0 -3
  9. package/dist/constants.js +0 -10
  10. package/dist/constants.js.map +0 -1
  11. package/dist/endpoints.d.ts +0 -47
  12. package/dist/endpoints.js +0 -60
  13. package/dist/endpoints.js.map +0 -1
  14. package/dist/errors.d.ts +0 -2
  15. package/dist/errors.js +0 -6
  16. package/dist/errors.js.map +0 -1
  17. package/dist/headers/index.d.ts +0 -7
  18. package/dist/headers/index.js +0 -45
  19. package/dist/headers/index.js.map +0 -1
  20. package/dist/http-helpers/index.d.ts +0 -18
  21. package/dist/http-helpers/index.js +0 -116
  22. package/dist/http-helpers/index.js.map +0 -1
  23. package/dist/index.d.ts +0 -5
  24. package/dist/index.js +0 -9
  25. package/dist/index.js.map +0 -1
  26. package/dist/order-builder/builder.d.ts +0 -19
  27. package/dist/order-builder/builder.js +0 -32
  28. package/dist/order-builder/builder.js.map +0 -1
  29. package/dist/order-builder/helpers.d.ts +0 -49
  30. package/dist/order-builder/helpers.js +0 -292
  31. package/dist/order-builder/helpers.js.map +0 -1
  32. package/dist/order-builder/index.d.ts +0 -1
  33. package/dist/order-builder/index.js +0 -5
  34. package/dist/order-builder/index.js.map +0 -1
  35. package/dist/signing/constants.d.ts +0 -14
  36. package/dist/signing/constants.js +0 -19
  37. package/dist/signing/constants.js.map +0 -1
  38. package/dist/signing/eip712.d.ts +0 -10
  39. package/dist/signing/eip712.js +0 -39
  40. package/dist/signing/eip712.js.map +0 -1
  41. package/dist/signing/hmac.d.ts +0 -9
  42. package/dist/signing/hmac.js +0 -32
  43. package/dist/signing/hmac.js.map +0 -1
  44. package/dist/signing/index.d.ts +0 -2
  45. package/dist/signing/index.js +0 -6
  46. package/dist/signing/index.js.map +0 -1
  47. package/dist/types.d.ts +0 -410
  48. package/dist/types.js +0 -34
  49. package/dist/types.js.map +0 -1
  50. package/dist/utilities.d.ts +0 -15
  51. package/dist/utilities.js +0 -89
  52. package/dist/utilities.js.map +0 -1
package/dist/client.js DELETED
@@ -1,812 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ClobClient = void 0;
4
- const tslib_1 = require("tslib");
5
- const types_1 = require("./types");
6
- const headers_1 = require("./headers");
7
- const http_helpers_1 = require("./http-helpers");
8
- const errors_1 = require("./errors");
9
- const utilities_1 = require("./utilities");
10
- const endpoints_1 = require("./endpoints");
11
- const builder_1 = require("./order-builder/builder");
12
- const constants_1 = require("./constants");
13
- const helpers_1 = require("./order-builder/helpers");
14
- class ClobClient {
15
- // eslint-disable-next-line max-params
16
- constructor(host, chainId, signer, creds, signatureType, funderAddress, geoBlockToken, useServerTime, builderConfig) {
17
- this.host = host.endsWith("/") ? host.slice(0, -1) : host;
18
- this.chainId = chainId;
19
- if (signer !== undefined) {
20
- this.signer = signer;
21
- }
22
- if (creds !== undefined) {
23
- this.creds = creds;
24
- }
25
- this.orderBuilder = new builder_1.OrderBuilder(signer, chainId, signatureType, funderAddress);
26
- this.tickSizes = {};
27
- this.negRisk = {};
28
- this.feeRates = {};
29
- this.geoBlockToken = geoBlockToken;
30
- this.useServerTime = useServerTime;
31
- if (builderConfig !== undefined) {
32
- this.builderConfig = builderConfig;
33
- }
34
- }
35
- // Public endpoints
36
- getOk() {
37
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
38
- return this.get(`${this.host}/`);
39
- });
40
- }
41
- getServerTime() {
42
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
43
- return this.get(`${this.host}${endpoints_1.TIME}`);
44
- });
45
- }
46
- getSamplingSimplifiedMarkets(next_cursor = constants_1.INITIAL_CURSOR) {
47
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
48
- return this.get(`${this.host}${endpoints_1.GET_SAMPLING_SIMPLIFIED_MARKETS}`, {
49
- params: { next_cursor },
50
- });
51
- });
52
- }
53
- getSamplingMarkets(next_cursor = constants_1.INITIAL_CURSOR) {
54
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
55
- return this.get(`${this.host}${endpoints_1.GET_SAMPLING_MARKETS}`, {
56
- params: { next_cursor },
57
- });
58
- });
59
- }
60
- getSimplifiedMarkets(next_cursor = constants_1.INITIAL_CURSOR) {
61
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
62
- return this.get(`${this.host}${endpoints_1.GET_SIMPLIFIED_MARKETS}`, {
63
- params: { next_cursor },
64
- });
65
- });
66
- }
67
- getMarkets(next_cursor = constants_1.INITIAL_CURSOR) {
68
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
69
- return this.get(`${this.host}${endpoints_1.GET_MARKETS}`, {
70
- params: { next_cursor },
71
- });
72
- });
73
- }
74
- getMarket(conditionID) {
75
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
76
- return this.get(`${this.host}${endpoints_1.GET_MARKET}${conditionID}`);
77
- });
78
- }
79
- getOrderBook(tokenID) {
80
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
81
- return this.get(`${this.host}${endpoints_1.GET_ORDER_BOOK}`, {
82
- params: { token_id: tokenID },
83
- });
84
- });
85
- }
86
- getOrderBooks(params) {
87
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
88
- return this.post(`${this.host}${endpoints_1.GET_ORDER_BOOKS}`, {
89
- data: params,
90
- });
91
- });
92
- }
93
- getTickSize(tokenID) {
94
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
95
- if (tokenID in this.tickSizes) {
96
- return this.tickSizes[tokenID];
97
- }
98
- const result = yield this.get(`${this.host}${endpoints_1.GET_TICK_SIZE}`, {
99
- params: { token_id: tokenID },
100
- });
101
- this.tickSizes[tokenID] = result.minimum_tick_size.toString();
102
- return this.tickSizes[tokenID];
103
- });
104
- }
105
- getNegRisk(tokenID) {
106
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
107
- if (tokenID in this.negRisk) {
108
- return this.negRisk[tokenID];
109
- }
110
- const result = yield this.get(`${this.host}${endpoints_1.GET_NEG_RISK}`, {
111
- params: { token_id: tokenID },
112
- });
113
- this.negRisk[tokenID] = result.neg_risk;
114
- return this.negRisk[tokenID];
115
- });
116
- }
117
- getFeeRateBps(tokenID) {
118
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
119
- if (tokenID in this.feeRates) {
120
- return this.feeRates[tokenID];
121
- }
122
- const result = yield this.get(`${this.host}${endpoints_1.GET_FEE_RATE}`, {
123
- params: { token_id: tokenID },
124
- });
125
- this.feeRates[tokenID] = result.base_fee;
126
- return this.feeRates[tokenID];
127
- });
128
- }
129
- /**
130
- * Calculates the hash for the given orderbook
131
- * @param orderbook
132
- * @returns
133
- */
134
- getOrderBookHash(orderbook) {
135
- return (0, utilities_1.generateOrderBookSummaryHash)(orderbook);
136
- }
137
- getMidpoint(tokenID) {
138
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
139
- return this.get(`${this.host}${endpoints_1.GET_MIDPOINT}`, {
140
- params: { token_id: tokenID },
141
- });
142
- });
143
- }
144
- getMidpoints(params) {
145
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
146
- return this.post(`${this.host}${endpoints_1.GET_MIDPOINTS}`, {
147
- data: params,
148
- });
149
- });
150
- }
151
- getPrice(tokenID, side) {
152
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
153
- return this.get(`${this.host}${endpoints_1.GET_PRICE}`, {
154
- params: { token_id: tokenID, side: side },
155
- });
156
- });
157
- }
158
- getPrices(params) {
159
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
160
- return this.post(`${this.host}${endpoints_1.GET_PRICES}`, {
161
- data: params,
162
- });
163
- });
164
- }
165
- getSpread(tokenID) {
166
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
167
- return this.get(`${this.host}${endpoints_1.GET_SPREAD}`, {
168
- params: { token_id: tokenID },
169
- });
170
- });
171
- }
172
- getSpreads(params) {
173
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
174
- return this.post(`${this.host}${endpoints_1.GET_SPREADS}`, {
175
- data: params,
176
- });
177
- });
178
- }
179
- getLastTradePrice(tokenID) {
180
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
181
- return this.get(`${this.host}${endpoints_1.GET_LAST_TRADE_PRICE}`, {
182
- params: { token_id: tokenID },
183
- });
184
- });
185
- }
186
- getLastTradesPrices(params) {
187
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
188
- return this.post(`${this.host}${endpoints_1.GET_LAST_TRADES_PRICES}`, {
189
- data: params,
190
- });
191
- });
192
- }
193
- getPricesHistory(params) {
194
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
195
- return this.get(`${this.host}${endpoints_1.GET_PRICES_HISTORY}`, {
196
- params,
197
- });
198
- });
199
- }
200
- // L1 Authed
201
- /**
202
- * Creates a new API key for a user
203
- * @param nonce
204
- * @returns ApiKeyCreds
205
- */
206
- createApiKey(nonce) {
207
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
208
- this.canL1Auth();
209
- const endpoint = `${this.host}${endpoints_1.CREATE_API_KEY}`;
210
- const headers = yield (0, headers_1.createL1Headers)(this.signer, this.chainId, nonce, this.useServerTime ? yield this.getServerTime() : undefined);
211
- return yield this.post(endpoint, { headers }).then((apiKeyRaw) => {
212
- const apiKey = {
213
- key: apiKeyRaw.apiKey,
214
- secret: apiKeyRaw.secret,
215
- passphrase: apiKeyRaw.passphrase,
216
- };
217
- return apiKey;
218
- });
219
- });
220
- }
221
- /**
222
- * Derives an existing API key for a user
223
- * @param nonce
224
- * @returns ApiKeyCreds
225
- */
226
- deriveApiKey(nonce) {
227
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
228
- this.canL1Auth();
229
- const endpoint = `${this.host}${endpoints_1.DERIVE_API_KEY}`;
230
- const headers = yield (0, headers_1.createL1Headers)(this.signer, this.chainId, nonce, this.useServerTime ? yield this.getServerTime() : undefined);
231
- return yield this.get(endpoint, { headers }).then((apiKeyRaw) => {
232
- const apiKey = {
233
- key: apiKeyRaw.apiKey,
234
- secret: apiKeyRaw.secret,
235
- passphrase: apiKeyRaw.passphrase,
236
- };
237
- return apiKey;
238
- });
239
- });
240
- }
241
- createOrDeriveApiKey(nonce) {
242
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
243
- return this.createApiKey(nonce).then(response => {
244
- if (!response.key) {
245
- return this.deriveApiKey(nonce);
246
- }
247
- return response;
248
- });
249
- });
250
- }
251
- getApiKeys() {
252
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
253
- this.canL2Auth();
254
- const endpoint = endpoints_1.GET_API_KEYS;
255
- const headerArgs = {
256
- method: http_helpers_1.GET,
257
- requestPath: endpoint,
258
- };
259
- const headers = yield (0, headers_1.createL2Headers)(this.signer, this.creds, headerArgs, this.useServerTime ? yield this.getServerTime() : undefined);
260
- return this.get(`${this.host}${endpoint}`, { headers });
261
- });
262
- }
263
- getClosedOnlyMode() {
264
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
265
- this.canL2Auth();
266
- const endpoint = endpoints_1.CLOSED_ONLY;
267
- const headerArgs = {
268
- method: http_helpers_1.GET,
269
- requestPath: endpoint,
270
- };
271
- const headers = yield (0, headers_1.createL2Headers)(this.signer, this.creds, headerArgs, this.useServerTime ? yield this.getServerTime() : undefined);
272
- return this.get(`${this.host}${endpoint}`, { headers });
273
- });
274
- }
275
- deleteApiKey() {
276
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
277
- this.canL2Auth();
278
- const endpoint = endpoints_1.DELETE_API_KEY;
279
- const headerArgs = {
280
- method: http_helpers_1.DELETE,
281
- requestPath: endpoint,
282
- };
283
- const headers = yield (0, headers_1.createL2Headers)(this.signer, this.creds, headerArgs, this.useServerTime ? yield this.getServerTime() : undefined);
284
- return this.del(`${this.host}${endpoint}`, { headers });
285
- });
286
- }
287
- getOrder(orderID) {
288
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
289
- this.canL2Auth();
290
- const endpoint = `${endpoints_1.GET_ORDER}${orderID}`;
291
- const headerArgs = {
292
- method: http_helpers_1.GET,
293
- requestPath: endpoint,
294
- };
295
- const headers = yield (0, headers_1.createL2Headers)(this.signer, this.creds, headerArgs, this.useServerTime ? yield this.getServerTime() : undefined);
296
- return this.get(`${this.host}${endpoint}`, { headers });
297
- });
298
- }
299
- getTrades(params, only_first_page = false, next_cursor) {
300
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
301
- this.canL2Auth();
302
- const endpoint = endpoints_1.GET_TRADES;
303
- const headerArgs = {
304
- method: http_helpers_1.GET,
305
- requestPath: endpoint,
306
- };
307
- const headers = yield (0, headers_1.createL2Headers)(this.signer, this.creds, headerArgs, this.useServerTime ? yield this.getServerTime() : undefined);
308
- let results = [];
309
- next_cursor = next_cursor || constants_1.INITIAL_CURSOR;
310
- while (next_cursor != constants_1.END_CURSOR && (next_cursor === constants_1.INITIAL_CURSOR || !only_first_page)) {
311
- const _params = Object.assign(Object.assign({}, params), { next_cursor });
312
- const response = yield this.get(`${this.host}${endpoint}`, {
313
- headers,
314
- params: _params,
315
- });
316
- next_cursor = response.next_cursor;
317
- results = [...results, ...response.data];
318
- }
319
- return results;
320
- });
321
- }
322
- getTradesPaginated(params, next_cursor) {
323
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
324
- this.canL2Auth();
325
- const endpoint = endpoints_1.GET_TRADES;
326
- const headerArgs = {
327
- method: http_helpers_1.GET,
328
- requestPath: endpoint,
329
- };
330
- const headers = yield (0, headers_1.createL2Headers)(this.signer, this.creds, headerArgs, this.useServerTime ? yield this.getServerTime() : undefined);
331
- next_cursor = next_cursor || constants_1.INITIAL_CURSOR;
332
- const _params = Object.assign(Object.assign({}, params), { next_cursor });
333
- const _a = yield this.get(`${this.host}${endpoint}`, {
334
- headers,
335
- params: _params,
336
- }), { data } = _a, rest = tslib_1.__rest(_a, ["data"]);
337
- return Object.assign({ trades: Array.isArray(data) ? [...data] : [] }, rest);
338
- });
339
- }
340
- getNotifications() {
341
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
342
- this.canL2Auth();
343
- const endpoint = endpoints_1.GET_NOTIFICATIONS;
344
- const headerArgs = {
345
- method: http_helpers_1.GET,
346
- requestPath: endpoint,
347
- };
348
- const headers = yield (0, headers_1.createL2Headers)(this.signer, this.creds, headerArgs, this.useServerTime ? yield this.getServerTime() : undefined);
349
- return this.get(`${this.host}${endpoint}`, {
350
- headers,
351
- params: { signature_type: this.orderBuilder.signatureType },
352
- });
353
- });
354
- }
355
- dropNotifications(params) {
356
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
357
- this.canL2Auth();
358
- const endpoint = endpoints_1.DROP_NOTIFICATIONS;
359
- const l2HeaderArgs = {
360
- method: http_helpers_1.DELETE,
361
- requestPath: endpoint,
362
- };
363
- const headers = yield (0, headers_1.createL2Headers)(this.signer, this.creds, l2HeaderArgs, this.useServerTime ? yield this.getServerTime() : undefined);
364
- return this.del(`${this.host}${endpoint}`, {
365
- headers,
366
- params: (0, http_helpers_1.parseDropNotificationParams)(params),
367
- });
368
- });
369
- }
370
- getBalanceAllowance(params) {
371
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
372
- this.canL2Auth();
373
- const endpoint = endpoints_1.GET_BALANCE_ALLOWANCE;
374
- const headerArgs = {
375
- method: http_helpers_1.GET,
376
- requestPath: endpoint,
377
- };
378
- const headers = yield (0, headers_1.createL2Headers)(this.signer, this.creds, headerArgs, this.useServerTime ? yield this.getServerTime() : undefined);
379
- const _params = Object.assign(Object.assign({}, params), { signature_type: this.orderBuilder.signatureType });
380
- return this.get(`${this.host}${endpoint}`, { headers, params: _params });
381
- });
382
- }
383
- updateBalanceAllowance(params) {
384
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
385
- this.canL2Auth();
386
- const endpoint = endpoints_1.UPDATE_BALANCE_ALLOWANCE;
387
- const headerArgs = {
388
- method: http_helpers_1.GET,
389
- requestPath: endpoint,
390
- };
391
- const headers = yield (0, headers_1.createL2Headers)(this.signer, this.creds, headerArgs, this.useServerTime ? yield this.getServerTime() : undefined);
392
- const _params = Object.assign(Object.assign({}, params), { signature_type: this.orderBuilder.signatureType });
393
- return this.get(`${this.host}${endpoint}`, { headers, params: _params });
394
- });
395
- }
396
- createOrder(userOrder, options) {
397
- var _a;
398
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
399
- this.canL1Auth();
400
- const { tokenID } = userOrder;
401
- const tickSize = yield this._resolveTickSize(tokenID, options === null || options === void 0 ? void 0 : options.tickSize);
402
- const feeRateBps = yield this._resolveFeeRateBps(tokenID, userOrder.feeRateBps);
403
- userOrder.feeRateBps = feeRateBps;
404
- if (!(0, utilities_1.priceValid)(userOrder.price, tickSize)) {
405
- throw new Error(`invalid price (${userOrder.price}), min: ${parseFloat(tickSize)} - max: ${1 - parseFloat(tickSize)}`);
406
- }
407
- const negRisk = (_a = options === null || options === void 0 ? void 0 : options.negRisk) !== null && _a !== void 0 ? _a : (yield this.getNegRisk(tokenID));
408
- return this.orderBuilder.buildOrder(userOrder, {
409
- tickSize,
410
- negRisk,
411
- });
412
- });
413
- }
414
- createMarketOrder(userMarketOrder, options) {
415
- var _a;
416
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
417
- this.canL1Auth();
418
- const { tokenID } = userMarketOrder;
419
- const tickSize = yield this._resolveTickSize(tokenID, options === null || options === void 0 ? void 0 : options.tickSize);
420
- const feeRateBps = yield this._resolveFeeRateBps(tokenID, userMarketOrder.feeRateBps);
421
- userMarketOrder.feeRateBps = feeRateBps;
422
- if (!userMarketOrder.price) {
423
- userMarketOrder.price = yield this.calculateMarketPrice(tokenID, userMarketOrder.side, userMarketOrder.amount, userMarketOrder.orderType);
424
- }
425
- if (!(0, utilities_1.priceValid)(userMarketOrder.price, tickSize)) {
426
- throw new Error(`invalid price (${userMarketOrder.price}), min: ${parseFloat(tickSize)} - max: ${1 - parseFloat(tickSize)}`);
427
- }
428
- const negRisk = (_a = options === null || options === void 0 ? void 0 : options.negRisk) !== null && _a !== void 0 ? _a : (yield this.getNegRisk(tokenID));
429
- return this.orderBuilder.buildMarketOrder(userMarketOrder, {
430
- tickSize,
431
- negRisk,
432
- });
433
- });
434
- }
435
- createAndPostOrder(userOrder, options, orderType = types_1.OrderType.GTC, deferExec = false) {
436
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
437
- const order = yield this.createOrder(userOrder, options);
438
- return this.postOrder(order, orderType, deferExec);
439
- });
440
- }
441
- createAndPostMarketOrder(userMarketOrder, options, orderType = types_1.OrderType.FOK, deferExec = false) {
442
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
443
- const order = yield this.createMarketOrder(userMarketOrder, options);
444
- return this.postOrder(order, orderType, deferExec);
445
- });
446
- }
447
- getOpenOrders(params, only_first_page = false, next_cursor) {
448
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
449
- this.canL2Auth();
450
- const endpoint = endpoints_1.GET_OPEN_ORDERS;
451
- const l2HeaderArgs = {
452
- method: http_helpers_1.GET,
453
- requestPath: endpoint,
454
- };
455
- const headers = yield (0, headers_1.createL2Headers)(this.signer, this.creds, l2HeaderArgs, this.useServerTime ? yield this.getServerTime() : undefined);
456
- let results = [];
457
- next_cursor = next_cursor || constants_1.INITIAL_CURSOR;
458
- while (next_cursor != constants_1.END_CURSOR && (next_cursor === constants_1.INITIAL_CURSOR || !only_first_page)) {
459
- const _params = Object.assign(Object.assign({}, params), { next_cursor });
460
- const response = yield this.get(`${this.host}${endpoint}`, {
461
- headers,
462
- params: _params,
463
- });
464
- next_cursor = response.next_cursor;
465
- results = [...results, ...response.data];
466
- }
467
- return results;
468
- });
469
- }
470
- postOrder(order, orderType = types_1.OrderType.GTC, deferExec = false) {
471
- var _a;
472
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
473
- this.canL2Auth();
474
- const endpoint = endpoints_1.POST_ORDER;
475
- const orderPayload = (0, utilities_1.orderToJson)(order, ((_a = this.creds) === null || _a === void 0 ? void 0 : _a.key) || "", orderType, deferExec);
476
- const l2HeaderArgs = {
477
- method: http_helpers_1.POST,
478
- requestPath: endpoint,
479
- body: JSON.stringify(orderPayload),
480
- };
481
- const headers = yield (0, headers_1.createL2Headers)(this.signer, this.creds, l2HeaderArgs, this.useServerTime ? yield this.getServerTime() : undefined);
482
- // builders flow
483
- if (this.canBuilderAuth()) {
484
- const builderHeaders = yield this._generateBuilderHeaders(headers, l2HeaderArgs);
485
- if (builderHeaders !== undefined) {
486
- return this.post(`${this.host}${endpoint}`, { headers: builderHeaders, data: orderPayload });
487
- }
488
- }
489
- return this.post(`${this.host}${endpoint}`, { headers, data: orderPayload });
490
- });
491
- }
492
- postOrders(args, deferExec = false) {
493
- var _a;
494
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
495
- this.canL2Auth();
496
- const endpoint = endpoints_1.POST_ORDERS;
497
- const ordersPayload = [];
498
- for (const { order, orderType } of args) {
499
- const orderPayload = (0, utilities_1.orderToJson)(order, ((_a = this.creds) === null || _a === void 0 ? void 0 : _a.key) || "", orderType, deferExec);
500
- ordersPayload.push(orderPayload);
501
- }
502
- const l2HeaderArgs = {
503
- method: http_helpers_1.POST,
504
- requestPath: endpoint,
505
- body: JSON.stringify(ordersPayload),
506
- };
507
- const headers = yield (0, headers_1.createL2Headers)(this.signer, this.creds, l2HeaderArgs, this.useServerTime ? yield this.getServerTime() : undefined);
508
- // builders flow
509
- if (this.canBuilderAuth()) {
510
- const builderHeaders = yield this._generateBuilderHeaders(headers, l2HeaderArgs);
511
- if (builderHeaders !== undefined) {
512
- return this.post(`${this.host}${endpoint}`, { headers: builderHeaders, data: ordersPayload });
513
- }
514
- }
515
- return this.post(`${this.host}${endpoint}`, { headers, data: ordersPayload });
516
- });
517
- }
518
- cancelOrder(payload) {
519
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
520
- this.canL2Auth();
521
- const endpoint = endpoints_1.CANCEL_ORDER;
522
- const l2HeaderArgs = {
523
- method: http_helpers_1.DELETE,
524
- requestPath: endpoint,
525
- body: JSON.stringify(payload),
526
- };
527
- const headers = yield (0, headers_1.createL2Headers)(this.signer, this.creds, l2HeaderArgs, this.useServerTime ? yield this.getServerTime() : undefined);
528
- return this.del(`${this.host}${endpoint}`, { headers, data: payload });
529
- });
530
- }
531
- cancelOrders(ordersHashes) {
532
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
533
- this.canL2Auth();
534
- const endpoint = endpoints_1.CANCEL_ORDERS;
535
- const l2HeaderArgs = {
536
- method: http_helpers_1.DELETE,
537
- requestPath: endpoint,
538
- body: JSON.stringify(ordersHashes),
539
- };
540
- const headers = yield (0, headers_1.createL2Headers)(this.signer, this.creds, l2HeaderArgs, this.useServerTime ? yield this.getServerTime() : undefined);
541
- return this.del(`${this.host}${endpoint}`, { headers, data: ordersHashes });
542
- });
543
- }
544
- cancelAll() {
545
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
546
- this.canL2Auth();
547
- const endpoint = endpoints_1.CANCEL_ALL;
548
- const l2HeaderArgs = {
549
- method: http_helpers_1.DELETE,
550
- requestPath: endpoint,
551
- };
552
- const headers = yield (0, headers_1.createL2Headers)(this.signer, this.creds, l2HeaderArgs, this.useServerTime ? yield this.getServerTime() : undefined);
553
- return this.del(`${this.host}${endpoint}`, { headers });
554
- });
555
- }
556
- cancelMarketOrders(payload) {
557
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
558
- this.canL2Auth();
559
- const endpoint = endpoints_1.CANCEL_MARKET_ORDERS;
560
- const l2HeaderArgs = {
561
- method: http_helpers_1.DELETE,
562
- requestPath: endpoint,
563
- body: JSON.stringify(payload),
564
- };
565
- const headers = yield (0, headers_1.createL2Headers)(this.signer, this.creds, l2HeaderArgs, this.useServerTime ? yield this.getServerTime() : undefined);
566
- return this.del(`${this.host}${endpoint}`, { headers, data: payload });
567
- });
568
- }
569
- isOrderScoring(params) {
570
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
571
- this.canL2Auth();
572
- const endpoint = endpoints_1.IS_ORDER_SCORING;
573
- const headerArgs = {
574
- method: http_helpers_1.GET,
575
- requestPath: endpoint,
576
- };
577
- const headers = yield (0, headers_1.createL2Headers)(this.signer, this.creds, headerArgs, this.useServerTime ? yield this.getServerTime() : undefined);
578
- return this.get(`${this.host}${endpoint}`, { headers, params });
579
- });
580
- }
581
- areOrdersScoring(params) {
582
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
583
- this.canL2Auth();
584
- const endpoint = endpoints_1.ARE_ORDERS_SCORING;
585
- const payload = JSON.stringify(params === null || params === void 0 ? void 0 : params.orderIds);
586
- const headerArgs = {
587
- method: http_helpers_1.POST,
588
- requestPath: endpoint,
589
- body: payload,
590
- };
591
- const headers = yield (0, headers_1.createL2Headers)(this.signer, this.creds, headerArgs, this.useServerTime ? yield this.getServerTime() : undefined);
592
- return this.post(`${this.host}${endpoint}`, {
593
- headers,
594
- data: payload,
595
- });
596
- });
597
- }
598
- // Rewards
599
- getEarningsForUserForDay(date) {
600
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
601
- this.canL2Auth();
602
- const endpoint = endpoints_1.GET_EARNINGS_FOR_USER_FOR_DAY;
603
- const headerArgs = {
604
- method: http_helpers_1.GET,
605
- requestPath: endpoint,
606
- };
607
- const headers = yield (0, headers_1.createL2Headers)(this.signer, this.creds, headerArgs, this.useServerTime ? yield this.getServerTime() : undefined);
608
- let results = [];
609
- let next_cursor = constants_1.INITIAL_CURSOR;
610
- while (next_cursor != constants_1.END_CURSOR) {
611
- const params = {
612
- date,
613
- signature_type: this.orderBuilder.signatureType,
614
- next_cursor,
615
- };
616
- const response = yield this.get(`${this.host}${endpoint}`, {
617
- headers,
618
- params,
619
- });
620
- next_cursor = response.next_cursor;
621
- results = [...results, ...response.data];
622
- }
623
- return results;
624
- });
625
- }
626
- getTotalEarningsForUserForDay(date) {
627
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
628
- this.canL2Auth();
629
- const endpoint = endpoints_1.GET_TOTAL_EARNINGS_FOR_USER_FOR_DAY;
630
- const headerArgs = {
631
- method: http_helpers_1.GET,
632
- requestPath: endpoint,
633
- };
634
- const headers = yield (0, headers_1.createL2Headers)(this.signer, this.creds, headerArgs, this.useServerTime ? yield this.getServerTime() : undefined);
635
- const params = {
636
- date,
637
- signature_type: this.orderBuilder.signatureType,
638
- };
639
- return yield this.get(`${this.host}${endpoint}`, {
640
- headers,
641
- params,
642
- });
643
- });
644
- }
645
- getUserEarningsAndMarketsConfig(date, order_by = "", position = "", no_competition = false) {
646
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
647
- this.canL2Auth();
648
- const endpoint = endpoints_1.GET_REWARDS_EARNINGS_PERCENTAGES;
649
- const headerArgs = {
650
- method: http_helpers_1.GET,
651
- requestPath: endpoint,
652
- };
653
- const headers = yield (0, headers_1.createL2Headers)(this.signer, this.creds, headerArgs, this.useServerTime ? yield this.getServerTime() : undefined);
654
- let results = [];
655
- let next_cursor = constants_1.INITIAL_CURSOR;
656
- while (next_cursor != constants_1.END_CURSOR) {
657
- const params = {
658
- date,
659
- signature_type: this.orderBuilder.signatureType,
660
- next_cursor,
661
- order_by,
662
- position,
663
- no_competition,
664
- };
665
- const response = yield this.get(`${this.host}${endpoint}`, {
666
- headers,
667
- params,
668
- });
669
- next_cursor = response.next_cursor;
670
- results = [...results, ...response.data];
671
- }
672
- return results;
673
- });
674
- }
675
- getRewardPercentages() {
676
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
677
- this.canL2Auth();
678
- const endpoint = endpoints_1.GET_LIQUIDITY_REWARD_PERCENTAGES;
679
- const headerArgs = {
680
- method: http_helpers_1.GET,
681
- requestPath: endpoint,
682
- };
683
- const headers = yield (0, headers_1.createL2Headers)(this.signer, this.creds, headerArgs, this.useServerTime ? yield this.getServerTime() : undefined);
684
- const _params = {
685
- signature_type: this.orderBuilder.signatureType,
686
- };
687
- return this.get(`${this.host}${endpoint}`, { headers, params: _params });
688
- });
689
- }
690
- getCurrentRewards() {
691
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
692
- let results = [];
693
- let next_cursor = constants_1.INITIAL_CURSOR;
694
- while (next_cursor != constants_1.END_CURSOR) {
695
- const response = yield this.get(`${this.host}${endpoints_1.GET_REWARDS_MARKETS_CURRENT}`, {
696
- params: { next_cursor },
697
- });
698
- next_cursor = response.next_cursor;
699
- results = [...results, ...response.data];
700
- }
701
- return results;
702
- });
703
- }
704
- getRawRewardsForMarket(conditionId) {
705
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
706
- let results = [];
707
- let next_cursor = constants_1.INITIAL_CURSOR;
708
- while (next_cursor != constants_1.END_CURSOR) {
709
- const response = yield this.get(`${this.host}${endpoints_1.GET_REWARDS_MARKETS}${conditionId}`, {
710
- params: { next_cursor },
711
- });
712
- next_cursor = response.next_cursor;
713
- results = [...results, ...response.data];
714
- }
715
- return results;
716
- });
717
- }
718
- getMarketTradesEvents(conditionID) {
719
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
720
- return this.get(`${this.host}${endpoints_1.GET_MARKET_TRADES_EVENTS}${conditionID}`);
721
- });
722
- }
723
- calculateMarketPrice(tokenID, side, amount, orderType = types_1.OrderType.FOK) {
724
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
725
- const book = yield this.getOrderBook(tokenID);
726
- if (!book) {
727
- throw new Error("no orderbook");
728
- }
729
- if (side === types_1.Side.BUY) {
730
- if (!book.asks) {
731
- throw new Error("no match");
732
- }
733
- return (0, helpers_1.calculateBuyMarketPrice)(book.asks, amount, orderType);
734
- }
735
- else {
736
- if (!book.bids) {
737
- throw new Error("no match");
738
- }
739
- return (0, helpers_1.calculateSellMarketPrice)(book.bids, amount, orderType);
740
- }
741
- });
742
- }
743
- canL1Auth() {
744
- if (this.signer === undefined) {
745
- throw errors_1.L1_AUTH_UNAVAILABLE_ERROR;
746
- }
747
- }
748
- canL2Auth() {
749
- if (this.signer === undefined) {
750
- throw errors_1.L1_AUTH_UNAVAILABLE_ERROR;
751
- }
752
- if (this.creds === undefined) {
753
- throw errors_1.L2_AUTH_NOT_AVAILABLE;
754
- }
755
- }
756
- canBuilderAuth() {
757
- return (this.builderConfig != undefined && this.builderConfig.isValid());
758
- }
759
- _resolveTickSize(tokenID, tickSize) {
760
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
761
- const minTickSize = yield this.getTickSize(tokenID);
762
- if (tickSize) {
763
- if ((0, utilities_1.isTickSizeSmaller)(tickSize, minTickSize)) {
764
- throw new Error(`invalid tick size (${tickSize}), minimum for the market is ${minTickSize}`);
765
- }
766
- }
767
- else {
768
- tickSize = minTickSize;
769
- }
770
- return tickSize;
771
- });
772
- }
773
- _resolveFeeRateBps(tokenID, userFeeRateBps) {
774
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
775
- const marketFeeRateBps = yield this.getFeeRateBps(tokenID);
776
- if (marketFeeRateBps > 0 && userFeeRateBps != undefined && userFeeRateBps != marketFeeRateBps) {
777
- throw new Error(`invalid user provided fee rate: ${userFeeRateBps}, fee rate for the market must be ${marketFeeRateBps}`);
778
- }
779
- return marketFeeRateBps;
780
- });
781
- }
782
- _generateBuilderHeaders(headers, headerArgs) {
783
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
784
- if (this.builderConfig !== undefined) {
785
- const builderHeaders = yield this.builderConfig.generateBuilderHeaders(headerArgs.method, headerArgs.requestPath, headerArgs.body);
786
- if (builderHeaders == undefined) {
787
- return undefined;
788
- }
789
- return (0, headers_1.injectBuilderHeaders)(headers, builderHeaders);
790
- }
791
- return undefined;
792
- });
793
- }
794
- // http methods
795
- get(endpoint, options) {
796
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
797
- return (0, http_helpers_1.get)(endpoint, Object.assign(Object.assign({}, options), { params: Object.assign(Object.assign({}, options === null || options === void 0 ? void 0 : options.params), { geo_block_token: this.geoBlockToken }) }));
798
- });
799
- }
800
- post(endpoint, options) {
801
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
802
- return (0, http_helpers_1.post)(endpoint, Object.assign(Object.assign({}, options), { params: Object.assign(Object.assign({}, options === null || options === void 0 ? void 0 : options.params), { geo_block_token: this.geoBlockToken }) }));
803
- });
804
- }
805
- del(endpoint, options) {
806
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
807
- return (0, http_helpers_1.del)(endpoint, Object.assign(Object.assign({}, options), { params: Object.assign(Object.assign({}, options === null || options === void 0 ? void 0 : options.params), { geo_block_token: this.geoBlockToken }) }));
808
- });
809
- }
810
- }
811
- exports.ClobClient = ClobClient;
812
- //# sourceMappingURL=client.js.map