skewtape 0.0.1 → 0.1.5
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/LICENSE +21 -0
- package/README.md +182 -0
- package/dist/cjs/backtest.d.ts +146 -0
- package/dist/cjs/backtest.js +410 -0
- package/dist/cjs/client.d.ts +255 -0
- package/dist/cjs/client.js +447 -0
- package/dist/cjs/download.d.ts +33 -0
- package/dist/cjs/download.js +160 -0
- package/dist/cjs/errors.d.ts +76 -0
- package/dist/cjs/errors.js +159 -0
- package/dist/cjs/exact.d.ts +36 -0
- package/dist/cjs/exact.js +168 -0
- package/dist/cjs/fees.d.ts +68 -0
- package/dist/cjs/fees.js +196 -0
- package/dist/cjs/geoblock.d.ts +48 -0
- package/dist/cjs/geoblock.js +78 -0
- package/dist/cjs/index.d.ts +31 -0
- package/dist/cjs/index.js +98 -0
- package/dist/cjs/kalshi.d.ts +261 -0
- package/dist/cjs/kalshi.js +416 -0
- package/dist/cjs/keccak.d.ts +10 -0
- package/dist/cjs/keccak.js +84 -0
- package/dist/cjs/msgpack.d.ts +15 -0
- package/dist/cjs/msgpack.js +112 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/paginated.d.ts +26 -0
- package/dist/cjs/paginated.js +51 -0
- package/dist/cjs/quote-math.d.ts +146 -0
- package/dist/cjs/quote-math.js +446 -0
- package/dist/cjs/quote.d.ts +108 -0
- package/dist/cjs/quote.js +307 -0
- package/dist/cjs/route-hyperliquid.d.ts +228 -0
- package/dist/cjs/route-hyperliquid.js +387 -0
- package/dist/cjs/route.d.ts +297 -0
- package/dist/cjs/route.js +516 -0
- package/dist/cjs/stream.d.ts +99 -0
- package/dist/cjs/stream.js +529 -0
- package/dist/cjs/version.d.ts +6 -0
- package/dist/cjs/version.js +9 -0
- package/dist/esm/backtest.d.ts +146 -0
- package/dist/esm/backtest.js +403 -0
- package/dist/esm/client.d.ts +255 -0
- package/dist/esm/client.js +441 -0
- package/dist/esm/download.d.ts +33 -0
- package/dist/esm/download.js +155 -0
- package/dist/esm/errors.d.ts +76 -0
- package/dist/esm/errors.js +142 -0
- package/dist/esm/exact.d.ts +36 -0
- package/dist/esm/exact.js +158 -0
- package/dist/esm/fees.d.ts +68 -0
- package/dist/esm/fees.js +185 -0
- package/dist/esm/geoblock.d.ts +48 -0
- package/dist/esm/geoblock.js +74 -0
- package/dist/esm/index.d.ts +31 -0
- package/dist/esm/index.js +30 -0
- package/dist/esm/kalshi.d.ts +261 -0
- package/dist/esm/kalshi.js +404 -0
- package/dist/esm/keccak.d.ts +10 -0
- package/dist/esm/keccak.js +80 -0
- package/dist/esm/msgpack.d.ts +15 -0
- package/dist/esm/msgpack.js +109 -0
- package/dist/esm/paginated.d.ts +26 -0
- package/dist/esm/paginated.js +47 -0
- package/dist/esm/quote-math.d.ts +146 -0
- package/dist/esm/quote-math.js +437 -0
- package/dist/esm/quote.d.ts +108 -0
- package/dist/esm/quote.js +297 -0
- package/dist/esm/route-hyperliquid.d.ts +228 -0
- package/dist/esm/route-hyperliquid.js +376 -0
- package/dist/esm/route.d.ts +297 -0
- package/dist/esm/route.js +507 -0
- package/dist/esm/stream.d.ts +99 -0
- package/dist/esm/stream.js +524 -0
- package/dist/esm/version.d.ts +6 -0
- package/dist/esm/version.js +6 -0
- package/package.json +48 -1
- package/src/backtest.ts +490 -0
- package/src/client.ts +595 -0
- package/src/download.ts +161 -0
- package/src/errors.ts +143 -0
- package/src/exact.ts +159 -0
- package/src/fees.ts +189 -0
- package/src/generated/schema.d.ts +2500 -0
- package/src/geoblock.ts +90 -0
- package/src/index.ts +146 -0
- package/src/kalshi.ts +563 -0
- package/src/keccak.ts +82 -0
- package/src/msgpack.ts +83 -0
- package/src/paginated.ts +51 -0
- package/src/quote-math.ts +555 -0
- package/src/quote.ts +324 -0
- package/src/route-hyperliquid.ts +457 -0
- package/src/route.ts +631 -0
- package/src/stream.ts +539 -0
- package/src/version.ts +6 -0
package/src/geoblock.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* sk.geoblock: whether a venue would accept orders from this machine's
|
|
3
|
+
* network location, as the venue itself says (ARCHITECTURE 13.3).
|
|
4
|
+
*
|
|
5
|
+
* const result = await geoblock.polymarket();
|
|
6
|
+
* if (result.status !== "allowed") {
|
|
7
|
+
* // do not route this user's orders to Polymarket
|
|
8
|
+
* }
|
|
9
|
+
*
|
|
10
|
+
* It asks the venue, not Skewtape, and answers "unknown" on any failure: a
|
|
11
|
+
* network error, a timeout, an unexpected status or body. It never answers
|
|
12
|
+
* "allowed" unless the venue said so. The developer is responsible for their
|
|
13
|
+
* users: this is one check for the machine it runs on, not a licence, and it
|
|
14
|
+
* says nothing about the venue's terms or the law where the user is.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* GET https://polymarket.com/api/geoblock answers {"blocked", "ip", "country",
|
|
19
|
+
* "region"} ("This endpoint is on polymarket.com, not the API servers",
|
|
20
|
+
* docs.polymarket.com/api-reference/geoblock.md, read 14 Nov 2026). The page
|
|
21
|
+
* lists blocked and close-only jurisdictions and does not say how close-only
|
|
22
|
+
* ones answer, so "allowed" means only that the venue answered blocked false.
|
|
23
|
+
*/
|
|
24
|
+
export const POLYMARKET_GEOBLOCK_URL = "https://polymarket.com/api/geoblock";
|
|
25
|
+
export const GEOBLOCK_DEFAULT_TIMEOUT_MS = 5000;
|
|
26
|
+
|
|
27
|
+
export interface GeoblockResult {
|
|
28
|
+
/** "allowed" (the venue answered blocked false), "blocked" (blocked true), or "unknown" (anything else; detail says why). */
|
|
29
|
+
status: "allowed" | "blocked" | "unknown";
|
|
30
|
+
allowed: boolean;
|
|
31
|
+
detail: string;
|
|
32
|
+
/** ISO 3166-1 alpha-2, as the venue gave it. */
|
|
33
|
+
country?: string;
|
|
34
|
+
region?: string;
|
|
35
|
+
ip?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface GeoblockOptions {
|
|
39
|
+
/** A fetch to use (tests pass one); the global fetch by default. */
|
|
40
|
+
fetch?: typeof fetch;
|
|
41
|
+
timeoutMs?: number;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const text = (v: unknown): string | undefined => (typeof v === "string" && v ? v : undefined);
|
|
45
|
+
|
|
46
|
+
function unknown(detail: string): GeoblockResult {
|
|
47
|
+
return { status: "unknown", allowed: false, detail };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Ask Polymarket whether it would take orders from this machine's network
|
|
52
|
+
* location. Sends nothing but the request: no Skewtape key, no order.
|
|
53
|
+
*/
|
|
54
|
+
export async function polymarketGeoblock(options: GeoblockOptions = {}): Promise<GeoblockResult> {
|
|
55
|
+
const doFetch = options.fetch ?? globalThis.fetch;
|
|
56
|
+
try {
|
|
57
|
+
// A redirect is not followed: the answer must be polymarket.com's own,
|
|
58
|
+
// as the Python SDK's httpx client follows none.
|
|
59
|
+
const response = await doFetch(POLYMARKET_GEOBLOCK_URL, {
|
|
60
|
+
method: "GET",
|
|
61
|
+
redirect: "manual",
|
|
62
|
+
signal: AbortSignal.timeout(options.timeoutMs ?? GEOBLOCK_DEFAULT_TIMEOUT_MS),
|
|
63
|
+
});
|
|
64
|
+
if (response.type === "opaqueredirect") return unknown("a redirect, not followed");
|
|
65
|
+
if (response.status !== 200) return unknown(`HTTP ${response.status}`);
|
|
66
|
+
const body: unknown = await response.json();
|
|
67
|
+
if (typeof body !== "object" || body === null || Array.isArray(body) || typeof (body as { blocked?: unknown }).blocked !== "boolean") {
|
|
68
|
+
return unknown("the reply carries no boolean blocked field");
|
|
69
|
+
}
|
|
70
|
+
const b = body as { blocked: boolean; country?: unknown; region?: unknown; ip?: unknown };
|
|
71
|
+
const result: GeoblockResult = {
|
|
72
|
+
status: b.blocked ? "blocked" : "allowed",
|
|
73
|
+
allowed: !b.blocked,
|
|
74
|
+
detail: b.blocked ? "the venue answered blocked" : "the venue answered not blocked",
|
|
75
|
+
};
|
|
76
|
+
const country = text(b.country);
|
|
77
|
+
const region = text(b.region);
|
|
78
|
+
const ip = text(b.ip);
|
|
79
|
+
if (country) result.country = country;
|
|
80
|
+
if (region) result.region = region;
|
|
81
|
+
if (ip) result.ip = ip;
|
|
82
|
+
return result;
|
|
83
|
+
} catch (err) {
|
|
84
|
+
// Any failure is unknown, never allowed.
|
|
85
|
+
return unknown(err instanceof Error ? `${err.name}: ${err.message}` : String(err));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** sk.geoblock: one helper per venue that publishes a check. */
|
|
90
|
+
export const geoblock = { polymarket: polymarketGeoblock } as const;
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skewtape: prediction-market data across venues in one schema.
|
|
3
|
+
*
|
|
4
|
+
* import { Skewtape } from "skewtape";
|
|
5
|
+
* const sk = new Skewtape(); // the key from SKEWTAPE_API_KEY, or { apiKey }
|
|
6
|
+
* for await (const event of sk.events({ minConfidence: 0.9, resolutionEqual: true })) {
|
|
7
|
+
* console.log(event.event_id, event.question_canonical);
|
|
8
|
+
* }
|
|
9
|
+
*
|
|
10
|
+
* sk.kalshi() is the optional live Kalshi client under the user's own Kalshi
|
|
11
|
+
* membership (src/kalshi.ts), apart from the API: Skewtape's Kalshi data
|
|
12
|
+
* comes from the calls above.
|
|
13
|
+
*
|
|
14
|
+
* The hand-written facade lives in src/; src/generated/schema.d.ts is
|
|
15
|
+
* generated from the OpenAPI document and never edited.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export {
|
|
19
|
+
DEFAULT_BASE_URL,
|
|
20
|
+
ENV_API_KEY,
|
|
21
|
+
Paginated,
|
|
22
|
+
Skewtape,
|
|
23
|
+
activeMembers,
|
|
24
|
+
type Bundle,
|
|
25
|
+
type BundleDownloadOptions,
|
|
26
|
+
type BundleFile,
|
|
27
|
+
type Candle,
|
|
28
|
+
type CandlesOptions,
|
|
29
|
+
type DownloadURL,
|
|
30
|
+
type EventsOptions,
|
|
31
|
+
type Fee,
|
|
32
|
+
type FeesOptions,
|
|
33
|
+
type Fill,
|
|
34
|
+
type FillsOptions,
|
|
35
|
+
type Market,
|
|
36
|
+
type MarketsOptions,
|
|
37
|
+
type MatchedEvent,
|
|
38
|
+
type MatchedEventMember,
|
|
39
|
+
type Page,
|
|
40
|
+
type Resolution,
|
|
41
|
+
type ResolutionsOptions,
|
|
42
|
+
type SkBacktestOptions,
|
|
43
|
+
type SkewtapeOptions,
|
|
44
|
+
type Venue,
|
|
45
|
+
} from "./client.js";
|
|
46
|
+
export {
|
|
47
|
+
BacktestError,
|
|
48
|
+
backtestToJSON,
|
|
49
|
+
runBacktest,
|
|
50
|
+
type BacktestOptions,
|
|
51
|
+
type BacktestResult,
|
|
52
|
+
type BacktestWarning,
|
|
53
|
+
type PositionResult,
|
|
54
|
+
type Totals,
|
|
55
|
+
type Trade,
|
|
56
|
+
type TradeResult,
|
|
57
|
+
} from "./backtest.js";
|
|
58
|
+
export { downloadFile, verifyChecksums, type DownloadOptions } from "./download.js";
|
|
59
|
+
export { Rat, fractionStr, roundHalfUp } from "./exact.js";
|
|
60
|
+
export { FeeError, feeRowOf, makerFeeRaw, microsToRaw, selectFeeRow, takerFeeRaw, type FeeRow, type FeeRowInput } from "./fees.js";
|
|
61
|
+
export {
|
|
62
|
+
DEFAULT_KALSHI_BASE_URL,
|
|
63
|
+
KALSHI_VENUES,
|
|
64
|
+
Kalshi,
|
|
65
|
+
KalshiError,
|
|
66
|
+
PERIODS,
|
|
67
|
+
kalshiTickers,
|
|
68
|
+
seriesTickerOf,
|
|
69
|
+
type KalshiCandlestick,
|
|
70
|
+
type KalshiCandlesticksOptions,
|
|
71
|
+
type KalshiEventLike,
|
|
72
|
+
type KalshiLevel,
|
|
73
|
+
type KalshiMarket,
|
|
74
|
+
type KalshiMarketsOptions,
|
|
75
|
+
type KalshiOHLC,
|
|
76
|
+
type KalshiOptions,
|
|
77
|
+
type KalshiOrderbook,
|
|
78
|
+
type KalshiPeriod,
|
|
79
|
+
type KalshiTrade,
|
|
80
|
+
type KalshiTradesOptions,
|
|
81
|
+
} from "./kalshi.js";
|
|
82
|
+
export {
|
|
83
|
+
BookUnavailable,
|
|
84
|
+
DEFAULT_BOOK_READERS,
|
|
85
|
+
KALSHI_FRACTION_MICRO,
|
|
86
|
+
quoteFromContext,
|
|
87
|
+
readKalshiBook,
|
|
88
|
+
readKalshiBookThroughDflow,
|
|
89
|
+
readPolymarketBook,
|
|
90
|
+
type BookReader,
|
|
91
|
+
type BookRequest,
|
|
92
|
+
type QuoteContext,
|
|
93
|
+
type QuoteContextMember,
|
|
94
|
+
type QuoteOptions,
|
|
95
|
+
} from "./quote.js";
|
|
96
|
+
export {
|
|
97
|
+
InvalidQuoteInputError,
|
|
98
|
+
QuoteError,
|
|
99
|
+
RuleMismatchError,
|
|
100
|
+
VenueUnreachableError,
|
|
101
|
+
computeQuote,
|
|
102
|
+
type Book,
|
|
103
|
+
type Leg,
|
|
104
|
+
type Level,
|
|
105
|
+
type QuoteInput,
|
|
106
|
+
type QuoteResult,
|
|
107
|
+
type Skip,
|
|
108
|
+
type VenueQuote,
|
|
109
|
+
} from "./quote-math.js";
|
|
110
|
+
export {
|
|
111
|
+
AuthenticationError,
|
|
112
|
+
BlockedError,
|
|
113
|
+
ChecksumError,
|
|
114
|
+
ConfigurationError,
|
|
115
|
+
ForbiddenPlanError,
|
|
116
|
+
InvalidRequestError,
|
|
117
|
+
NotFoundError,
|
|
118
|
+
QuotaExceededError,
|
|
119
|
+
RateLimitError,
|
|
120
|
+
ServerError,
|
|
121
|
+
SkewtapeError,
|
|
122
|
+
} from "./errors.js";
|
|
123
|
+
export {
|
|
124
|
+
DFLOW_TRADING_API,
|
|
125
|
+
DFlowOrderRequest,
|
|
126
|
+
POLYMARKET_EXCHANGES,
|
|
127
|
+
PolymarketOrder,
|
|
128
|
+
RouteError,
|
|
129
|
+
route,
|
|
130
|
+
type DFlowRoute,
|
|
131
|
+
type PolymarketRoute,
|
|
132
|
+
type PolymarketTypedData,
|
|
133
|
+
type RouteInput,
|
|
134
|
+
} from "./route.js";
|
|
135
|
+
export {
|
|
136
|
+
HYPERLIQUID_EXCHANGE_URL,
|
|
137
|
+
HYPERLIQUID_TESTNET_EXCHANGE_URL,
|
|
138
|
+
HyperliquidApproveBuilderFee,
|
|
139
|
+
HyperliquidOrder,
|
|
140
|
+
hyperliquidApproveBuilderFee,
|
|
141
|
+
type HyperliquidRoute,
|
|
142
|
+
} from "./route-hyperliquid.js";
|
|
143
|
+
export { geoblock, type GeoblockResult, type GeoblockOptions } from "./geoblock.js";
|
|
144
|
+
export { Stream, feedUrl, type FeedMessage, type FeedSocket, type FeedSocketConstructor, type StreamOptions } from "./stream.js";
|
|
145
|
+
export { VERSION } from "./version.js";
|
|
146
|
+
export type { components, paths } from "./generated/schema.js";
|