@kuestcom/clob-client 5.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +101 -0
  3. package/dist/client.d.ts +164 -0
  4. package/dist/client.js +967 -0
  5. package/dist/client.js.map +1 -0
  6. package/dist/config.d.ts +12 -0
  7. package/dist/config.js +28 -0
  8. package/dist/config.js.map +1 -0
  9. package/dist/constants.d.ts +3 -0
  10. package/dist/constants.js +7 -0
  11. package/dist/constants.js.map +1 -0
  12. package/dist/endpoints.d.ts +67 -0
  13. package/dist/endpoints.js +82 -0
  14. package/dist/endpoints.js.map +1 -0
  15. package/dist/errors.d.ts +10 -0
  16. package/dist/errors.js +16 -0
  17. package/dist/errors.js.map +1 -0
  18. package/dist/headers/index.d.ts +6 -0
  19. package/dist/headers/index.js +42 -0
  20. package/dist/headers/index.js.map +1 -0
  21. package/dist/http-helpers/index.d.ts +21 -0
  22. package/dist/http-helpers/index.js +151 -0
  23. package/dist/http-helpers/index.js.map +1 -0
  24. package/dist/index.d.ts +11 -0
  25. package/dist/index.js +10 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/order-builder/builder.d.ts +29 -0
  28. package/dist/order-builder/builder.js +52 -0
  29. package/dist/order-builder/builder.js.map +1 -0
  30. package/dist/order-builder/helpers.d.ts +50 -0
  31. package/dist/order-builder/helpers.js +276 -0
  32. package/dist/order-builder/helpers.js.map +1 -0
  33. package/dist/order-builder/index.d.ts +1 -0
  34. package/dist/order-builder/index.js +2 -0
  35. package/dist/order-builder/index.js.map +1 -0
  36. package/dist/order-utils/exchange.order.builder.d.ts +31 -0
  37. package/dist/order-utils/exchange.order.builder.js +120 -0
  38. package/dist/order-utils/exchange.order.builder.js.map +1 -0
  39. package/dist/order-utils/exchange.order.const.d.ts +13 -0
  40. package/dist/order-utils/exchange.order.const.js +28 -0
  41. package/dist/order-utils/exchange.order.const.js.map +1 -0
  42. package/dist/order-utils/index.d.ts +6 -0
  43. package/dist/order-utils/index.js +7 -0
  44. package/dist/order-utils/index.js.map +1 -0
  45. package/dist/order-utils/model/eip712.model.d.ts +25 -0
  46. package/dist/order-utils/model/eip712.model.js +2 -0
  47. package/dist/order-utils/model/eip712.model.js.map +1 -0
  48. package/dist/order-utils/model/order-side.model.d.ts +4 -0
  49. package/dist/order-utils/model/order-side.model.js +6 -0
  50. package/dist/order-utils/model/order-side.model.js.map +1 -0
  51. package/dist/order-utils/model/order.model.d.ts +112 -0
  52. package/dist/order-utils/model/order.model.js +2 -0
  53. package/dist/order-utils/model/order.model.js.map +1 -0
  54. package/dist/order-utils/model/signature-types.model.d.ts +14 -0
  55. package/dist/order-utils/model/signature-types.model.js +16 -0
  56. package/dist/order-utils/model/signature-types.model.js.map +1 -0
  57. package/dist/order-utils/utils.d.ts +1 -0
  58. package/dist/order-utils/utils.js +4 -0
  59. package/dist/order-utils/utils.js.map +1 -0
  60. package/dist/rfq-client.d.ts +64 -0
  61. package/dist/rfq-client.js +403 -0
  62. package/dist/rfq-client.js.map +1 -0
  63. package/dist/rfq-deps.d.ts +44 -0
  64. package/dist/rfq-deps.js +2 -0
  65. package/dist/rfq-deps.js.map +1 -0
  66. package/dist/signer.d.ts +22 -0
  67. package/dist/signer.js +50 -0
  68. package/dist/signer.js.map +1 -0
  69. package/dist/signing/constants.d.ts +14 -0
  70. package/dist/signing/constants.js +16 -0
  71. package/dist/signing/constants.js.map +1 -0
  72. package/dist/signing/eip712.d.ts +9 -0
  73. package/dist/signing/eip712.js +40 -0
  74. package/dist/signing/eip712.js.map +1 -0
  75. package/dist/signing/hmac.d.ts +9 -0
  76. package/dist/signing/hmac.js +58 -0
  77. package/dist/signing/hmac.js.map +1 -0
  78. package/dist/signing/index.d.ts +2 -0
  79. package/dist/signing/index.js +3 -0
  80. package/dist/signing/index.js.map +1 -0
  81. package/dist/types.d.ts +667 -0
  82. package/dist/types.js +37 -0
  83. package/dist/types.js.map +1 -0
  84. package/dist/utilities.d.ts +16 -0
  85. package/dist/utilities.js +93 -0
  86. package/dist/utilities.js.map +1 -0
  87. package/package.json +85 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Polymarket
