@livo-build/kit 0.2.0 → 0.2.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.
|
@@ -66,7 +66,12 @@ export interface PmHistoryPoint {
|
|
|
66
66
|
export declare function pmSnapshot(opts?: PmFeedOptions): Promise<PmSnapshot>;
|
|
67
67
|
/** Order-book depth for an outcome token (straight from the public CLOB). */
|
|
68
68
|
export declare function pmBook(tokenId: string, opts?: PmFeedOptions): Promise<PmBook>;
|
|
69
|
-
/**
|
|
69
|
+
/**
|
|
70
|
+
* Price history points for charting an outcome token. Prefers Livo's indexer (`/candles`,
|
|
71
|
+
* server-side CLOB egress on a trusted domain — works where the browser can't reach
|
|
72
|
+
* `clob.polymarket.com` directly), falling back to the public CLOB. Returns ascending
|
|
73
|
+
* `{ t, p }` points (`p` = the bucket close).
|
|
74
|
+
*/
|
|
70
75
|
export declare function pmPriceHistory(tokenId: string, params?: {
|
|
71
76
|
interval?: "1h" | "6h" | "1d" | "1w" | "max";
|
|
72
77
|
fidelity?: number;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
// Frontend-safe Polymarket client. Reads Livo's Polymarket indexer
|
|
2
|
-
// (polymarket.livo.build) for the normalized markets + odds + trades feed
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
2
|
+
// (polymarket.livo.build) for the normalized markets + odds + trades feed AND for price
|
|
3
|
+
// history (`/candles`, fetched server-side from a Polymarket-permitted region) — so the
|
|
4
|
+
// browser never calls clob.polymarket.com directly, which fails on CORS / geoblocks /
|
|
5
|
+
// TLS-cert errors in some networks/regions. Order-book DEPTH (`pmBook`) still reads the
|
|
6
|
+
// public CLOB directly (the indexer exposes no per-token book), so it inherits those
|
|
7
|
+
// limits. For TRADING, route orders through your api/ Worker (usePlaceOrder), which signs
|
|
8
|
+
// server-side with @livo-build/runtime — never ship a trading key to the browser.
|
|
6
9
|
export const POLYMARKET_FEED = "https://polymarket.livo.build";
|
|
7
10
|
export const CLOB_HOST = "https://clob.polymarket.com";
|
|
8
11
|
const feedBase = (o) => (o?.feedUrl ?? POLYMARKET_FEED).replace(/\/$/, "");
|
|
@@ -21,8 +24,29 @@ export function pmSnapshot(opts) {
|
|
|
21
24
|
export function pmBook(tokenId, opts) {
|
|
22
25
|
return getJson(`${clobBase(opts)}/book?token_id=${encodeURIComponent(tokenId)}`);
|
|
23
26
|
}
|
|
24
|
-
/**
|
|
27
|
+
/** Span (seconds) of each `interval` preset — used to size the indexer `/candles` request. */
|
|
28
|
+
const INTERVAL_SPAN_S = { "1h": 3600, "6h": 21600, "1d": 86400, "1w": 604800, max: 0 };
|
|
29
|
+
/**
|
|
30
|
+
* Price history points for charting an outcome token. Prefers Livo's indexer (`/candles`,
|
|
31
|
+
* server-side CLOB egress on a trusted domain — works where the browser can't reach
|
|
32
|
+
* `clob.polymarket.com` directly), falling back to the public CLOB. Returns ascending
|
|
33
|
+
* `{ t, p }` points (`p` = the bucket close).
|
|
34
|
+
*/
|
|
25
35
|
export async function pmPriceHistory(tokenId, params = {}, opts) {
|
|
36
|
+
const bucket = Math.max(60, (params.fidelity ?? 60) * 60); // fidelity is in MINUTES
|
|
37
|
+
const span = INTERVAL_SPAN_S[params.interval ?? "1w"] ?? 604800;
|
|
38
|
+
const limit = span > 0 ? Math.max(1, Math.min(1000, Math.round(span / bucket))) : 1000; // "max" → cap at 1000
|
|
39
|
+
// 1) Livo indexer (trusted domain, server-side CLOB egress).
|
|
40
|
+
try {
|
|
41
|
+
const j = await getJson(`${feedBase(opts)}/candles?token_id=${encodeURIComponent(tokenId)}&interval=${bucket}&limit=${limit}`);
|
|
42
|
+
const candles = j.candles ?? [];
|
|
43
|
+
if (candles.length)
|
|
44
|
+
return candles.map((c) => ({ t: c.time, p: c.c }));
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
/* indexer miss — fall back to the public CLOB below */
|
|
48
|
+
}
|
|
49
|
+
// 2) Public CLOB fallback (direct — may fail in blocked networks/regions).
|
|
26
50
|
const qs = new URLSearchParams({ market: tokenId, interval: params.interval ?? "1w" });
|
|
27
51
|
if (params.fidelity)
|
|
28
52
|
qs.set("fidelity", String(params.fidelity));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livo-build/kit",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Livo frontend kit — reusable React + wagmi v3 building blocks (wallet connect modal, providers, hooks) for web3 apps built on Livo.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "UNLICENSED",
|