@polymarket/clob-client-v2 1.0.8 → 1.1.1-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -0
- package/dist/client.cjs +97 -20
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +31 -5
- package/dist/client.d.ts +31 -5
- package/dist/client.js +97 -20
- package/dist/client.js.map +1 -1
- package/dist/types/clob.cjs.map +1 -1
- package/dist/types/clob.d.cts +5 -0
- package/dist/types/clob.d.ts +5 -0
- package/dist/types/clob.js.map +1 -1
- package/package.json +1 -1
package/dist/client.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ClobSigner } from "./signing/signer.cjs";
|
|
2
2
|
import { Side } from "./order-utils/model/side.cjs";
|
|
3
|
-
import { ApiKeyCreds, ApiKeysResponse, BalanceAllowanceParams, BalanceAllowanceResponse, BanStatus, BookParams, BuilderApiKey, BuilderApiKeyResponse, BuilderConfig, BuilderFeeRates, BuilderTradeParams, BuilderTradesResponse, Chain, CreateOrderOptions, DropNotificationParams, FeeInfos, FeeRates, MarketDetails, MarketPrice, MarketReward, MarketTradeEvent, NegRisk, Notification, OpenOrder, OpenOrderParams, OpenOrdersResponse, OrderBookSummary, OrderMarketCancelParams, OrderPayload, OrderScoring, OrderScoringParams, OrderType, OrdersScoring, OrdersScoringParams, PaginationPayload, PreMigrationOrdersResponse, PriceHistoryFilterParams, ReadonlyApiKeyResponse, RewardsPercentages, TickSize, TickSizes, TotalUserEarning, Trade, TradeParams, TradesPaginatedResponse, UserEarning, UserRewardsEarning } from "./types/clob.cjs";
|
|
3
|
+
import { ApiKeyCreds, ApiKeysResponse, BalanceAllowanceParams, BalanceAllowanceResponse, BanStatus, BookParams, BuilderApiKey, BuilderApiKeyResponse, BuilderConfig, BuilderFeeRates, BuilderTradeParams, BuilderTradesResponse, Chain, CreateOrderOptions, DropNotificationParams, FeeInfos, FeeRates, MarketDetails, MarketPrice, MarketReward, MarketTradeEvent, NegRisk, Notification, OpenOrder, OpenOrderParams, OpenOrdersResponse, OrderBookSummary, OrderMarketCancelParams, OrderPayload, OrderResponse, OrderScoring, OrderScoringParams, OrderType, OrdersScoring, OrdersScoringParams, PaginationPayload, PreMigrationOrdersResponse, PriceHistoryFilterParams, ReadonlyApiKeyResponse, RewardsPercentages, TickSize, TickSizes, TotalUserEarning, Trade, TradeParams, TradesPaginatedResponse, UserEarning, UserRewardsEarning } from "./types/clob.cjs";
|
|
4
4
|
import { UserMarketOrderV1, UserOrderV1 } from "./types/ordersV1.cjs";
|
|
5
5
|
import { UserMarketOrderV2, UserOrderV2 } from "./types/ordersV2.cjs";
|
|
6
6
|
import { ExchangeV3OrderAmounts } from "./types/ordersV3.cjs";
|
|
@@ -41,6 +41,8 @@ declare class ClobClient {
|
|
|
41
41
|
readonly signatureType: SignatureTypeV2;
|
|
42
42
|
readonly funderAddress?: string;
|
|
43
43
|
private cachedVersion?;
|
|
44
|
+
private versionRequest?;
|
|
45
|
+
private readonly marketInfoRequests;
|
|
44
46
|
readonly retryOnError?: boolean;
|
|
45
47
|
readonly throwOnError?: boolean;
|
|
46
48
|
readonly feeSlippage: number;
|
|
@@ -63,14 +65,28 @@ declare class ClobClient {
|
|
|
63
65
|
heartbeat_id: string;
|
|
64
66
|
error_msg?: string;
|
|
65
67
|
}>;
|
|
68
|
+
/**
|
|
69
|
+
* Fetches the current order version from the server and adopts it for the
|
|
70
|
+
* orders this client signs afterwards. Joins a version request that is
|
|
71
|
+
* already in flight. An error response yields the default version 2, which
|
|
72
|
+
* the first order corrects through the order version mismatch recovery.
|
|
73
|
+
* Throws ApiError when the client was created with throwOnError.
|
|
74
|
+
*/
|
|
66
75
|
getVersion(): Promise<number>;
|
|
76
|
+
private startVersionRequest;
|
|
67
77
|
getServerTime(): Promise<number>;
|
|
68
78
|
getSamplingSimplifiedMarkets(next_cursor?: string): Promise<PaginationPayload>;
|
|
69
79
|
getSamplingMarkets(next_cursor?: string): Promise<PaginationPayload>;
|
|
70
80
|
getSimplifiedMarkets(next_cursor?: string): Promise<PaginationPayload>;
|
|
71
81
|
getMarkets(next_cursor?: string): Promise<PaginationPayload>;
|
|
72
82
|
getMarket(conditionID: string): Promise<any>;
|
|
83
|
+
/**
|
|
84
|
+
* Fetches the market parameters for a condition and caches the tick size,
|
|
85
|
+
* neg-risk flag, and fee details of both outcomes for later orders. Every
|
|
86
|
+
* call refreshes the caches. Concurrent calls for a condition share one request.
|
|
87
|
+
*/
|
|
73
88
|
getClobMarketInfo(conditionID: string): Promise<MarketDetails>;
|
|
89
|
+
private fetchClobMarketInfo;
|
|
74
90
|
getOrderBook(tokenID: string): Promise<OrderBookSummary>;
|
|
75
91
|
getOrderBooks(params: BookParams[]): Promise<OrderBookSummary[]>;
|
|
76
92
|
getTickSize(tokenID: string): Promise<TickSize>;
|
|
@@ -122,12 +138,22 @@ declare class ClobClient {
|
|
|
122
138
|
createOrder(userOrder: UserOrderV1 | UserOrderV2, options?: Partial<CreateOrderOptions>): Promise<SignedOrder>;
|
|
123
139
|
createMarketOrder(userMarketOrder: UserMarketOrderV1 | UserMarketOrderV2, options?: Partial<CreateOrderOptions>): Promise<SignedOrder>;
|
|
124
140
|
createExchangeV3OrderFromAmounts(userOrder: ExchangeV3OrderAmounts): Promise<SignedOrder>;
|
|
125
|
-
createAndPostOrder<T extends OrderType.GTC | OrderType.GTD = OrderType.GTC>(userOrder: UserOrderV1 | UserOrderV2, options?: Partial<CreateOrderOptions>, orderType?: T, postOnly?: boolean, deferExec?: boolean): Promise<
|
|
126
|
-
createAndPostMarketOrder<T extends OrderType.FOK | OrderType.FAK = OrderType.FOK>(userMarketOrder: UserMarketOrderV1 | UserMarketOrderV2, options?: Partial<CreateOrderOptions>, orderType?: T, deferExec?: boolean): Promise<
|
|
141
|
+
createAndPostOrder<T extends OrderType.GTC | OrderType.GTD = OrderType.GTC>(userOrder: UserOrderV1 | UserOrderV2, options?: Partial<CreateOrderOptions>, orderType?: T, postOnly?: boolean, deferExec?: boolean): Promise<OrderResponse>;
|
|
142
|
+
createAndPostMarketOrder<T extends OrderType.FOK | OrderType.FAK = OrderType.FOK>(userMarketOrder: UserMarketOrderV1 | UserMarketOrderV2, options?: Partial<CreateOrderOptions>, orderType?: T, deferExec?: boolean): Promise<OrderResponse>;
|
|
127
143
|
getOpenOrders(params?: OpenOrderParams, only_first_page?: boolean, next_cursor?: string): Promise<OpenOrdersResponse>;
|
|
128
144
|
getPreMigrationOrders(only_first_page?: boolean, next_cursor?: string): Promise<PreMigrationOrdersResponse>;
|
|
129
|
-
|
|
130
|
-
|
|
145
|
+
/**
|
|
146
|
+
* Posts an order to the CLOB.
|
|
147
|
+
*
|
|
148
|
+
* When the order matches, the response carries the settlement transaction
|
|
149
|
+
* hashes of its fills in `transactionsHashes`, resolved on a best-effort
|
|
150
|
+
* basis. If a hash is not available yet, the fill's trade can be followed
|
|
151
|
+
* via `tradeIDs`.
|
|
152
|
+
*/
|
|
153
|
+
postOrder<T extends OrderType = OrderType.GTC>(order: SignedOrder, orderType?: T, postOnly?: boolean, deferExec?: boolean): Promise<OrderResponse>;
|
|
154
|
+
postOrders(args: PostOrdersArgs[], postOnly?: boolean, deferExec?: boolean): Promise<OrderResponse[]>;
|
|
155
|
+
private waitForResolvedTrades;
|
|
156
|
+
private resolveTransactionsHashes;
|
|
131
157
|
cancelOrder(payload: OrderPayload): Promise<any>;
|
|
132
158
|
cancelOrders(ordersHashes: string[]): Promise<any>;
|
|
133
159
|
cancelAll(): Promise<any>;
|
package/dist/client.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ClobSigner } from "./signing/signer.js";
|
|
2
2
|
import { Side } from "./order-utils/model/side.js";
|
|
3
|
-
import { ApiKeyCreds, ApiKeysResponse, BalanceAllowanceParams, BalanceAllowanceResponse, BanStatus, BookParams, BuilderApiKey, BuilderApiKeyResponse, BuilderConfig, BuilderFeeRates, BuilderTradeParams, BuilderTradesResponse, Chain, CreateOrderOptions, DropNotificationParams, FeeInfos, FeeRates, MarketDetails, MarketPrice, MarketReward, MarketTradeEvent, NegRisk, Notification, OpenOrder, OpenOrderParams, OpenOrdersResponse, OrderBookSummary, OrderMarketCancelParams, OrderPayload, OrderScoring, OrderScoringParams, OrderType, OrdersScoring, OrdersScoringParams, PaginationPayload, PreMigrationOrdersResponse, PriceHistoryFilterParams, ReadonlyApiKeyResponse, RewardsPercentages, TickSize, TickSizes, TotalUserEarning, Trade, TradeParams, TradesPaginatedResponse, UserEarning, UserRewardsEarning } from "./types/clob.js";
|
|
3
|
+
import { ApiKeyCreds, ApiKeysResponse, BalanceAllowanceParams, BalanceAllowanceResponse, BanStatus, BookParams, BuilderApiKey, BuilderApiKeyResponse, BuilderConfig, BuilderFeeRates, BuilderTradeParams, BuilderTradesResponse, Chain, CreateOrderOptions, DropNotificationParams, FeeInfos, FeeRates, MarketDetails, MarketPrice, MarketReward, MarketTradeEvent, NegRisk, Notification, OpenOrder, OpenOrderParams, OpenOrdersResponse, OrderBookSummary, OrderMarketCancelParams, OrderPayload, OrderResponse, OrderScoring, OrderScoringParams, OrderType, OrdersScoring, OrdersScoringParams, PaginationPayload, PreMigrationOrdersResponse, PriceHistoryFilterParams, ReadonlyApiKeyResponse, RewardsPercentages, TickSize, TickSizes, TotalUserEarning, Trade, TradeParams, TradesPaginatedResponse, UserEarning, UserRewardsEarning } from "./types/clob.js";
|
|
4
4
|
import { UserMarketOrderV1, UserOrderV1 } from "./types/ordersV1.js";
|
|
5
5
|
import { UserMarketOrderV2, UserOrderV2 } from "./types/ordersV2.js";
|
|
6
6
|
import { ExchangeV3OrderAmounts } from "./types/ordersV3.js";
|
|
@@ -43,6 +43,8 @@ declare class ClobClient {
|
|
|
43
43
|
readonly signatureType: SignatureTypeV2;
|
|
44
44
|
readonly funderAddress?: string;
|
|
45
45
|
private cachedVersion?;
|
|
46
|
+
private versionRequest?;
|
|
47
|
+
private readonly marketInfoRequests;
|
|
46
48
|
readonly retryOnError?: boolean;
|
|
47
49
|
readonly throwOnError?: boolean;
|
|
48
50
|
readonly feeSlippage: number;
|
|
@@ -65,14 +67,28 @@ declare class ClobClient {
|
|
|
65
67
|
heartbeat_id: string;
|
|
66
68
|
error_msg?: string;
|
|
67
69
|
}>;
|
|
70
|
+
/**
|
|
71
|
+
* Fetches the current order version from the server and adopts it for the
|
|
72
|
+
* orders this client signs afterwards. Joins a version request that is
|
|
73
|
+
* already in flight. An error response yields the default version 2, which
|
|
74
|
+
* the first order corrects through the order version mismatch recovery.
|
|
75
|
+
* Throws ApiError when the client was created with throwOnError.
|
|
76
|
+
*/
|
|
68
77
|
getVersion(): Promise<number>;
|
|
78
|
+
private startVersionRequest;
|
|
69
79
|
getServerTime(): Promise<number>;
|
|
70
80
|
getSamplingSimplifiedMarkets(next_cursor?: string): Promise<PaginationPayload>;
|
|
71
81
|
getSamplingMarkets(next_cursor?: string): Promise<PaginationPayload>;
|
|
72
82
|
getSimplifiedMarkets(next_cursor?: string): Promise<PaginationPayload>;
|
|
73
83
|
getMarkets(next_cursor?: string): Promise<PaginationPayload>;
|
|
74
84
|
getMarket(conditionID: string): Promise<any>;
|
|
85
|
+
/**
|
|
86
|
+
* Fetches the market parameters for a condition and caches the tick size,
|
|
87
|
+
* neg-risk flag, and fee details of both outcomes for later orders. Every
|
|
88
|
+
* call refreshes the caches. Concurrent calls for a condition share one request.
|
|
89
|
+
*/
|
|
75
90
|
getClobMarketInfo(conditionID: string): Promise<MarketDetails>;
|
|
91
|
+
private fetchClobMarketInfo;
|
|
76
92
|
getOrderBook(tokenID: string): Promise<OrderBookSummary>;
|
|
77
93
|
getOrderBooks(params: BookParams[]): Promise<OrderBookSummary[]>;
|
|
78
94
|
getTickSize(tokenID: string): Promise<TickSize>;
|
|
@@ -124,12 +140,22 @@ declare class ClobClient {
|
|
|
124
140
|
createOrder(userOrder: UserOrderV1 | UserOrderV2, options?: Partial<CreateOrderOptions>): Promise<SignedOrder>;
|
|
125
141
|
createMarketOrder(userMarketOrder: UserMarketOrderV1 | UserMarketOrderV2, options?: Partial<CreateOrderOptions>): Promise<SignedOrder>;
|
|
126
142
|
createExchangeV3OrderFromAmounts(userOrder: ExchangeV3OrderAmounts): Promise<SignedOrder>;
|
|
127
|
-
createAndPostOrder<T extends OrderType.GTC | OrderType.GTD = OrderType.GTC>(userOrder: UserOrderV1 | UserOrderV2, options?: Partial<CreateOrderOptions>, orderType?: T, postOnly?: boolean, deferExec?: boolean): Promise<
|
|
128
|
-
createAndPostMarketOrder<T extends OrderType.FOK | OrderType.FAK = OrderType.FOK>(userMarketOrder: UserMarketOrderV1 | UserMarketOrderV2, options?: Partial<CreateOrderOptions>, orderType?: T, deferExec?: boolean): Promise<
|
|
143
|
+
createAndPostOrder<T extends OrderType.GTC | OrderType.GTD = OrderType.GTC>(userOrder: UserOrderV1 | UserOrderV2, options?: Partial<CreateOrderOptions>, orderType?: T, postOnly?: boolean, deferExec?: boolean): Promise<OrderResponse>;
|
|
144
|
+
createAndPostMarketOrder<T extends OrderType.FOK | OrderType.FAK = OrderType.FOK>(userMarketOrder: UserMarketOrderV1 | UserMarketOrderV2, options?: Partial<CreateOrderOptions>, orderType?: T, deferExec?: boolean): Promise<OrderResponse>;
|
|
129
145
|
getOpenOrders(params?: OpenOrderParams, only_first_page?: boolean, next_cursor?: string): Promise<OpenOrdersResponse>;
|
|
130
146
|
getPreMigrationOrders(only_first_page?: boolean, next_cursor?: string): Promise<PreMigrationOrdersResponse>;
|
|
131
|
-
|
|
132
|
-
|
|
147
|
+
/**
|
|
148
|
+
* Posts an order to the CLOB.
|
|
149
|
+
*
|
|
150
|
+
* When the order matches, the response carries the settlement transaction
|
|
151
|
+
* hashes of its fills in `transactionsHashes`, resolved on a best-effort
|
|
152
|
+
* basis. If a hash is not available yet, the fill's trade can be followed
|
|
153
|
+
* via `tradeIDs`.
|
|
154
|
+
*/
|
|
155
|
+
postOrder<T extends OrderType = OrderType.GTC>(order: SignedOrder, orderType?: T, postOnly?: boolean, deferExec?: boolean): Promise<OrderResponse>;
|
|
156
|
+
postOrders(args: PostOrdersArgs[], postOnly?: boolean, deferExec?: boolean): Promise<OrderResponse[]>;
|
|
157
|
+
private waitForResolvedTrades;
|
|
158
|
+
private resolveTransactionsHashes;
|
|
133
159
|
cancelOrder(payload: OrderPayload): Promise<any>;
|
|
134
160
|
cancelOrders(ordersHashes: string[]): Promise<any>;
|
|
135
161
|
cancelAll(): Promise<any>;
|
package/dist/client.js
CHANGED
|
@@ -17,6 +17,11 @@ import { ROUNDING_CONFIG } from "./order-builder/helpers/roundingConfig.js";
|
|
|
17
17
|
import { OrderBuilder } from "./order-builder/orderBuilder.js";
|
|
18
18
|
|
|
19
19
|
//#region src/client.ts
|
|
20
|
+
const RESOLVE_TRADES_TIMEOUT_MS = 3e4;
|
|
21
|
+
const RESOLVE_TRADES_POLL_INTERVAL_MS = 250;
|
|
22
|
+
const FAILED_TRADE_STATUS = "FAILED";
|
|
23
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
24
|
+
const isTradeResolved = (trade) => trade.status.toUpperCase() === FAILED_TRADE_STATUS || Boolean(trade.transaction_hash && trade.transaction_hash.length > 0);
|
|
20
25
|
var ClobClient = class {
|
|
21
26
|
host;
|
|
22
27
|
chainId;
|
|
@@ -34,6 +39,8 @@ var ClobClient = class {
|
|
|
34
39
|
signatureType;
|
|
35
40
|
funderAddress;
|
|
36
41
|
cachedVersion;
|
|
42
|
+
versionRequest;
|
|
43
|
+
marketInfoRequests = /* @__PURE__ */ new Map();
|
|
37
44
|
retryOnError;
|
|
38
45
|
throwOnError;
|
|
39
46
|
feeSlippage;
|
|
@@ -74,8 +81,26 @@ var ClobClient = class {
|
|
|
74
81
|
data: { heartbeat_id: heartbeatId }
|
|
75
82
|
});
|
|
76
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Fetches the current order version from the server and adopts it for the
|
|
86
|
+
* orders this client signs afterwards. Joins a version request that is
|
|
87
|
+
* already in flight. An error response yields the default version 2, which
|
|
88
|
+
* the first order corrects through the order version mismatch recovery.
|
|
89
|
+
* Throws ApiError when the client was created with throwOnError.
|
|
90
|
+
*/
|
|
77
91
|
async getVersion() {
|
|
78
|
-
return
|
|
92
|
+
return this.versionRequest ?? this.startVersionRequest();
|
|
93
|
+
}
|
|
94
|
+
startVersionRequest() {
|
|
95
|
+
const request = this.get(`${this.host}/version`).then((response) => {
|
|
96
|
+
const version = response?.version ?? 2;
|
|
97
|
+
this.cachedVersion = version;
|
|
98
|
+
return version;
|
|
99
|
+
}).finally(() => {
|
|
100
|
+
if (this.versionRequest === request) this.versionRequest = void 0;
|
|
101
|
+
});
|
|
102
|
+
this.versionRequest = request;
|
|
103
|
+
return request;
|
|
79
104
|
}
|
|
80
105
|
async getServerTime() {
|
|
81
106
|
return this.get(`${this.host}${TIME}`);
|
|
@@ -95,7 +120,23 @@ var ClobClient = class {
|
|
|
95
120
|
async getMarket(conditionID) {
|
|
96
121
|
return this.get(`${this.host}${GET_MARKET}${conditionID}`);
|
|
97
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Fetches the market parameters for a condition and caches the tick size,
|
|
125
|
+
* neg-risk flag, and fee details of both outcomes for later orders. Every
|
|
126
|
+
* call refreshes the caches. Concurrent calls for a condition share one request.
|
|
127
|
+
*/
|
|
98
128
|
async getClobMarketInfo(conditionID) {
|
|
129
|
+
const pending = this.marketInfoRequests.get(conditionID);
|
|
130
|
+
if (pending) return pending;
|
|
131
|
+
const request = this.fetchClobMarketInfo(conditionID);
|
|
132
|
+
this.marketInfoRequests.set(conditionID, request);
|
|
133
|
+
try {
|
|
134
|
+
return await request;
|
|
135
|
+
} finally {
|
|
136
|
+
this.marketInfoRequests.delete(conditionID);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
async fetchClobMarketInfo(conditionID) {
|
|
99
140
|
const result = await this.get(`${this.host}${GET_CLOB_MARKET}${conditionID}`);
|
|
100
141
|
if (!result?.t) throw new Error(`failed to fetch market info for condition id ${conditionID}`);
|
|
101
142
|
for (const token of result.t) {
|
|
@@ -472,20 +513,16 @@ var ClobClient = class {
|
|
|
472
513
|
return this.orderBuilder.buildExchangeV3OrderFromAmounts(orderToSign);
|
|
473
514
|
}
|
|
474
515
|
async createAndPostOrder(userOrder, options, orderType = OrderType.GTC, postOnly = false, deferExec = false) {
|
|
475
|
-
|
|
476
|
-
await this._retryOnVersionUpdate(async () => {
|
|
516
|
+
return this._retryOnVersionUpdate(async () => {
|
|
477
517
|
const order = await this.createOrder(userOrder, options);
|
|
478
|
-
|
|
518
|
+
return this.postOrder(order, orderType, postOnly, deferExec);
|
|
479
519
|
});
|
|
480
|
-
return postOrderResponse;
|
|
481
520
|
}
|
|
482
521
|
async createAndPostMarketOrder(userMarketOrder, options, orderType = OrderType.FOK, deferExec = false) {
|
|
483
|
-
|
|
484
|
-
await this._retryOnVersionUpdate(async () => {
|
|
522
|
+
return this._retryOnVersionUpdate(async () => {
|
|
485
523
|
const order = await this.createMarketOrder(userMarketOrder, options);
|
|
486
|
-
|
|
524
|
+
return this.postOrder(order, orderType, false, deferExec);
|
|
487
525
|
});
|
|
488
|
-
return postOrderMarketResponse;
|
|
489
526
|
}
|
|
490
527
|
async getOpenOrders(params, only_first_page = false, next_cursor) {
|
|
491
528
|
this.canL2Auth();
|
|
@@ -532,6 +569,14 @@ var ClobClient = class {
|
|
|
532
569
|
}
|
|
533
570
|
return results;
|
|
534
571
|
}
|
|
572
|
+
/**
|
|
573
|
+
* Posts an order to the CLOB.
|
|
574
|
+
*
|
|
575
|
+
* When the order matches, the response carries the settlement transaction
|
|
576
|
+
* hashes of its fills in `transactionsHashes`, resolved on a best-effort
|
|
577
|
+
* basis. If a hash is not available yet, the fill's trade can be followed
|
|
578
|
+
* via `tradeIDs`.
|
|
579
|
+
*/
|
|
535
580
|
async postOrder(order, orderType = OrderType.GTC, postOnly = false, deferExec = false) {
|
|
536
581
|
this.canL2Auth();
|
|
537
582
|
if (postOnly && (orderType === OrderType.FOK || orderType === OrderType.FAK)) throw new Error("postOnly is not supported for FOK/FAK orders");
|
|
@@ -548,7 +593,9 @@ var ClobClient = class {
|
|
|
548
593
|
data: orderPayload
|
|
549
594
|
}, true);
|
|
550
595
|
if (this._isOrderVersionMismatch(res)) await this.resolveVersion(true);
|
|
551
|
-
|
|
596
|
+
const response = this.throwIfError(res);
|
|
597
|
+
if (deferExec) return response;
|
|
598
|
+
return this.resolveTransactionsHashes(response);
|
|
552
599
|
}
|
|
553
600
|
async postOrders(args, postOnly = false, deferExec = false) {
|
|
554
601
|
this.canL2Auth();
|
|
@@ -571,7 +618,34 @@ var ClobClient = class {
|
|
|
571
618
|
data: ordersPayload
|
|
572
619
|
}, true);
|
|
573
620
|
if (this._isOrderVersionMismatch(res)) await this.resolveVersion(true);
|
|
574
|
-
|
|
621
|
+
const responses = this.throwIfError(res);
|
|
622
|
+
if (deferExec || !Array.isArray(responses)) return responses;
|
|
623
|
+
return Promise.all(responses.map((response) => this.resolveTransactionsHashes(response)));
|
|
624
|
+
}
|
|
625
|
+
async waitForResolvedTrades(tradeIDs) {
|
|
626
|
+
const ids = [...new Set(tradeIDs.filter((id) => id.length > 0))];
|
|
627
|
+
if (ids.length === 0) return [];
|
|
628
|
+
const resolved = /* @__PURE__ */ new Map();
|
|
629
|
+
const requestedIDs = new Set(ids);
|
|
630
|
+
const deadline = Date.now() + RESOLVE_TRADES_TIMEOUT_MS;
|
|
631
|
+
for (;;) {
|
|
632
|
+
const pending = ids.filter((id) => !resolved.has(id));
|
|
633
|
+
const pages = await Promise.all(pending.map((id) => this.getTrades({ id }, true).catch(() => [])));
|
|
634
|
+
for (const trades of pages) for (const trade of trades) if (isTradeResolved(trade) && requestedIDs.has(trade.id)) resolved.set(trade.id, trade);
|
|
635
|
+
if (ids.every((id) => resolved.has(id)) || Date.now() >= deadline) return ids.map((id) => resolved.get(id)).filter((trade) => trade !== void 0);
|
|
636
|
+
await sleep(RESOLVE_TRADES_POLL_INTERVAL_MS);
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
async resolveTransactionsHashes(response) {
|
|
640
|
+
if (response.transactionsHashes && response.transactionsHashes.length > 0) return response;
|
|
641
|
+
const tradeIDs = response.tradeIDs ?? [];
|
|
642
|
+
if (tradeIDs.length === 0) return response;
|
|
643
|
+
const transactionsHashes = (await this.waitForResolvedTrades(tradeIDs)).filter((trade) => trade.status.toUpperCase() !== FAILED_TRADE_STATUS).map((trade) => trade.transaction_hash).filter((hash) => Boolean(hash));
|
|
644
|
+
if (transactionsHashes.length === 0) return response;
|
|
645
|
+
return {
|
|
646
|
+
...response,
|
|
647
|
+
transactionsHashes
|
|
648
|
+
};
|
|
575
649
|
}
|
|
576
650
|
async cancelOrder(payload) {
|
|
577
651
|
this.canL2Auth();
|
|
@@ -828,6 +902,7 @@ var ClobClient = class {
|
|
|
828
902
|
if (!result?.condition_id) throw new Error(`failed to resolve condition id for token ${tokenID}`);
|
|
829
903
|
this.tokenConditionMap[tokenID] = result.condition_id;
|
|
830
904
|
}
|
|
905
|
+
if (tokenID in this.feeInfos) return;
|
|
831
906
|
await this.getClobMarketInfo(this.tokenConditionMap[tokenID]);
|
|
832
907
|
}
|
|
833
908
|
async ensureBuilderFeeRateCached(builderCode) {
|
|
@@ -853,16 +928,18 @@ var ClobClient = class {
|
|
|
853
928
|
}
|
|
854
929
|
async resolveVersion(forceUpdate = false) {
|
|
855
930
|
if (!forceUpdate && this.cachedVersion !== void 0) return this.cachedVersion;
|
|
856
|
-
|
|
857
|
-
this.
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
931
|
+
if (!forceUpdate && this.versionRequest) return this.versionRequest;
|
|
932
|
+
return this.startVersionRequest();
|
|
933
|
+
}
|
|
934
|
+
async _retryOnVersionUpdate(attempt) {
|
|
935
|
+
try {
|
|
936
|
+
const response = await attempt();
|
|
937
|
+
if (!this._isOrderVersionMismatch(response)) return response;
|
|
938
|
+
} catch (err) {
|
|
939
|
+
const data = err instanceof ApiError ? err.data : void 0;
|
|
940
|
+
if (!this._isOrderVersionMismatch(data)) throw err;
|
|
865
941
|
}
|
|
942
|
+
return attempt();
|
|
866
943
|
}
|
|
867
944
|
_isOrderVersionMismatch(resp) {
|
|
868
945
|
const error = resp?.error;
|