skewtape 0.1.6 → 0.1.7
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 +4 -13
- package/dist/cjs/client.d.ts +37 -6
- package/dist/cjs/client.js +42 -13
- package/dist/cjs/fees.d.ts +4 -2
- package/dist/cjs/fees.js +48 -8
- package/dist/cjs/index.d.ts +2 -2
- package/dist/cjs/index.js +2 -5
- package/dist/cjs/kalshi.d.ts +3 -3
- package/dist/cjs/kalshi.js +4 -4
- package/dist/cjs/paginated.d.ts +1 -1
- package/dist/cjs/paginated.js +1 -1
- package/dist/cjs/quote.d.ts +1 -12
- package/dist/cjs/quote.js +1 -16
- package/dist/cjs/route.d.ts +6 -65
- package/dist/cjs/route.js +3 -120
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/client.d.ts +37 -6
- package/dist/esm/client.js +42 -13
- package/dist/esm/fees.d.ts +4 -2
- package/dist/esm/fees.js +48 -8
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +2 -2
- package/dist/esm/kalshi.d.ts +3 -3
- package/dist/esm/kalshi.js +4 -4
- package/dist/esm/paginated.d.ts +1 -1
- package/dist/esm/paginated.js +1 -1
- package/dist/esm/quote.d.ts +1 -12
- package/dist/esm/quote.js +0 -14
- package/dist/esm/route.d.ts +6 -65
- package/dist/esm/route.js +2 -117
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +1 -1
- package/src/client.ts +72 -21
- package/src/fees.ts +47 -7
- package/src/generated/schema.d.ts +388 -34
- package/src/index.ts +0 -4
- package/src/kalshi.ts +4 -4
- package/src/paginated.ts +1 -1
- package/src/quote.ts +1 -16
- package/src/route.ts +7 -147
- package/src/version.ts +1 -1
package/README.md
CHANGED
|
@@ -44,12 +44,12 @@ const pairs = await sk.pairs({ minConfidence: 0.9 }).toArray();
|
|
|
44
44
|
|
|
45
45
|
The quickstart above is run against a mock API by the package's tests, so it stays current.
|
|
46
46
|
|
|
47
|
-
- Every list (`markets`, `events`, `pairs`, `fills`, `candles`, `resolutions`, `fees`) returns a `Paginated`: `for await` for every item across pages, `.pages()` for the pages, `.first()` for the first item, `.toArray()` for all of them. Nothing is fetched until you iterate. `markets({
|
|
47
|
+
- Every list (`markets`, `events`, `pairs`, `fills`, `candles`, `resolutions`, `fees`) returns a `Paginated`: `for await` for every item across pages, `.pages()` for the pages, `.first()` for the first item, `.toArray()` for all of them. Nothing is fetched until you iterate. `markets({ ... })` filters on the server: `status` (any of open, closed, resolved and voided), `category` (exact labels, at most 20), `venueEventId` (with `venue`), `closeAfter` and `closeBefore` (close_at at or after the one, before the other), `q` (a keyword search on the question), and `sort` (`venue` by default, `close_at`, `updated_at`, `first_seen_at`) with `order` (`asc` by default, or `desc`). `resolved: true` is `status: ["resolved"]` and `resolved: false` the three others, so it is one request per page; pass `resolved` or `status`, not both. `resolutions({ ... })` takes `resolvedAfter`, `resolvedBefore`, `sort` (`venue` or `resolved_at`) and `order`; `events` and `pairs` take `sort` (`event_id` or `published_at`) and `order`.
|
|
48
48
|
- A `429 rate_limited`, or a `429` with no error body as a proxy sends, is retried with the server's `Retry-After` (three times by default, `maxRetries`). A `429 lookup_rate_limited` (too many invalid keys from your address) throws `AuthenticationError` at once: fix the key. A `429 quota_exceeded` throws `QuotaExceededError` at once, with `resetsAt` and `upgradeUrl`. A request past `timeout` (30 seconds by default) throws a `SkewtapeError`. Any other error throws a `SkewtapeError` subclass (`AuthenticationError`, `ForbiddenPlanError` with `.plan`, `BlockedError` with `.blockReasonCode`, `NotFoundError`, `RateLimitError`, `QuotaExceededError`, `ServerError`), carrying the API's `code`, `message`, `docsUrl` and `requestId`.
|
|
49
49
|
- `sk.download.bundles()` lists the History snapshots and monthly deltas your account may download, and `sk.download.bundle(bundleId, folder)` fetches one whole, resuming a partial download, checking each file's sha256 and the folder's `CHECKSUMS.sha256`; `sk.download.file(bundleId, path, dest)` fetches one file. They need a key on the Builder or Pro plan (a History purchase downloads from the dashboard), and the file host never sees the key. `sk.download(url, dest, { sha256 })` fetches a link you already hold; `sk.download.verify(folder)` checks a folder.
|
|
50
50
|
- Withheld fields read `null` with `blocked` true and `block_reason_code` on the row: see [Data rights and geoblocking](https://docs.skewtape.com/rights).
|
|
51
51
|
- The response types are the API's (`Market`, `MatchedEvent`, `Fill`, ...), exported from the package, generated from the public OpenAPI document into `src/generated/schema.d.ts` and never edited by hand. `AGENTS.md` tells a coding agent how to use the package. The version's major and minor follow the API's version.
|
|
52
|
-
- `sk.quote(eventId, { outcome, side, size })` is the best venue, or split across venues, for a size of one outcome of a matched event once each venue's taker fee is counted ([Quotes](https://docs.skewtape.com/quote)). It places nothing. One metered call reads the quote context (`sk.quoteContext(eventId)` alone); the books are read from each venue, from your machine, with a fetch that never carries your key. Amounts are integers in millionths (`net_micros`, `net_avg_price_micros`, ...). A venue that cannot be reached is left out and named in `skipped`, and none reachable throws `VenueUnreachableError`; members that do not resolve alike throw `RuleMismatchError` unless `allowRuleMismatch`; a venue whose fee is unknown (no fee row, or one the data policy withholds) is never compared with one whose fee is known: when a venue whose fee is known can fill some of the size, it is left out of the plan, quoted alone in `venues` before fees, and `warnings` says so (otherwise they are compared before fees, and `warnings` says the fee is not counted). Kalshi's book is Kalshi's public orderbook, read with no key (a
|
|
52
|
+
- `sk.quote(eventId, { outcome, side, size })` is the best venue, or split across venues, for a size of one outcome of a matched event once each venue's taker fee is counted ([Quotes](https://docs.skewtape.com/quote)). It places nothing. One metered call reads the quote context (`sk.quoteContext(eventId)` alone); the books are read from each venue, from your machine, with a fetch that never carries your key. Amounts are integers in millionths (`net_micros`, `net_avg_price_micros`, ...). A venue that cannot be reached is left out and named in `skipped`, and none reachable throws `VenueUnreachableError`; members that do not resolve alike throw `RuleMismatchError` unless `allowRuleMismatch`; a venue whose fee is unknown (no fee row, or one the data policy withholds) is never compared with one whose fee is known: when a venue whose fee is known can fill some of the size, it is left out of the plan, quoted alone in `venues` before fees, and `warnings` says so (otherwise they are compared before fees, and `warnings` says the fee is not counted). Kalshi's book is Kalshi's public orderbook, read with no key (a member of a venue with no reader, such as the retired `kalshi_dflow`, is left out); any venue's reader can be replaced in `bookReaders`.
|
|
53
53
|
|
|
54
54
|
```ts
|
|
55
55
|
// The best venue, or split, for 100 contracts of "yes" once each taker fee is
|
|
@@ -109,7 +109,7 @@ Skewtape's Kalshi data (markets, fills, candles, resolutions) comes from the cal
|
|
|
109
109
|
const kalshi = sk.kalshi(); // public requests; with your own key: sk.kalshi({ accessKey: keyId, privateKey: pem })
|
|
110
110
|
|
|
111
111
|
// The live Kalshi markets of a matched event, found by the ticker its kalshi
|
|
112
|
-
//
|
|
112
|
+
// members carry.
|
|
113
113
|
const event = await sk.events.get("st_evt_00412");
|
|
114
114
|
for (const market of await kalshi.marketsFor(event)) {
|
|
115
115
|
console.log(market.ticker, market.status, market.yes_bid_dollars, market.yes_ask_dollars);
|
|
@@ -125,7 +125,7 @@ for await (const trade of kalshi.trades({ ticker: "KXKBORFI-26NOV030430SAMKTW-Y"
|
|
|
125
125
|
const sticks = await kalshi.candlesticks("KXKBORFI-26NOV030430SAMKTW-Y", { period: "1h", since });
|
|
126
126
|
```
|
|
127
127
|
|
|
128
|
-
- `kalshi.markets({ status, seriesTicker, eventTicker, tickers })`, `kalshi.market(ticker)`, `kalshi.trades({ ticker, since, until })`, `kalshi.orderbook(ticker, { depth })` and `kalshi.candlesticks(ticker, { period, since, until })` (`1m`, `1h` or `1d`; a Kalshi `1d` stick is a New York day). `kalshi.tickers(event)` and `kalshi.marketsFor(event)` read a matched event's `kalshi`
|
|
128
|
+
- `kalshi.markets({ status, seriesTicker, eventTicker, tickers })`, `kalshi.market(ticker)`, `kalshi.trades({ ticker, since, until })`, `kalshi.orderbook(ticker, { depth })` and `kalshi.candlesticks(ticker, { period, since, until })` (`1m`, `1h` or `1d`; a Kalshi `1d` stick is a New York day). `kalshi.tickers(event)` and `kalshi.marketsFor(event)` read a matched event's `kalshi` members, whose `market_id` is the Kalshi ticker.
|
|
129
129
|
- Prices and counts are Kalshi's own strings; every row keeps the whole JSON object in `raw`.
|
|
130
130
|
- Kalshi serves older trades and settled markets from its `/historical` routes, past a cutoff that moves, and this client does not call them: for that history use `sk.fills` and `sk.markets`.
|
|
131
131
|
- Your key goes in the options, from wherever you keep it; the client reads no environment variable. With one, every request is signed as Kalshi's docs describe (Ed25519 or RSA, through `node:crypto`) and counts against your account's rate-limit tier. Without one the calls are public requests. Kalshi's terms and rate limits apply to them, not your Skewtape plan.
|
|
@@ -148,14 +148,6 @@ const order = route({
|
|
|
148
148
|
const signature = await walletClient.signTypedData(order.typedData); // viem; ethers v6: signer.signTypedData(domain, types, message)
|
|
149
149
|
const body = order.postBody(signature, yourClobApiKeyId); // POST /order, with your CLOB credentials
|
|
150
150
|
|
|
151
|
-
// DFlow (tokenized Kalshi outcome tokens): the GET /order request that returns
|
|
152
|
-
// the unsigned transaction, with your fee and fee account.
|
|
153
|
-
const request = route({
|
|
154
|
-
venue: "kalshi_dflow", inputMint: usdcMint, outputMint: outcomeMint, amount: 25_000_000,
|
|
155
|
-
userPublicKey: yourUsersWallet, platformFeeScale: 50, feeAccount: yourFeeTokenAccount,
|
|
156
|
-
});
|
|
157
|
-
// fetch(request.fullUrl, { headers: { [request.apiKeyHeader]: yourDflowKey } })
|
|
158
|
-
|
|
159
151
|
// Hyperliquid HIP-4 outcomes: an order on side 0 or 1 of an outcome (coin
|
|
160
152
|
// "#960" is outcome 96, side 0), signed by the key that trades (an API wallet).
|
|
161
153
|
const hl = route({
|
|
@@ -173,7 +165,6 @@ const where = await geoblock.polymarket(); // "allowed", "blocked" or "unknown"
|
|
|
173
165
|
```
|
|
174
166
|
|
|
175
167
|
- **Polymarket:** the order is the V2 `Order` (salt, maker, signer, tokenId, makerAmount, takerAmount, side, signatureType, timestamp, metadata, builder), on the exchange's EIP-712 domain: "Polymarket CTF Exchange", version "2" for `ctf` and `neg_risk`, "3" for a Protocol V2 book (`protocol_v2`), Polygon. Prices and sizes are decimal strings, never floats, and amounts follow Polymarket's rounding by tick size. A limit order (`GTC`, `GTD` with `expiration` in Unix seconds) and a market SELL (`FOK`, `FAK`) take `size` in shares; a market BUY takes `amount`, the USD to spend, with `price` the most you pay. `signatureType` is `EOA` (the default; `signer` is the maker), `POLY_PROXY` or `POLY_GNOSIS_SAFE` (pass `signer`). A Deposit Wallet order (`POLY_1271`) is signed through an ERC-7739 wrapper this builder does not produce. `typedDataJson()` gives the JSON `eth_signTypedData_v4` takes. Builder fee rates are set on your Polymarket profile, not in the order.
|
|
176
|
-
- **DFlow:** `platformFeeScale` is DFlow's fee for a prediction market swap, 0 to 999 in thousandths; `platformFeeBps` its fixed spot fee. Either needs `feeAccount`, your token account for the fee mint, which must exist before the trade.
|
|
177
168
|
- **Hyperliquid (HIP-4 outcomes):** the order is an L1 action, signed as a "phantom agent" on the EIP-712 domain "Exchange", chain 1337, so it is signed by a key you hold (usually an API wallet your user approved), not a browser wallet on its own chain. `builder` and `builderFee` (tenths of a basis point, at most 1000) are yours, both or neither; your user first approves your maximum fee with their main wallet (`hyperliquidApproveBuilderFee`; viem refuses its type name, so a viem key signs `digest`). Prices have at most 5 significant figures and 8 decimals less `szDecimals` (pass it if you have it: the docs do not give one for outcomes); `tif` is `Gtc`, `Ioc` or `Alo`; `nonce` is now in milliseconds by default. Hyperliquid's HIP-4 page says outcome fees are zero for testing and builders earn on sell orders, its fees page that fees are charged on closing or settling: the order is the same either way.
|
|
178
169
|
- **Your users are your responsibility:** who may trade on which venue, from where, under which terms. `geoblock.polymarket()` asks Polymarket whether it would take orders from this machine's network location, and any failure (network, timeout, an unexpected reply) is `"unknown"`, never `"allowed"`. It is one indication, not a licence.
|
|
179
170
|
|
package/dist/cjs/client.d.ts
CHANGED
|
@@ -61,11 +61,26 @@ export interface MarketsOptions {
|
|
|
61
61
|
venue?: string;
|
|
62
62
|
marketId?: string[];
|
|
63
63
|
updatedSince?: Date | string;
|
|
64
|
+
/** Only markets in one of these statuses. */
|
|
65
|
+
status?: Array<"open" | "closed" | "resolved" | "voided">;
|
|
66
|
+
/** Only markets whose category label is exactly one of these (at most 20). */
|
|
67
|
+
category?: string[];
|
|
68
|
+
/** Only the markets of this venue event; needs venue, since event ids are per venue. */
|
|
69
|
+
venueEventId?: string;
|
|
70
|
+
/** Only markets whose close_at is at or after this time. */
|
|
71
|
+
closeAfter?: Date | string;
|
|
72
|
+
/** Only markets whose close_at is before this time. */
|
|
73
|
+
closeBefore?: Date | string;
|
|
74
|
+
/** Keyword search on the question, 1 to 100 characters. */
|
|
75
|
+
q?: string;
|
|
76
|
+
/** venue (the default), close_at, updated_at or first_seen_at. */
|
|
77
|
+
sort?: "venue" | "close_at" | "updated_at" | "first_seen_at";
|
|
78
|
+
/** asc (the default) or desc. */
|
|
79
|
+
order?: "asc" | "desc";
|
|
64
80
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
* or
|
|
68
|
-
* /v1/markets would make it one request per page of results.
|
|
81
|
+
* true is status ["resolved"], false the three others (open, closed,
|
|
82
|
+
* voided): filtered on the server like status, so one request per page of
|
|
83
|
+
* results. Pass resolved or status, not both (a ConfigurationError).
|
|
69
84
|
*/
|
|
70
85
|
resolved?: boolean;
|
|
71
86
|
limit?: number;
|
|
@@ -75,6 +90,10 @@ export interface EventsOptions {
|
|
|
75
90
|
resolutionEqual?: boolean;
|
|
76
91
|
venue?: string;
|
|
77
92
|
status?: "approved" | "needs_rereview" | "retired";
|
|
93
|
+
/** event_id (the default) or published_at. */
|
|
94
|
+
sort?: "event_id" | "published_at";
|
|
95
|
+
/** asc (the default) or desc. */
|
|
96
|
+
order?: "asc" | "desc";
|
|
78
97
|
limit?: number;
|
|
79
98
|
}
|
|
80
99
|
export interface FillsOptions {
|
|
@@ -102,6 +121,14 @@ export interface ResolutionsOptions {
|
|
|
102
121
|
/** Up to 100 market ids. */
|
|
103
122
|
marketId?: string[];
|
|
104
123
|
createdSince?: Date | string;
|
|
124
|
+
/** Only events whose resolved_at is at or after this time. */
|
|
125
|
+
resolvedAfter?: Date | string;
|
|
126
|
+
/** Only events whose resolved_at is before this time. */
|
|
127
|
+
resolvedBefore?: Date | string;
|
|
128
|
+
/** venue (the default) or resolved_at. */
|
|
129
|
+
sort?: "venue" | "resolved_at";
|
|
130
|
+
/** asc (the default) or desc. */
|
|
131
|
+
order?: "asc" | "desc";
|
|
105
132
|
limit?: number;
|
|
106
133
|
}
|
|
107
134
|
export interface FeesOptions {
|
|
@@ -148,7 +175,11 @@ export declare class Skewtape {
|
|
|
148
175
|
* error envelope. A request past the timeout is a SkewtapeError.
|
|
149
176
|
*/
|
|
150
177
|
private call;
|
|
151
|
-
/**
|
|
178
|
+
/**
|
|
179
|
+
* sk.markets({venue, status, q}) lists markets; sk.markets.get(venue,
|
|
180
|
+
* marketId) reads one. Every filter is the API's, resolved included (true
|
|
181
|
+
* is status ["resolved"], false the three others), so one request per page.
|
|
182
|
+
*/
|
|
152
183
|
readonly markets: ((options?: MarketsOptions) => Paginated<Market>) & {
|
|
153
184
|
get: (venue: string, marketId: string) => Promise<Market>;
|
|
154
185
|
};
|
|
@@ -165,7 +196,7 @@ export declare class Skewtape {
|
|
|
165
196
|
fills(options: FillsOptions): Paginated<Fill>;
|
|
166
197
|
/** sk.candles({res, since}) lists candles of one size from since to until. */
|
|
167
198
|
candles(options: CandlesOptions): Paginated<Candle>;
|
|
168
|
-
/** sk.resolutions({venue, marketId, createdSince}) lists resolution events, of up to 100 markets when marketId is given. */
|
|
199
|
+
/** sk.resolutions({venue, marketId, createdSince, resolvedAfter, resolvedBefore}) lists resolution events, of up to 100 markets when marketId is given. */
|
|
169
200
|
resolutions(options?: ResolutionsOptions): Paginated<Resolution>;
|
|
170
201
|
/** sk.fees({venue}) lists the fee schedule rows. */
|
|
171
202
|
fees(options?: FeesOptions): Paginated<Fee>;
|
package/dist/cjs/client.js
CHANGED
|
@@ -56,6 +56,14 @@ function dateOf(micros) {
|
|
|
56
56
|
function iso(v) {
|
|
57
57
|
return v instanceof Date ? v.toISOString() : v;
|
|
58
58
|
}
|
|
59
|
+
/** The status filter sk.markets sends: status as given, or resolved's (true is resolved, false the three others). */
|
|
60
|
+
function marketStatus(options) {
|
|
61
|
+
if (options.resolved === undefined)
|
|
62
|
+
return options.status;
|
|
63
|
+
if (options.status !== undefined)
|
|
64
|
+
throw new errors_js_1.ConfigurationError('pass resolved or status, not both: resolved true is status ["resolved"], false the three others');
|
|
65
|
+
return options.resolved ? ["resolved"] : ["open", "closed", "voided"];
|
|
66
|
+
}
|
|
59
67
|
function defaultSleep(seconds) {
|
|
60
68
|
return new Promise((resolve) => setTimeout(resolve, seconds * 1000));
|
|
61
69
|
}
|
|
@@ -136,18 +144,33 @@ class Skewtape {
|
|
|
136
144
|
throw (0, errors_js_1.errorFromResponse)(response.status, response.headers, error);
|
|
137
145
|
}
|
|
138
146
|
}
|
|
139
|
-
/**
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
147
|
+
/**
|
|
148
|
+
* sk.markets({venue, status, q}) lists markets; sk.markets.get(venue,
|
|
149
|
+
* marketId) reads one. Every filter is the API's, resolved included (true
|
|
150
|
+
* is status ["resolved"], false the three others), so one request per page.
|
|
151
|
+
*/
|
|
152
|
+
markets = Object.assign((options = {}) => {
|
|
153
|
+
const status = marketStatus(options);
|
|
154
|
+
return new paginated_js_1.Paginated(async (cursor) => {
|
|
155
|
+
const query = {
|
|
156
|
+
venue: options.venue,
|
|
157
|
+
market_id: options.marketId,
|
|
158
|
+
updated_since: iso(options.updatedSince),
|
|
159
|
+
status,
|
|
160
|
+
category: options.category,
|
|
161
|
+
venue_event_id: options.venueEventId,
|
|
162
|
+
close_after: iso(options.closeAfter),
|
|
163
|
+
close_before: iso(options.closeBefore),
|
|
164
|
+
q: options.q,
|
|
165
|
+
sort: options.sort,
|
|
166
|
+
order: options.order,
|
|
167
|
+
limit: options.limit ?? 100,
|
|
168
|
+
cursor,
|
|
169
|
+
};
|
|
170
|
+
const data = await this.call(() => this.api.GET("/v1/markets", { params: { query } }));
|
|
171
|
+
return { items: data.data, nextCursor: data.next_cursor ?? null };
|
|
172
|
+
});
|
|
173
|
+
}, {
|
|
151
174
|
get: (venue, marketId) => this.call(() => this.api.GET("/v1/markets/{venue}/{market_id}", { params: { path: { venue, market_id: marketId } } })),
|
|
152
175
|
});
|
|
153
176
|
/** sk.events({minConfidence, resolutionEqual}) lists matched events; sk.events.get(eventId) reads one. */
|
|
@@ -171,6 +194,8 @@ class Skewtape {
|
|
|
171
194
|
resolution_equal: options.resolutionEqual,
|
|
172
195
|
venue: options.venue,
|
|
173
196
|
status: options.status,
|
|
197
|
+
sort: options.sort,
|
|
198
|
+
order: options.order,
|
|
174
199
|
limit: options.limit ?? 100,
|
|
175
200
|
cursor,
|
|
176
201
|
};
|
|
@@ -214,13 +239,17 @@ class Skewtape {
|
|
|
214
239
|
return { items: data.data, nextCursor: data.next_cursor ?? null };
|
|
215
240
|
});
|
|
216
241
|
}
|
|
217
|
-
/** sk.resolutions({venue, marketId, createdSince}) lists resolution events, of up to 100 markets when marketId is given. */
|
|
242
|
+
/** sk.resolutions({venue, marketId, createdSince, resolvedAfter, resolvedBefore}) lists resolution events, of up to 100 markets when marketId is given. */
|
|
218
243
|
resolutions(options = {}) {
|
|
219
244
|
return new paginated_js_1.Paginated(async (cursor) => {
|
|
220
245
|
const query = {
|
|
221
246
|
venue: options.venue,
|
|
222
247
|
market_id: options.marketId,
|
|
223
248
|
created_since: iso(options.createdSince),
|
|
249
|
+
resolved_after: iso(options.resolvedAfter),
|
|
250
|
+
resolved_before: iso(options.resolvedBefore),
|
|
251
|
+
sort: options.sort,
|
|
252
|
+
order: options.order,
|
|
224
253
|
limit: options.limit ?? 100,
|
|
225
254
|
cursor,
|
|
226
255
|
};
|
package/dist/cjs/fees.d.ts
CHANGED
|
@@ -62,7 +62,9 @@ export declare function makerFeeRaw(row: FeeRowInput, sizeRaw: bigint, notionalR
|
|
|
62
62
|
/**
|
|
63
63
|
* The row in force for a fill of venue at time at (microseconds, a Date or
|
|
64
64
|
* an ISO string): the market's fee_category if a row has it, else the row
|
|
65
|
-
* with category *; of several, the latest effective_from.
|
|
66
|
-
*
|
|
65
|
+
* with category *; of several, the latest effective_from. A Polymarket
|
|
66
|
+
* fee_category that joins names ("finance|mentions") gives the terms its rows
|
|
67
|
+
* share, under the joined name, while every one of them is in force and
|
|
68
|
+
* charges alike, and never the * row. Undefined when no row applies.
|
|
67
69
|
*/
|
|
68
70
|
export declare function selectFeeRow(rows: Iterable<FeeRowInput>, venue: string, category: string | null | undefined, at: bigint | Date | string): FeeRow | undefined;
|
package/dist/cjs/fees.js
CHANGED
|
@@ -20,6 +20,13 @@ const errors_js_1 = require("./errors.js");
|
|
|
20
20
|
const exact_js_1 = require("./exact.js");
|
|
21
21
|
exports.COLLATERAL_MICROS_DECIMALS = 6;
|
|
22
22
|
exports.FALLBACK_CATEGORY = "*";
|
|
23
|
+
/**
|
|
24
|
+
* A Polymarket fee_category joins several rows' names ("finance|mentions")
|
|
25
|
+
* when those rows charge alike and the venue's data does not say which is the
|
|
26
|
+
* market's.
|
|
27
|
+
*/
|
|
28
|
+
const JOINED_VENUE = "polymarket";
|
|
29
|
+
const JOINED_SEPARATOR = "|";
|
|
23
30
|
const MICROS_PER_UNIT = 1000000n;
|
|
24
31
|
/** A fee that cannot be computed: an unknown formula or rounding, a missing parameter, a size out of range. */
|
|
25
32
|
class FeeError extends errors_js_1.SkewtapeError {
|
|
@@ -176,21 +183,54 @@ function inForce(r, at) {
|
|
|
176
183
|
/**
|
|
177
184
|
* The row in force for a fill of venue at time at (microseconds, a Date or
|
|
178
185
|
* an ISO string): the market's fee_category if a row has it, else the row
|
|
179
|
-
* with category *; of several, the latest effective_from.
|
|
180
|
-
*
|
|
186
|
+
* with category *; of several, the latest effective_from. A Polymarket
|
|
187
|
+
* fee_category that joins names ("finance|mentions") gives the terms its rows
|
|
188
|
+
* share, under the joined name, while every one of them is in force and
|
|
189
|
+
* charges alike, and never the * row. Undefined when no row applies.
|
|
181
190
|
*/
|
|
182
191
|
function selectFeeRow(rows, venue, category, at) {
|
|
183
192
|
const t = typeof at === "bigint" ? at : (0, exact_js_1.parseMicros)(at, "at");
|
|
184
|
-
const all = [...rows].map(feeRowOf);
|
|
193
|
+
const all = [...rows].map(feeRowOf).filter((r) => r.venue === venue);
|
|
194
|
+
if (venue === JOINED_VENUE && category && category.includes(JOINED_SEPARATOR))
|
|
195
|
+
return joinedRow(all, category, t);
|
|
185
196
|
const wanted = category && category !== exports.FALLBACK_CATEGORY ? [category, exports.FALLBACK_CATEGORY] : [exports.FALLBACK_CATEGORY];
|
|
186
197
|
for (const cat of wanted) {
|
|
187
|
-
|
|
188
|
-
for (const r of all) {
|
|
189
|
-
if (r.venue === venue && r.category === cat && inForce(r, t) && (best === undefined || r.effectiveFrom > best.effectiveFrom))
|
|
190
|
-
best = r;
|
|
191
|
-
}
|
|
198
|
+
const best = rowInForce(all, cat, t);
|
|
192
199
|
if (best)
|
|
193
200
|
return best;
|
|
194
201
|
}
|
|
195
202
|
return undefined;
|
|
196
203
|
}
|
|
204
|
+
function rowInForce(rows, category, at) {
|
|
205
|
+
let best;
|
|
206
|
+
for (const r of rows) {
|
|
207
|
+
if (r.category === category && inForce(r, at) && (best === undefined || r.effectiveFrom > best.effectiveFrom))
|
|
208
|
+
best = r;
|
|
209
|
+
}
|
|
210
|
+
return best;
|
|
211
|
+
}
|
|
212
|
+
function joinedRow(rows, key, at) {
|
|
213
|
+
let out;
|
|
214
|
+
for (const name of key.split(JOINED_SEPARATOR)) {
|
|
215
|
+
const r = rowInForce(rows, name, at);
|
|
216
|
+
if (r === undefined || (out !== undefined && !sameTerms(out, r)))
|
|
217
|
+
return undefined;
|
|
218
|
+
if (out === undefined) {
|
|
219
|
+
out = { ...r, category: key };
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
if (r.effectiveFrom > out.effectiveFrom)
|
|
223
|
+
out.effectiveFrom = r.effectiveFrom;
|
|
224
|
+
if (r.effectiveTo !== null && (out.effectiveTo === null || r.effectiveTo < out.effectiveTo))
|
|
225
|
+
out.effectiveTo = r.effectiveTo;
|
|
226
|
+
}
|
|
227
|
+
return out;
|
|
228
|
+
}
|
|
229
|
+
/** Whether two rows charge alike: everything but the name, period and source. */
|
|
230
|
+
function sameTerms(a, b) {
|
|
231
|
+
return a.formula === b.formula && a.rounding === b.rounding && a.minFeeMicros === b.minFeeMicros && sameParams(a.takerParams, b.takerParams) && sameParams(a.makerRebateParams, b.makerRebateParams);
|
|
232
|
+
}
|
|
233
|
+
function sameParams(a, b) {
|
|
234
|
+
const keys = Object.keys(a);
|
|
235
|
+
return keys.length === Object.keys(b).length && keys.every((k) => a[k] === b[k]);
|
|
236
|
+
}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -20,10 +20,10 @@ export { downloadFile, verifyChecksums, type DownloadOptions } from "./download.
|
|
|
20
20
|
export { Rat, fractionStr, roundHalfUp } from "./exact.js";
|
|
21
21
|
export { FeeError, feeRowOf, makerFeeRaw, microsToRaw, selectFeeRow, takerFeeRaw, type FeeRow, type FeeRowInput } from "./fees.js";
|
|
22
22
|
export { DEFAULT_KALSHI_BASE_URL, KALSHI_VENUES, Kalshi, KalshiError, PERIODS, kalshiTickers, seriesTickerOf, type KalshiCandlestick, type KalshiCandlesticksOptions, type KalshiEventLike, type KalshiLevel, type KalshiMarket, type KalshiMarketsOptions, type KalshiOHLC, type KalshiOptions, type KalshiOrderbook, type KalshiPeriod, type KalshiTrade, type KalshiTradesOptions, } from "./kalshi.js";
|
|
23
|
-
export { BookUnavailable, DEFAULT_BOOK_READERS, KALSHI_FRACTION_MICRO, quoteFromContext, readKalshiBook,
|
|
23
|
+
export { BookUnavailable, DEFAULT_BOOK_READERS, KALSHI_FRACTION_MICRO, quoteFromContext, readKalshiBook, readPolymarketBook, type BookReader, type BookRequest, type QuoteContext, type QuoteContextMember, type QuoteOptions, } from "./quote.js";
|
|
24
24
|
export { InvalidQuoteInputError, QuoteError, RuleMismatchError, VenueUnreachableError, computeQuote, type Book, type Leg, type Level, type QuoteInput, type QuoteResult, type Skip, type VenueQuote, } from "./quote-math.js";
|
|
25
25
|
export { AuthenticationError, BlockedError, ChecksumError, ConfigurationError, ForbiddenPlanError, InvalidRequestError, NotFoundError, QuotaExceededError, RateLimitError, ServerError, SkewtapeError, } from "./errors.js";
|
|
26
|
-
export {
|
|
26
|
+
export { POLYMARKET_EXCHANGES, PolymarketOrder, RouteError, route, type PolymarketRoute, type PolymarketTypedData, type RouteInput, } from "./route.js";
|
|
27
27
|
export { HYPERLIQUID_EXCHANGE_URL, HYPERLIQUID_TESTNET_EXCHANGE_URL, HyperliquidApproveBuilderFee, HyperliquidOrder, hyperliquidApproveBuilderFee, type HyperliquidRoute, } from "./route-hyperliquid.js";
|
|
28
28
|
export { geoblock, type GeoblockResult, type GeoblockOptions } from "./geoblock.js";
|
|
29
29
|
export { Stream, feedUrl, type FeedMessage, type FeedSocket, type FeedSocketConstructor, type StreamOptions } from "./stream.js";
|
package/dist/cjs/index.js
CHANGED
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
* generated from the OpenAPI document and never edited.
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.
|
|
20
|
-
exports.VERSION = exports.feedUrl = exports.Stream = exports.geoblock = exports.hyperliquidApproveBuilderFee = exports.HyperliquidOrder = exports.HyperliquidApproveBuilderFee = exports.HYPERLIQUID_TESTNET_EXCHANGE_URL = exports.HYPERLIQUID_EXCHANGE_URL = exports.route = exports.RouteError =
|
|
19
|
+
exports.PolymarketOrder = exports.POLYMARKET_EXCHANGES = exports.SkewtapeError = exports.ServerError = exports.RateLimitError = exports.QuotaExceededError = exports.NotFoundError = exports.InvalidRequestError = exports.ForbiddenPlanError = exports.ConfigurationError = exports.ChecksumError = exports.BlockedError = exports.AuthenticationError = exports.computeQuote = exports.VenueUnreachableError = exports.RuleMismatchError = exports.QuoteError = exports.InvalidQuoteInputError = exports.readPolymarketBook = exports.readKalshiBook = exports.quoteFromContext = exports.KALSHI_FRACTION_MICRO = exports.DEFAULT_BOOK_READERS = exports.BookUnavailable = exports.seriesTickerOf = exports.kalshiTickers = exports.PERIODS = exports.KalshiError = exports.Kalshi = exports.KALSHI_VENUES = exports.DEFAULT_KALSHI_BASE_URL = exports.takerFeeRaw = exports.selectFeeRow = exports.microsToRaw = exports.makerFeeRaw = exports.feeRowOf = exports.FeeError = exports.roundHalfUp = exports.fractionStr = exports.Rat = exports.verifyChecksums = exports.downloadFile = exports.runBacktest = exports.backtestToJSON = exports.BacktestError = exports.activeMembers = exports.Skewtape = exports.Paginated = exports.ENV_API_KEY = exports.DEFAULT_BASE_URL = void 0;
|
|
20
|
+
exports.VERSION = exports.feedUrl = exports.Stream = exports.geoblock = exports.hyperliquidApproveBuilderFee = exports.HyperliquidOrder = exports.HyperliquidApproveBuilderFee = exports.HYPERLIQUID_TESTNET_EXCHANGE_URL = exports.HYPERLIQUID_EXCHANGE_URL = exports.route = exports.RouteError = void 0;
|
|
21
21
|
var client_js_1 = require("./client.js");
|
|
22
22
|
Object.defineProperty(exports, "DEFAULT_BASE_URL", { enumerable: true, get: function () { return client_js_1.DEFAULT_BASE_URL; } });
|
|
23
23
|
Object.defineProperty(exports, "ENV_API_KEY", { enumerable: true, get: function () { return client_js_1.ENV_API_KEY; } });
|
|
@@ -56,7 +56,6 @@ Object.defineProperty(exports, "DEFAULT_BOOK_READERS", { enumerable: true, get:
|
|
|
56
56
|
Object.defineProperty(exports, "KALSHI_FRACTION_MICRO", { enumerable: true, get: function () { return quote_js_1.KALSHI_FRACTION_MICRO; } });
|
|
57
57
|
Object.defineProperty(exports, "quoteFromContext", { enumerable: true, get: function () { return quote_js_1.quoteFromContext; } });
|
|
58
58
|
Object.defineProperty(exports, "readKalshiBook", { enumerable: true, get: function () { return quote_js_1.readKalshiBook; } });
|
|
59
|
-
Object.defineProperty(exports, "readKalshiBookThroughDflow", { enumerable: true, get: function () { return quote_js_1.readKalshiBookThroughDflow; } });
|
|
60
59
|
Object.defineProperty(exports, "readPolymarketBook", { enumerable: true, get: function () { return quote_js_1.readPolymarketBook; } });
|
|
61
60
|
var quote_math_js_1 = require("./quote-math.js");
|
|
62
61
|
Object.defineProperty(exports, "InvalidQuoteInputError", { enumerable: true, get: function () { return quote_math_js_1.InvalidQuoteInputError; } });
|
|
@@ -77,8 +76,6 @@ Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: functi
|
|
|
77
76
|
Object.defineProperty(exports, "ServerError", { enumerable: true, get: function () { return errors_js_1.ServerError; } });
|
|
78
77
|
Object.defineProperty(exports, "SkewtapeError", { enumerable: true, get: function () { return errors_js_1.SkewtapeError; } });
|
|
79
78
|
var route_js_1 = require("./route.js");
|
|
80
|
-
Object.defineProperty(exports, "DFLOW_TRADING_API", { enumerable: true, get: function () { return route_js_1.DFLOW_TRADING_API; } });
|
|
81
|
-
Object.defineProperty(exports, "DFlowOrderRequest", { enumerable: true, get: function () { return route_js_1.DFlowOrderRequest; } });
|
|
82
79
|
Object.defineProperty(exports, "POLYMARKET_EXCHANGES", { enumerable: true, get: function () { return route_js_1.POLYMARKET_EXCHANGES; } });
|
|
83
80
|
Object.defineProperty(exports, "PolymarketOrder", { enumerable: true, get: function () { return route_js_1.PolymarketOrder; } });
|
|
84
81
|
Object.defineProperty(exports, "RouteError", { enumerable: true, get: function () { return route_js_1.RouteError; } });
|
package/dist/cjs/kalshi.d.ts
CHANGED
|
@@ -159,8 +159,8 @@ export interface KalshiEventLike {
|
|
|
159
159
|
}
|
|
160
160
|
/**
|
|
161
161
|
* The Kalshi tickers of a matched event: the market_id of its members on
|
|
162
|
-
* kalshi
|
|
163
|
-
*
|
|
162
|
+
* kalshi (the ticker is the id), active ones unless includeInactive, in
|
|
163
|
+
* member order, each once.
|
|
164
164
|
*/
|
|
165
165
|
export declare function kalshiTickers(event: KalshiEventLike, includeInactive?: boolean): string[];
|
|
166
166
|
export interface KalshiOptions {
|
|
@@ -250,7 +250,7 @@ export declare class Kalshi {
|
|
|
250
250
|
* periods a request and a 1d stick is a New York day.
|
|
251
251
|
*/
|
|
252
252
|
candlesticks(ticker: string, options: KalshiCandlesticksOptions): Promise<KalshiCandlestick[]>;
|
|
253
|
-
/** The Kalshi tickers of a Skewtape matched event: the market_id of its kalshi
|
|
253
|
+
/** The Kalshi tickers of a Skewtape matched event: the market_id of its kalshi members, active ones unless includeInactive. */
|
|
254
254
|
tickers(event: KalshiEventLike, options?: {
|
|
255
255
|
includeInactive?: boolean;
|
|
256
256
|
}): string[];
|
package/dist/cjs/kalshi.js
CHANGED
|
@@ -43,7 +43,7 @@ const version_js_1 = require("./version.js");
|
|
|
43
43
|
/** The production Trade API host Kalshi's docs prefer (api.elections.kalshi.com stays supported; pass baseUrl for it or for the demo host). */
|
|
44
44
|
exports.DEFAULT_KALSHI_BASE_URL = "https://external-api.kalshi.com/trade-api/v2";
|
|
45
45
|
/** The matched-event member venues whose market_id is a Kalshi ticker. */
|
|
46
|
-
exports.KALSHI_VENUES = new Set(["kalshi"
|
|
46
|
+
exports.KALSHI_VENUES = new Set(["kalshi"]);
|
|
47
47
|
/** Candlestick sizes, as sk.candles names them, to Kalshi's period_interval minutes. */
|
|
48
48
|
exports.PERIODS = { "1m": 1, "1h": 60, "1d": 1440 };
|
|
49
49
|
/**
|
|
@@ -228,8 +228,8 @@ class Signer {
|
|
|
228
228
|
}
|
|
229
229
|
/**
|
|
230
230
|
* The Kalshi tickers of a matched event: the market_id of its members on
|
|
231
|
-
* kalshi
|
|
232
|
-
*
|
|
231
|
+
* kalshi (the ticker is the id), active ones unless includeInactive, in
|
|
232
|
+
* member order, each once.
|
|
233
233
|
*/
|
|
234
234
|
function kalshiTickers(event, includeInactive = false) {
|
|
235
235
|
const out = [];
|
|
@@ -398,7 +398,7 @@ class Kalshi {
|
|
|
398
398
|
const rows = Array.isArray(body.candlesticks) ? body.candlesticks : [];
|
|
399
399
|
return rows.map((s) => candlestickFromRaw(record(s), minutes));
|
|
400
400
|
}
|
|
401
|
-
/** The Kalshi tickers of a Skewtape matched event: the market_id of its kalshi
|
|
401
|
+
/** The Kalshi tickers of a Skewtape matched event: the market_id of its kalshi members, active ones unless includeInactive. */
|
|
402
402
|
tickers(event, options = {}) {
|
|
403
403
|
return kalshiTickers(event, options.includeInactive ?? false);
|
|
404
404
|
}
|
package/dist/cjs/paginated.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export declare class Paginated<T> implements AsyncIterable<T> {
|
|
|
16
16
|
private readonly fetchPage;
|
|
17
17
|
private readonly keep?;
|
|
18
18
|
constructor(fetchPage: (cursor?: string) => Promise<Page<T>>, keep?: ((item: T) => boolean) | undefined);
|
|
19
|
-
/** The pages as the API returns them; a client-side filter (
|
|
19
|
+
/** The pages as the API returns them; a client-side filter (sk.pairs: the matched events of two active members) applies to each. */
|
|
20
20
|
pages(): AsyncGenerator<Page<T>, void, undefined>;
|
|
21
21
|
[Symbol.asyncIterator](): AsyncGenerator<T, void, undefined>;
|
|
22
22
|
/** The first item, or undefined when there is none. */
|
package/dist/cjs/paginated.js
CHANGED
|
@@ -17,7 +17,7 @@ class Paginated {
|
|
|
17
17
|
this.fetchPage = fetchPage;
|
|
18
18
|
this.keep = keep;
|
|
19
19
|
}
|
|
20
|
-
/** The pages as the API returns them; a client-side filter (
|
|
20
|
+
/** The pages as the API returns them; a client-side filter (sk.pairs: the matched events of two active members) applies to each. */
|
|
21
21
|
async *pages() {
|
|
22
22
|
let cursor;
|
|
23
23
|
for (;;) {
|
package/dist/cjs/quote.d.ts
CHANGED
|
@@ -38,7 +38,7 @@ export interface QuoteOptions {
|
|
|
38
38
|
size: number | string;
|
|
39
39
|
/** Quote members that do not resolve alike, with a warning; refused by default. */
|
|
40
40
|
allowRuleMismatch?: boolean;
|
|
41
|
-
/** Readers by venue, used before the defaults (Polymarket's CLOB; Kalshi's public orderbook
|
|
41
|
+
/** Readers by venue, used before the defaults (Polymarket's CLOB; Kalshi's public orderbook). */
|
|
42
42
|
bookReaders?: Record<string, BookReader>;
|
|
43
43
|
/** The fetch the books are read with; the global one by default. It must not carry the Skewtape key. */
|
|
44
44
|
venueFetch?: typeof fetch;
|
|
@@ -84,17 +84,6 @@ export declare const readPolymarketBook: BookReader;
|
|
|
84
84
|
* may refuse. Kalshi documents no minimum order beyond that.
|
|
85
85
|
*/
|
|
86
86
|
export declare const readKalshiBook: BookReader;
|
|
87
|
-
/**
|
|
88
|
-
* A kalshi_dflow member trades through DFlow (ADR-0016), whose orderbook
|
|
89
|
-
* needs DFlow access, not set up yet, so the member is left out with that
|
|
90
|
-
* reason, plainly; nothing reads the book another way. (A kalshi member is
|
|
91
|
-
* read from Kalshi's own book: readKalshiBook.)
|
|
92
|
-
*
|
|
93
|
-
* TODO(decision): DFlow's orderbook endpoint, its shape and the key it needs
|
|
94
|
-
* (production access is by request). Until then a caller can pass its own
|
|
95
|
-
* reader in bookReaders.
|
|
96
|
-
*/
|
|
97
|
-
export declare const readKalshiBookThroughDflow: BookReader;
|
|
98
87
|
export declare const DEFAULT_BOOK_READERS: Readonly<Record<string, BookReader>>;
|
|
99
88
|
/** The event's outcome names a quote can take, as the members' outcome maps name them. */
|
|
100
89
|
export declare function outcomesOf(context: QuoteContext): string[];
|
package/dist/cjs/quote.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* quote-math.ts, which passes tape's conformance vectors.
|
|
13
13
|
*/
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.MICRO = exports.DEFAULT_BOOK_READERS = exports.
|
|
15
|
+
exports.MICRO = exports.DEFAULT_BOOK_READERS = exports.readKalshiBook = exports.readPolymarketBook = exports.BOOK_TIMEOUT_SECONDS = exports.BookUnavailable = exports.KALSHI_FRACTION_MICRO = exports.POLYMARKET_CLOB_URL = void 0;
|
|
16
16
|
exports.micros = micros;
|
|
17
17
|
exports.outcomesOf = outcomesOf;
|
|
18
18
|
exports.quoteFromContext = quoteFromContext;
|
|
@@ -199,24 +199,9 @@ const readKalshiBook = async (request, fetchImpl) => {
|
|
|
199
199
|
}
|
|
200
200
|
};
|
|
201
201
|
exports.readKalshiBook = readKalshiBook;
|
|
202
|
-
/**
|
|
203
|
-
* A kalshi_dflow member trades through DFlow (ADR-0016), whose orderbook
|
|
204
|
-
* needs DFlow access, not set up yet, so the member is left out with that
|
|
205
|
-
* reason, plainly; nothing reads the book another way. (A kalshi member is
|
|
206
|
-
* read from Kalshi's own book: readKalshiBook.)
|
|
207
|
-
*
|
|
208
|
-
* TODO(decision): DFlow's orderbook endpoint, its shape and the key it needs
|
|
209
|
-
* (production access is by request). Until then a caller can pass its own
|
|
210
|
-
* reader in bookReaders.
|
|
211
|
-
*/
|
|
212
|
-
const readKalshiBookThroughDflow = async () => {
|
|
213
|
-
throw new BookUnavailable("kalshi_dflow's book is read through DFlow's orderbook, and DFlow access is not set up yet");
|
|
214
|
-
};
|
|
215
|
-
exports.readKalshiBookThroughDflow = readKalshiBookThroughDflow;
|
|
216
202
|
exports.DEFAULT_BOOK_READERS = {
|
|
217
203
|
polymarket: exports.readPolymarketBook,
|
|
218
204
|
kalshi: exports.readKalshiBook,
|
|
219
|
-
kalshi_dflow: exports.readKalshiBookThroughDflow,
|
|
220
205
|
};
|
|
221
206
|
/** Each outcome's name (its label, or its token id when the market gives two outcomes the same label) to its token id. */
|
|
222
207
|
function names(member) {
|
package/dist/cjs/route.d.ts
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
*
|
|
5
5
|
* route() builds and checks an order, and stops there: it never signs, never
|
|
6
6
|
* sends, never takes a private key, and needs no Skewtape key. Every code and
|
|
7
|
-
* fee it carries is the developer's own: the Polymarket builder code
|
|
8
|
-
*
|
|
7
|
+
* fee it carries is the developer's own: the Polymarket builder code and the
|
|
8
|
+
* Hyperliquid builder fee. Omitting them sends none, and no Skewtape value
|
|
9
9
|
* exists in this package (a test scans it). The developer is responsible for
|
|
10
10
|
* their users: who may trade where, and under which terms (sk.geoblock helps
|
|
11
11
|
* with Polymarket's).
|
|
@@ -225,73 +225,14 @@ export interface PolymarketRoute {
|
|
|
225
225
|
/** The fields each venue's order takes: anything else, a private key above all, is refused. */
|
|
226
226
|
export declare const ROUTE_FIELDS: {
|
|
227
227
|
readonly polymarket: readonly ["venue", "exchange", "tokenId", "side", "price", "tickSize", "maker", "size", "amount", "orderType", "signatureType", "signer", "builder", "metadata", "expiration", "salt", "timestampMs"];
|
|
228
|
-
readonly kalshi_dflow: readonly ["venue", "inputMint", "outputMint", "amount", "userPublicKey", "slippageBps", "predictionMarketSlippageBps", "platformFeeScale", "platformFeeBps", "platformFeeMode", "feeAccount", "baseUrl"];
|
|
229
228
|
readonly hyperliquid: readonly ["venue", "outcome", "side", "isBuy", "price", "size", "tif", "reduceOnly", "cloid", "builder", "builderFee", "szDecimals", "nonce", "vaultAddress", "expiresAfter", "mainnet"];
|
|
230
229
|
};
|
|
231
230
|
export declare function polymarketOrder(input: PolymarketRoute): PolymarketOrder;
|
|
231
|
+
export type RouteInput = PolymarketRoute | HyperliquidRoute;
|
|
232
232
|
/**
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
* the developer's own key in the x-api-key header ("All calls to the
|
|
236
|
-
* production endpoints must use an API key", pond.dflow.net/get-started/api-key.md).
|
|
237
|
-
*/
|
|
238
|
-
export declare const DFLOW_TRADING_API = "https://quote-api.dflow.net";
|
|
239
|
-
export declare const DFLOW_API_KEY_HEADER = "x-api-key";
|
|
240
|
-
/**
|
|
241
|
-
* platformFeeScale: "Optional platform fee scale for World prediction market
|
|
242
|
-
* swaps and async prediction market swaps, with 3 decimals ... Must be >= 0 and
|
|
243
|
-
* < 1000. For example, a value of 50 means 0.050." platformFeeBps: a fixed fee
|
|
244
|
-
* in basis points, for spot trades (pond.dflow.net/spot/trading/platform-fees.md).
|
|
245
|
-
*/
|
|
246
|
-
export declare const DFLOW_FEE_SCALE_MAX = 999;
|
|
247
|
-
export declare const DFLOW_FEE_BPS_MAX = 10000;
|
|
248
|
-
/**
|
|
249
|
-
* The request that returns an unsigned DFlow transaction: GET `url` with
|
|
250
|
-
* `params` and your own DFlow key in the x-api-key header. The response's
|
|
251
|
-
* `transaction` (base64) is for your user to sign and submit. Nothing was
|
|
252
|
-
* sent: route() never calls DFlow.
|
|
253
|
-
*/
|
|
254
|
-
export declare class DFlowOrderRequest {
|
|
255
|
-
readonly url: string;
|
|
256
|
-
readonly params: Readonly<Record<string, string>>;
|
|
257
|
-
readonly venue: "kalshi_dflow";
|
|
258
|
-
readonly apiKeyHeader = "x-api-key";
|
|
259
|
-
constructor(url: string, params: Readonly<Record<string, string>>);
|
|
260
|
-
get fullUrl(): string;
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* A DFlow order to build, for tokenized Kalshi outcome tokens or any DFlow
|
|
264
|
-
* trade, carrying the developer's own fee (ARCHITECTURE 13.3). amount: the
|
|
265
|
-
* input amount in the input mint's base units. userPublicKey: your user's
|
|
266
|
-
* wallet, so the response carries the transaction to sign. platformFeeScale:
|
|
267
|
-
* your fee for a prediction market swap, 0 to 999 in thousandths (DFlow's
|
|
268
|
-
* platformFeeScale; its docs give no formula). Or platformFeeBps: a fixed fee
|
|
269
|
-
* in basis points, DFlow's spot fee. Either needs feeAccount, your token
|
|
270
|
-
* account for the fee mint (the stablecoin for a prediction market swap),
|
|
271
|
-
* which must exist before the trade. With no fee, none is sent.
|
|
272
|
-
*/
|
|
273
|
-
export interface DFlowRoute {
|
|
274
|
-
venue: "kalshi_dflow";
|
|
275
|
-
inputMint: string;
|
|
276
|
-
outputMint: string;
|
|
277
|
-
amount: number | bigint;
|
|
278
|
-
userPublicKey: string;
|
|
279
|
-
slippageBps?: number | "auto";
|
|
280
|
-
predictionMarketSlippageBps?: number;
|
|
281
|
-
platformFeeScale?: number;
|
|
282
|
-
platformFeeBps?: number;
|
|
283
|
-
platformFeeMode?: "outputMint" | "inputMint";
|
|
284
|
-
feeAccount?: string;
|
|
285
|
-
baseUrl?: string;
|
|
286
|
-
}
|
|
287
|
-
export declare function dflowOrder(input: DFlowRoute): DFlowOrderRequest;
|
|
288
|
-
export type RouteInput = PolymarketRoute | DFlowRoute | HyperliquidRoute;
|
|
289
|
-
/**
|
|
290
|
-
* An unsigned order for `venue` ("polymarket", "kalshi_dflow" or
|
|
291
|
-
* "hyperliquid", a HIP-4 outcome), with the developer's own builder code or
|
|
292
|
-
* fee. It never signs, never sends, and takes no private key.
|
|
233
|
+
* An unsigned order for `venue` ("polymarket" or "hyperliquid", a HIP-4
|
|
234
|
+
* outcome), with the developer's own builder code or fee. It never signs, never sends, and takes no private key.
|
|
293
235
|
*/
|
|
294
236
|
export declare function route(order: PolymarketRoute): PolymarketOrder;
|
|
295
|
-
export declare function route(order: DFlowRoute): DFlowOrderRequest;
|
|
296
237
|
export declare function route(order: HyperliquidRoute): HyperliquidOrder;
|
|
297
|
-
export declare function route(order: RouteInput): PolymarketOrder |
|
|
238
|
+
export declare function route(order: RouteInput): PolymarketOrder | HyperliquidOrder;
|