4
+ Copyright (c) 2026 Kuest
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,101 @@
1
+ # Kuest CLOB Client
2
+
3
+ <a href='https://www.npmjs.com/package/@kuestcom/clob-client'>
4
+ <img src='https://img.shields.io/npm/v/@kuestcom/clob-client.svg' alt='NPM'/>
5
+ </a>
6
+
7
+ Typescript client for the Kuest CLOB
8
+
9
+ ### Usage
10
+
11
+ ```ts
12
+ // npm install @kuestcom/clob-client
13
+ // npm install ethers
14
+ // Client initialization example and dumping API Keys
15
+
16
+ import { ApiKeyCreds, ClobClient, OrderType, Side, } from "@kuestcom/clob-client";
17
+ import { Wallet } from "@ethersproject/wallet";
18
+
19
+ const host = 'https://clob.kuest.com';
20
+ const funder = ''; // This is your Kuest Profile Address, where you send UDSC to.
21
+ const signer = new Wallet(""); // This is your Private Key.
22
+
23
+
24
+ // In general don't create a new API key, always derive or createOrDerive
25
+ const creds = new ClobClient(host, 80002, signer).createOrDeriveApiKey();
26
+
27
+ //0: Browser Wallet(Metamask, Coinbase Wallet, etc)
28
+ //1: Magic/Email Login
29
+ const signatureType = 1;
30
+ (async () => {
31
+ const clobClient = new ClobClient(host, 80002, signer, await creds, signatureType, funder);
32
+ const resp2 = await clobClient.createAndPostOrder(
33
+ {
34
+ tokenID: "", //Use https://docs.kuest.com/developers/gamma-markets-api/get-markets to grab a sample token
35
+ price: 0.01,
36
+ side: Side.BUY,
37
+ size: 5,
38
+ },
39
+ { tickSize: "0.001",negRisk: false }, //You'll need to adjust these based on the market. Get the tickSize and negRisk T/F from the get-markets above
40
+ //{ tickSize: "0.001",negRisk: true },
41
+
42
+ OrderType.GTC,
43
+ );
44
+ console.log(resp2)
45
+ })();
46
+ ```
47
+
48
+ See [examples](examples/) for more information
49
+
50
+ ### Builder signing
51
+
52
+ Builder signing: disabled.
53
+ To enable later, remove line 145 of `src/client.ts`: `const BUILDER_SIGNING_ENABLED = false;`
54
+
55
+ ### Using viem WalletClient
56
+
57
+ ```ts
58
+ import { ClobClient } from "@kuestcom/clob-client";
59
+ import { createWalletClient, http } from "viem";
60
+ import { polygonAmoy } from "viem/chains";
61
+ import { privateKeyToAccount } from "viem/accounts";
62
+
63
+ const host = "https://clob.kuest.com";
64
+ const account = privateKeyToAccount("0x...");
65
+ const walletClient = createWalletClient({
66
+ account,
67
+ chain: polygonAmoy,
68
+ transport: http(),
69
+ });
70
+
71
+ const clobClient = new ClobClient(host, 80002, walletClient);
72
+ ```
73
+
74
+ ### Error Handling
75
+
76
+ By default, API errors are returned as `{ error: "...", status: ... }` objects. To have the client throw errors instead, pass `throwOnError: true` as the last constructor argument:
77
+
78
+ ```ts
79
+ import { ClobClient, ApiError } from "@kuestcom/clob-client";
80
+
81
+ const clobClient = new ClobClient(
82
+ host, 80002, signer, await creds, signatureType, funder,
83
+ undefined, // geoBlockToken
84
+ undefined, // useServerTime
85
+ undefined, // builderConfig
86
+ undefined, // getSigner
87
+ undefined, // retryOnError
88
+ undefined, // tickSizeTtlMs
89
+ true, // throwOnError
90
+ );
91
+
92
+ try {
93
+ const book = await clobClient.getOrderBook(tokenID);
94
+ } catch (e) {
95
+ if (e instanceof ApiError) {
96
+ console.log(e.message); // "No orderbook exists for the requested token id"
97
+ console.log(e.status); // 404
98
+ console.log(e.data); // full error response object from the API
99
+ }
100
+ }
101
+ ```
@@ -0,0 +1,164 @@
1
+ import type { BuilderConfig } from "@kuestcom/builder-signing-sdk";
2
+ import type { RequestOptions } from "./http-helpers/index.ts";
3
+ import { OrderBuilder } from "./order-builder/builder.ts";
4
+ import type { SignatureType, SignedOrder } from "./order-utils/index.ts";
5
+ import type { IRfqClient } from "./rfq-deps.ts";
6
+ import type { ClobSigner } from "./signer.ts";
7
+ import type { ApiKeyCreds, ApiKeysResponse, BalanceAllowanceParams, BalanceAllowanceResponse, BanStatus, BookParams, BuilderApiKey, BuilderApiKeyResponse, BuilderTrade, Chain, CreateOrderOptions, DropNotificationParams, FeeRates, HeartbeatResponse, MarketPrice, MarketReward, MarketTradeEvent, NegRisk, Notification, OpenOrder, OpenOrderParams, OpenOrdersResponse, OrderBookSummary, OrderMarketCancelParams, OrderPayload, OrderScoring, OrderScoringParams, OrdersScoring, OrdersScoringParams, PaginationPayload, PostOrdersArgs, PriceHistoryFilterParams, ReadonlyApiKeyResponse, RewardsPercentages, TickSize, TickSizes, TotalUserEarning, Trade, TradeParams, UserEarning, UserMarketOrder, UserOrder, UserRewardsEarning } from "./types.ts";
8
+ import { OrderType, Side } from "./types.ts";
9
+ export declare class ClobClient {
10
+ readonly host: string;
11
+ readonly chainId: Chain;
12
+ readonly signer?: ClobSigner;
13
+ readonly creds?: ApiKeyCreds;
14
+ readonly orderBuilder: OrderBuilder;
15
+ readonly tickSizes: TickSizes;
16
+ readonly negRisk: NegRisk;
17
+ readonly feeRates: FeeRates;
18
+ readonly geoBlockToken?: string;
19
+ readonly useServerTime?: boolean;
20
+ readonly builderConfig?: BuilderConfig;
21
+ readonly rfq: IRfqClient;
22
+ readonly retryOnError?: boolean;
23
+ readonly throwOnError: boolean;
24
+ private tickSizeTimestamps;
25
+ private readonly tickSizeTtlMs;
26
+ constructor(host: string, chainId: Chain, signer?: ClobSigner, creds?: ApiKeyCreds, signatureType?: SignatureType, funderAddress?: string, geoBlockToken?: string, useServerTime?: boolean, builderConfig?: BuilderConfig, getSigner?: () => Promise<ClobSigner> | ClobSigner, retryOnError?: boolean, tickSizeTtlMs?: number, throwOnError?: boolean);
27
+ getOk(): Promise<any>;
28
+ getServerTime(): Promise<number>;
29
+ getSamplingSimplifiedMarkets(next_cursor?: string): Promise<PaginationPayload>;
30
+ getSamplingMarkets(next_cursor?: string): Promise<PaginationPayload>;
31
+ getSimplifiedMarkets(next_cursor?: string): Promise<PaginationPayload>;
32
+ getMarkets(next_cursor?: string): Promise<PaginationPayload>;
33
+ getMarket(conditionID: string): Promise<any>;
34
+ getOrderBook(tokenID: string): Promise<OrderBookSummary>;
35
+ getOrderBooks(params: BookParams[]): Promise<OrderBookSummary[]>;
36
+ getTickSize(tokenID: string): Promise<TickSize>;
37
+ /**
38
+ * Clears the tick size cache, forcing fresh fetches on the next access.
39
+ * @param tokenID - If provided, only clears the cache for this token. Otherwise clears all.
40
+ */
41
+ clearTickSizeCache(tokenID?: string): void;
42
+ getNegRisk(tokenID: string): Promise<boolean>;
43
+ getFeeRateBps(tokenID: string): Promise<number>;
44
+ /**
45
+ * Calculates the hash for the given orderbook
46
+ * @param orderbook
47
+ * @returns
48
+ */
49
+ getOrderBookHash(orderbook: OrderBookSummary): Promise<string>;
50
+ getMidpoint(tokenID: string): Promise<any>;
51
+ getMidpoints(params: BookParams[]): Promise<any>;
52
+ getPrice(tokenID: string, side: string): Promise<any>;
53
+ getPrices(params: BookParams[]): Promise<any>;
54
+ getSpread(tokenID: string): Promise<any>;
55
+ getSpreads(params: BookParams[]): Promise<any>;
56
+ getLastTradePrice(tokenID: string): Promise<any>;
57
+ getLastTradesPrices(params: BookParams[]): Promise<any>;
58
+ getPricesHistory(params: PriceHistoryFilterParams): Promise<MarketPrice[]>;
59
+ /**
60
+ * Creates a new API key for a user
61
+ * @param nonce
62
+ * @returns ApiKeyCreds
63
+ */
64
+ createApiKey(nonce?: number): Promise<ApiKeyCreds>;
65
+ /**
66
+ * Derives an existing API key for a user
67
+ * @param nonce
68
+ * @returns ApiKeyCreds
69
+ */
70
+ deriveApiKey(nonce?: number): Promise<ApiKeyCreds>;
71
+ createOrDeriveApiKey(nonce?: number): Promise<ApiKeyCreds>;
72
+ getApiKeys(): Promise<ApiKeysResponse>;
73
+ getClosedOnlyMode(): Promise<BanStatus>;
74
+ deleteApiKey(): Promise<any>;
75
+ /**
76
+ * Creates a new readonly API key for a user
77
+ * @returns ReadonlyApiKeyResponse
78
+ */
79
+ createReadonlyApiKey(): Promise<ReadonlyApiKeyResponse>;
80
+ getReadonlyApiKeys(): Promise<string[]>;
81
+ /**
82
+ * Deletes a readonly API key for a user
83
+ * @param key The readonly API key to delete
84
+ * @returns boolean
85
+ */
86
+ deleteReadonlyApiKey(key: string): Promise<boolean>;
87
+ /**
88
+ * Validates a readonly API key for a given address
89
+ * @param address The wallet address
90
+ * @param key The readonly API key to validate
91
+ * @returns string
92
+ */
93
+ validateReadonlyApiKey(address: string, key: string): Promise<string>;
94
+ getOrder(orderID: string): Promise<OpenOrder>;
95
+ getTrades(params?: TradeParams, only_first_page?: boolean, next_cursor?: string): Promise<Trade[]>;
96
+ getTradesPaginated(params?: TradeParams, next_cursor?: string): Promise<{
97
+ trades: Trade[];
98
+ next_cursor: string;
99
+ limit: number;
100
+ count: number;
101
+ }>;
102
+ getBuilderTrades(params?: TradeParams, next_cursor?: string): Promise<{
103
+ trades: BuilderTrade[];
104
+ next_cursor: string;
105
+ limit: number;
106
+ count: number;
107
+ }>;
108
+ getNotifications(): Promise<Notification[]>;
109
+ dropNotifications(params?: DropNotificationParams): Promise<void>;
110
+ getBalanceAllowance(params?: BalanceAllowanceParams): Promise<BalanceAllowanceResponse>;
111
+ updateBalanceAllowance(params?: BalanceAllowanceParams): Promise<void>;
112
+ createOrder(userOrder: UserOrder, options?: Partial<CreateOrderOptions>): Promise<SignedOrder>;
113
+ createMarketOrder(userMarketOrder: UserMarketOrder, options?: Partial<CreateOrderOptions>): Promise<SignedOrder>;
114
+ createAndPostOrder<T extends OrderType.GTC | OrderType.GTD = OrderType.GTC>(userOrder: UserOrder, options?: Partial<CreateOrderOptions>, orderType?: T, deferExec?: boolean, postOnly?: boolean): Promise<any>;
115
+ createAndPostMarketOrder<T extends OrderType.FOK | OrderType.FAK = OrderType.FOK>(userMarketOrder: UserMarketOrder, options?: Partial<CreateOrderOptions>, orderType?: T, deferExec?: boolean): Promise<any>;
116
+ getOpenOrders(params?: OpenOrderParams, only_first_page?: boolean, next_cursor?: string): Promise<OpenOrdersResponse>;
117
+ postOrder<T extends OrderType = OrderType.GTC>(order: SignedOrder, orderType?: T, deferExec?: boolean, postOnly?: boolean): Promise<any>;
118
+ postOrders(args: PostOrdersArgs[], deferExec?: boolean, defaultPostOnly?: boolean): Promise<any>;
119
+ cancelOrder(payload: OrderPayload): Promise<any>;
120
+ cancelOrders(ordersHashes: string[]): Promise<any>;
121
+ cancelAll(): Promise<any>;
122
+ /**
123
+ * Sends a heartbeat to the server to keep the session active.
124
+ *
125
+ * If heartbeats are started and one isn't sent within 10s, all orders will be cancelled.
126
+ * Requires Level 2 authentication.
127
+ *
128
+ * Pass the previously returned `heartbeat_id` to chain heartbeats.
129
+ * Pass `undefined`/`null` to start a new heartbeat chain.
130
+ */
131
+ postHeartbeat(heartbeatId?: string | null): Promise<HeartbeatResponse>;
132
+ cancelMarketOrders(payload: OrderMarketCancelParams): Promise<any>;
133
+ isOrderScoring(params?: OrderScoringParams): Promise<OrderScoring>;
134
+ areOrdersScoring(params?: OrdersScoringParams): Promise<OrdersScoring>;
135
+ getEarningsForUserForDay(date: string): Promise<UserEarning[]>;
136
+ getTotalEarningsForUserForDay(date: string): Promise<TotalUserEarning[]>;
137
+ getUserEarningsAndMarketsConfig(date: string, order_by?: string, position?: string, no_competition?: boolean): Promise<UserRewardsEarning[]>;
138
+ getRewardPercentages(): Promise<RewardsPercentages>;
139
+ getCurrentRewards(): Promise<MarketReward[]>;
140
+ getRawRewardsForMarket(conditionId: string): Promise<MarketReward[]>;
141
+ getMarketTradesEvents(conditionID: string): Promise<MarketTradeEvent[]>;
142
+ calculateMarketPrice(tokenID: string, side: Side, amount: number, orderType?: OrderType): Promise<number>;
143
+ createBuilderApiKey(): Promise<BuilderApiKey>;
144
+ getBuilderApiKeys(): Promise<BuilderApiKeyResponse[]>;
145
+ revokeBuilderApiKey(): Promise<any>;
146
+ protected _resolveTickSize(tokenID: string, tickSize?: TickSize): Promise<TickSize>;
147
+ protected get(endpoint: string, options?: RequestOptions): Promise<any>;
148
+ protected post(endpoint: string, options?: RequestOptions): Promise<any>;
149
+ protected put(endpoint: string, options?: RequestOptions): Promise<any>;
150
+ protected del(endpoint: string, options?: RequestOptions): Promise<any>;
151
+ private throwIfError;
152
+ private canL1Auth;
153
+ private canL2Auth;
154
+ private mustBuilderAuth;
155
+ private canBuilderAuth;
156
+ private ensureBuilderSigningEnabled;
157
+ private _resolveFeeRateBps;
158
+ private _generateBuilderHeaders;
159
+ private _getBuilderHeaders;
160
+ /**
161
+ * Opportunistically updates the tick size cache from an order book response.
162
+ */
163
+ private updateTickSizeFromOrderBook;
164
+ }