@cesto/sdk 0.0.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.
- package/LICENSE +21 -0
- package/README.md +184 -0
- package/dist/index.cjs +394 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +573 -0
- package/dist/index.d.ts +573 -0
- package/dist/index.js +377 -0
- package/dist/index.js.map +1 -0
- package/package.json +66 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,573 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error hierarchy thrown by the SDK.
|
|
3
|
+
*
|
|
4
|
+
* Everything extends {@link CestoError}. Server (non-2xx) responses become an
|
|
5
|
+
* {@link APIError} subclass built from the API's `{ code, message, details,
|
|
6
|
+
* requestId }` envelope; transport problems become {@link APIConnectionError}
|
|
7
|
+
* (or its timeout subclass); caller cancellation becomes {@link APIUserAbortError}.
|
|
8
|
+
*/
|
|
9
|
+
/** Base class for every error the SDK throws. */
|
|
10
|
+
declare class CestoError extends Error {
|
|
11
|
+
constructor(message: string);
|
|
12
|
+
}
|
|
13
|
+
/** Parsed `{ code, message, details, requestId }` envelope from the API. */
|
|
14
|
+
interface APIErrorEnvelope {
|
|
15
|
+
code?: string;
|
|
16
|
+
message?: string;
|
|
17
|
+
details?: unknown;
|
|
18
|
+
requestId?: string;
|
|
19
|
+
}
|
|
20
|
+
/** A non-2xx HTTP response. */
|
|
21
|
+
declare class APIError extends CestoError {
|
|
22
|
+
/** HTTP status code. */
|
|
23
|
+
readonly status: number;
|
|
24
|
+
/** Machine-readable error code from the API envelope (e.g. `RESOURCE_NOT_FOUND`). */
|
|
25
|
+
readonly code?: string;
|
|
26
|
+
/** Correlation id from the API envelope, useful when reporting issues. */
|
|
27
|
+
readonly requestId?: string;
|
|
28
|
+
/** Structured error details from the API envelope. */
|
|
29
|
+
readonly details?: unknown;
|
|
30
|
+
/** Response headers. */
|
|
31
|
+
readonly headers?: Headers;
|
|
32
|
+
constructor(status: number, message: string, opts?: {
|
|
33
|
+
code?: string;
|
|
34
|
+
requestId?: string;
|
|
35
|
+
details?: unknown;
|
|
36
|
+
headers?: Headers;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
declare class BadRequestError extends APIError {
|
|
40
|
+
}
|
|
41
|
+
declare class AuthenticationError extends APIError {
|
|
42
|
+
}
|
|
43
|
+
declare class PermissionDeniedError extends APIError {
|
|
44
|
+
}
|
|
45
|
+
declare class NotFoundError extends APIError {
|
|
46
|
+
}
|
|
47
|
+
declare class ConflictError extends APIError {
|
|
48
|
+
}
|
|
49
|
+
declare class UnprocessableEntityError extends APIError {
|
|
50
|
+
}
|
|
51
|
+
/** HTTP 429. Carries `retryAfter` (ms) when the server sent a `Retry-After` header. */
|
|
52
|
+
declare class RateLimitError extends APIError {
|
|
53
|
+
/** Milliseconds to wait before retrying, derived from `Retry-After`. */
|
|
54
|
+
readonly retryAfter?: number;
|
|
55
|
+
constructor(status: number, message: string, opts?: {
|
|
56
|
+
code?: string;
|
|
57
|
+
requestId?: string;
|
|
58
|
+
details?: unknown;
|
|
59
|
+
headers?: Headers;
|
|
60
|
+
retryAfter?: number;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
declare class InternalServerError extends APIError {
|
|
64
|
+
}
|
|
65
|
+
/** A network-level failure (DNS, connection reset, fetch threw). */
|
|
66
|
+
declare class APIConnectionError extends CestoError {
|
|
67
|
+
readonly cause?: unknown;
|
|
68
|
+
constructor(message?: string, opts?: {
|
|
69
|
+
cause?: unknown;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/** The request exceeded the configured timeout. */
|
|
73
|
+
declare class APIConnectionTimeoutError extends APIConnectionError {
|
|
74
|
+
constructor(message?: string);
|
|
75
|
+
}
|
|
76
|
+
/** The caller's `AbortSignal` fired. */
|
|
77
|
+
declare class APIUserAbortError extends CestoError {
|
|
78
|
+
constructor(message?: string);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Which deployed Cesto backend to target. */
|
|
82
|
+
type CestoEnvironment = 'PRODUCTION' | 'BETA';
|
|
83
|
+
/** Options for constructing a {@link Cesto} client. */
|
|
84
|
+
interface ClientOptions {
|
|
85
|
+
/**
|
|
86
|
+
* Secret API key (`cesto_sk_…`). Required — the constructor throws if omitted.
|
|
87
|
+
* Read it from your environment yourself, e.g. `apiKey: process.env.CESTO_API_KEY`.
|
|
88
|
+
*/
|
|
89
|
+
apiKey?: string;
|
|
90
|
+
/**
|
|
91
|
+
* Which backend to target in a deployed build (`NODE_ENV=production`):
|
|
92
|
+
* `PRODUCTION` → backend.cesto.co, `BETA` → dev.backend.cesto.co. Default `PRODUCTION`.
|
|
93
|
+
*/
|
|
94
|
+
environment?: CestoEnvironment;
|
|
95
|
+
/** Per-request timeout in milliseconds. Default `60000`. */
|
|
96
|
+
timeout?: number;
|
|
97
|
+
/** Max automatic retries on transient failures. Default `2`. */
|
|
98
|
+
maxRetries?: number;
|
|
99
|
+
/** Custom fetch implementation (e.g. undici, a test mock). Default `globalThis.fetch`. */
|
|
100
|
+
fetch?: typeof fetch;
|
|
101
|
+
}
|
|
102
|
+
/** Per-request overrides accepted by every resource method. */
|
|
103
|
+
interface RequestOptions {
|
|
104
|
+
/** Override the client timeout (ms) for this request. */
|
|
105
|
+
timeout?: number;
|
|
106
|
+
/** Override the client retry count for this request (e.g. `0` to disable). */
|
|
107
|
+
maxRetries?: number;
|
|
108
|
+
/** Caller cancellation; composed with the internal timeout signal. */
|
|
109
|
+
signal?: AbortSignal;
|
|
110
|
+
}
|
|
111
|
+
/** Fully-resolved, validated client configuration. */
|
|
112
|
+
interface ResolvedOptions {
|
|
113
|
+
apiKey: string;
|
|
114
|
+
/** Normalized base URL, no trailing slash. */
|
|
115
|
+
baseURL: string;
|
|
116
|
+
timeout: number;
|
|
117
|
+
maxRetries: number;
|
|
118
|
+
fetch: typeof fetch;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** Backtest chart window. Only `1y` carries full portfolio metrics. */
|
|
122
|
+
type ChartTimeRange = '7d' | '1m' | '3m' | '6m' | '1y' | 'all';
|
|
123
|
+
type PredictionProtocol = 'kalshi' | 'polymarket';
|
|
124
|
+
type PredictionSide = 'YES' | 'NO';
|
|
125
|
+
type MarketStatus = 'initialized' | 'active' | 'inactive' | 'closed' | 'determined' | 'finalized';
|
|
126
|
+
/** Whether the requester's region may view / invest in a product. */
|
|
127
|
+
interface GeoStatus {
|
|
128
|
+
canView: boolean;
|
|
129
|
+
canInvest: boolean;
|
|
130
|
+
}
|
|
131
|
+
/** One incentive campaign overlaid on a product. */
|
|
132
|
+
interface IncentiveOverlayCampaign {
|
|
133
|
+
campaignId: string;
|
|
134
|
+
slug: string;
|
|
135
|
+
partnerName: string;
|
|
136
|
+
rewardTokenSymbol: string;
|
|
137
|
+
rewardTokenMint: string;
|
|
138
|
+
/** Campaign APY in percent, or null when TVL is 0 / not yet computed. */
|
|
139
|
+
apy: number | null;
|
|
140
|
+
/** ISO timestamp. */
|
|
141
|
+
endsAt: string;
|
|
142
|
+
tvlUsd: string;
|
|
143
|
+
pointsMultiplier: string | null;
|
|
144
|
+
}
|
|
145
|
+
/** Prediction-market performance (present only for prediction-market products). */
|
|
146
|
+
interface PredictionPerformance {
|
|
147
|
+
roi: number;
|
|
148
|
+
impliedProbability: number;
|
|
149
|
+
daysToExpiration: number;
|
|
150
|
+
/** ISO timestamp. */
|
|
151
|
+
expirationDate: string;
|
|
152
|
+
}
|
|
153
|
+
/** Backtested token/basket performance over a window. */
|
|
154
|
+
interface TokenPerformance {
|
|
155
|
+
avgPercentChange?: number;
|
|
156
|
+
daysAvailable?: number;
|
|
157
|
+
startDate?: string;
|
|
158
|
+
endDate?: string;
|
|
159
|
+
annualizedReturn?: number;
|
|
160
|
+
return?: number;
|
|
161
|
+
netPnL?: number | null;
|
|
162
|
+
pricePnL?: number | null;
|
|
163
|
+
netAPY?: number | null;
|
|
164
|
+
priceAPY?: number | null;
|
|
165
|
+
yieldBreakdown?: {
|
|
166
|
+
pricePnL: number;
|
|
167
|
+
yieldPnL: number;
|
|
168
|
+
netPnL: number;
|
|
169
|
+
priceAPY: number;
|
|
170
|
+
netAPY: number;
|
|
171
|
+
annualizedReturn: number;
|
|
172
|
+
} | null;
|
|
173
|
+
predictionPerformance?: PredictionPerformance | null;
|
|
174
|
+
/** Incentive overlay (added per window when campaigns apply). */
|
|
175
|
+
incentiveAPY?: number;
|
|
176
|
+
totalAPY?: number;
|
|
177
|
+
}
|
|
178
|
+
/** Live state of a prediction market attached to a product. */
|
|
179
|
+
interface PredictionMarketState {
|
|
180
|
+
marketTicker: string;
|
|
181
|
+
protocol: PredictionProtocol;
|
|
182
|
+
side: PredictionSide;
|
|
183
|
+
title?: string;
|
|
184
|
+
/** Unix seconds. */
|
|
185
|
+
closeTime: number;
|
|
186
|
+
status: MarketStatus;
|
|
187
|
+
result?: 'yes' | 'no';
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** Product summary attached to a position. */
|
|
191
|
+
interface PositionProduct {
|
|
192
|
+
id: string;
|
|
193
|
+
name: string;
|
|
194
|
+
slug: string;
|
|
195
|
+
category: string | null;
|
|
196
|
+
logoUrl: string | null;
|
|
197
|
+
isActive: boolean;
|
|
198
|
+
}
|
|
199
|
+
/** The product version a position currently tracks. */
|
|
200
|
+
interface PositionVersion {
|
|
201
|
+
id: string;
|
|
202
|
+
version: number;
|
|
203
|
+
isDeprecated: boolean;
|
|
204
|
+
}
|
|
205
|
+
/** One underlying investment row within a position (transparency view). */
|
|
206
|
+
interface PositionInvestment {
|
|
207
|
+
id: string;
|
|
208
|
+
/** Invested amount in token base units. */
|
|
209
|
+
totalInvested: string;
|
|
210
|
+
totalInvestedUsd: string;
|
|
211
|
+
tokenMint: string;
|
|
212
|
+
tokenDecimals: number;
|
|
213
|
+
/** ISO timestamp. */
|
|
214
|
+
openedAt: string;
|
|
215
|
+
closedAt: string | null;
|
|
216
|
+
closedReason: string | null;
|
|
217
|
+
creationType: string | null;
|
|
218
|
+
executionStatus: string | null;
|
|
219
|
+
/** UI-facing status, e.g. `Active`, `Closing`, `Scheduled`. */
|
|
220
|
+
displayStatus: string;
|
|
221
|
+
partialReason: string | null;
|
|
222
|
+
openingExecutionId: string | null;
|
|
223
|
+
scheduledToOpenAt: string | null;
|
|
224
|
+
closingExecutionId: string | null;
|
|
225
|
+
closeExecutionStatus: string | null;
|
|
226
|
+
scheduledToCloseAt: string | null;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Aggregated valuation for a position (live + partial buckets).
|
|
230
|
+
*
|
|
231
|
+
* The bucket internals mirror the API's portfolio aggregation and are treated as
|
|
232
|
+
* loosely-typed until the `/v1` route formalizes them; `totalCurrentValueUsd` is
|
|
233
|
+
* the field most consumers read.
|
|
234
|
+
*/
|
|
235
|
+
interface PositionValuation {
|
|
236
|
+
live?: Record<string, unknown>;
|
|
237
|
+
partial?: Record<string, unknown>;
|
|
238
|
+
calculatedAt?: string;
|
|
239
|
+
}
|
|
240
|
+
/** A live position — one entry per (user, product). */
|
|
241
|
+
interface Position {
|
|
242
|
+
productId: string;
|
|
243
|
+
product: PositionProduct;
|
|
244
|
+
currentVersion: PositionVersion | null;
|
|
245
|
+
aggregatedData: PositionValuation | null;
|
|
246
|
+
investments: PositionInvestment[];
|
|
247
|
+
incentives: {
|
|
248
|
+
campaigns: IncentiveOverlayCampaign[];
|
|
249
|
+
};
|
|
250
|
+
cacheMetadata: {
|
|
251
|
+
calculatedAt: string;
|
|
252
|
+
expiresAt: string;
|
|
253
|
+
} | null;
|
|
254
|
+
}
|
|
255
|
+
/** Result of `positions.list({ wallet })`. */
|
|
256
|
+
interface PositionsResult {
|
|
257
|
+
positions: Position[];
|
|
258
|
+
pendingClosePositions: Position[];
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** Query parameters; `undefined`/`null` values are skipped. */
|
|
262
|
+
type QueryParams = Record<string, string | number | boolean | undefined | null>;
|
|
263
|
+
interface GetOptions extends RequestOptions {
|
|
264
|
+
query?: QueryParams;
|
|
265
|
+
}
|
|
266
|
+
/** Internal transport: builds requests, applies auth, retries, and parses JSON. */
|
|
267
|
+
declare class APIClientCore {
|
|
268
|
+
private readonly opts;
|
|
269
|
+
constructor(opts: ResolvedOptions);
|
|
270
|
+
get<T>(path: string, options?: GetOptions): Promise<T>;
|
|
271
|
+
private request;
|
|
272
|
+
private buildURL;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** Base class for resource groups; holds a reference to the transport. */
|
|
276
|
+
declare abstract class APIResource {
|
|
277
|
+
protected readonly client: APIClientCore;
|
|
278
|
+
constructor(client: APIClientCore);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
interface PositionsListParams {
|
|
282
|
+
/** External Solana wallet address (Phantom/Solflare). Required. */
|
|
283
|
+
wallet: string;
|
|
284
|
+
}
|
|
285
|
+
declare class Positions extends APIResource {
|
|
286
|
+
/**
|
|
287
|
+
* List a user's open/closing positions, resolved from their external Solana
|
|
288
|
+
* wallet. A wallet with no Cesto account returns an empty result (not an error).
|
|
289
|
+
*/
|
|
290
|
+
list(params: PositionsListParams, options?: RequestOptions): Promise<PositionsResult>;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/** An item in `products.list()` — `GET /products`. */
|
|
294
|
+
interface ProductListItem {
|
|
295
|
+
id: string;
|
|
296
|
+
slug: string;
|
|
297
|
+
name: string;
|
|
298
|
+
description: string | null;
|
|
299
|
+
logoUrl: string | null;
|
|
300
|
+
category: string | null;
|
|
301
|
+
tags: string[];
|
|
302
|
+
isActive: boolean;
|
|
303
|
+
isPublished: boolean;
|
|
304
|
+
pointMultiplier: number;
|
|
305
|
+
metadata: Record<string, unknown> | null;
|
|
306
|
+
geoStatus: GeoStatus;
|
|
307
|
+
/** Active incentive campaigns; `[]` when none. */
|
|
308
|
+
incentives: IncentiveOverlayCampaign[];
|
|
309
|
+
}
|
|
310
|
+
/** Backtested performance for a product — `GET /products/analytics` (per product). */
|
|
311
|
+
interface ProductBacktest {
|
|
312
|
+
protocolsInvolved: string[];
|
|
313
|
+
tokensInvolved: string[];
|
|
314
|
+
tokenPerformance: TokenPerformance | null;
|
|
315
|
+
tokenPerformance7d: TokenPerformance | null;
|
|
316
|
+
tokenPerformance30d: TokenPerformance | null;
|
|
317
|
+
priceChange24h: number | null;
|
|
318
|
+
tokenPriceChanges: Record<string, {
|
|
319
|
+
priceChange24h: number | null;
|
|
320
|
+
priceChange24hPercent: number | null;
|
|
321
|
+
}>;
|
|
322
|
+
}
|
|
323
|
+
/** `products.list({ includeBacktest: true })` — list item with backtest merged in. */
|
|
324
|
+
type ProductWithBacktest = ProductListItem & {
|
|
325
|
+
backtest: ProductBacktest | null;
|
|
326
|
+
};
|
|
327
|
+
interface ProductCreator {
|
|
328
|
+
id: string;
|
|
329
|
+
username: string | null;
|
|
330
|
+
email: string | null;
|
|
331
|
+
solanaWalletAddress: string | null;
|
|
332
|
+
embeddedWalletAddress: string | null;
|
|
333
|
+
}
|
|
334
|
+
interface OndoTradingStatus {
|
|
335
|
+
allTradable: boolean;
|
|
336
|
+
currentSession: string;
|
|
337
|
+
hasOndoTokens: boolean;
|
|
338
|
+
tokens: unknown[];
|
|
339
|
+
untradableTokens: unknown[];
|
|
340
|
+
nextFullyTradableAt: string | null;
|
|
341
|
+
nextFullyTradableSession: string | null;
|
|
342
|
+
}
|
|
343
|
+
/** Full product detail — `GET /products/:slug`. */
|
|
344
|
+
interface ProductVersionResponse {
|
|
345
|
+
id: string;
|
|
346
|
+
versionId: string;
|
|
347
|
+
version: number;
|
|
348
|
+
changelog: string | null;
|
|
349
|
+
minimumInvestment: string;
|
|
350
|
+
inputTokenMint: string;
|
|
351
|
+
inputTokenDecimals: number;
|
|
352
|
+
about: string | null;
|
|
353
|
+
riskNotes: string | null;
|
|
354
|
+
resources: string | null;
|
|
355
|
+
name: string;
|
|
356
|
+
slug: string;
|
|
357
|
+
description: string | null;
|
|
358
|
+
logoUrl: string | null;
|
|
359
|
+
category: string | null;
|
|
360
|
+
tags: string[];
|
|
361
|
+
isActive: boolean;
|
|
362
|
+
isPublished: boolean;
|
|
363
|
+
metadata: Record<string, unknown> | null;
|
|
364
|
+
pointMultiplier: number;
|
|
365
|
+
createdBy: string;
|
|
366
|
+
creator: ProductCreator | null;
|
|
367
|
+
tokensInvolved: string[];
|
|
368
|
+
protocolsInvolved: string[];
|
|
369
|
+
tokenPerformance: TokenPerformance | null;
|
|
370
|
+
tokenPerformance7d: TokenPerformance | null;
|
|
371
|
+
tokenPerformance30d: TokenPerformance | null;
|
|
372
|
+
predictionMarkets?: PredictionMarketState[];
|
|
373
|
+
canInvest: boolean;
|
|
374
|
+
/** Raw workflow definition. */
|
|
375
|
+
definition: unknown;
|
|
376
|
+
geoStatus: GeoStatus;
|
|
377
|
+
ondoTradingStatus: OndoTradingStatus;
|
|
378
|
+
incentives?: IncentiveOverlayCampaign[];
|
|
379
|
+
}
|
|
380
|
+
interface BacktestChartTimeSeriesPoint {
|
|
381
|
+
timestamp: string;
|
|
382
|
+
portfolioValue: number;
|
|
383
|
+
sp500Value?: number;
|
|
384
|
+
mag7Value?: number;
|
|
385
|
+
btcValue?: number;
|
|
386
|
+
solValue?: number;
|
|
387
|
+
usdcValue?: number;
|
|
388
|
+
isLiquidated?: boolean;
|
|
389
|
+
liquidationThreshold?: number;
|
|
390
|
+
}
|
|
391
|
+
interface BacktestChartMetrics {
|
|
392
|
+
totalReturn: number;
|
|
393
|
+
cagr: number;
|
|
394
|
+
volatility: number;
|
|
395
|
+
maxDrawdown: number;
|
|
396
|
+
sharpe: number;
|
|
397
|
+
}
|
|
398
|
+
interface PredictionMarketEvent {
|
|
399
|
+
ticker: string;
|
|
400
|
+
marketTicker: string;
|
|
401
|
+
seriesTicker: string;
|
|
402
|
+
title: string;
|
|
403
|
+
closeTime: number;
|
|
404
|
+
currentProbability?: number;
|
|
405
|
+
currentPrice: number;
|
|
406
|
+
daysToClose: number;
|
|
407
|
+
timeSeries: Array<{
|
|
408
|
+
market_ticker: string;
|
|
409
|
+
event_ticker: string;
|
|
410
|
+
raw_numerical_forecast: number;
|
|
411
|
+
numerical_forecast: number;
|
|
412
|
+
formatted_forecast: string;
|
|
413
|
+
end_period_ts: number;
|
|
414
|
+
period_interval: number;
|
|
415
|
+
}>;
|
|
416
|
+
}
|
|
417
|
+
/** Token-portfolio backtest chart — `GET /products/:id/graph` (non-prediction). */
|
|
418
|
+
interface BacktestChart {
|
|
419
|
+
workflowId: string;
|
|
420
|
+
name: string;
|
|
421
|
+
timeRange?: ChartTimeRange;
|
|
422
|
+
timeSeries: BacktestChartTimeSeriesPoint[];
|
|
423
|
+
/** Computed only when `timeRange === '1y'`; null otherwise. */
|
|
424
|
+
metrics: BacktestChartMetrics | null;
|
|
425
|
+
assetPerformance: Array<{
|
|
426
|
+
token: string;
|
|
427
|
+
mint: string;
|
|
428
|
+
returnPct: number;
|
|
429
|
+
}>;
|
|
430
|
+
contributions: Array<{
|
|
431
|
+
token: string;
|
|
432
|
+
mint: string;
|
|
433
|
+
contribution: number;
|
|
434
|
+
}>;
|
|
435
|
+
assetSparklines: Array<{
|
|
436
|
+
token: string;
|
|
437
|
+
mint: string;
|
|
438
|
+
points: Array<{
|
|
439
|
+
timestamp: string;
|
|
440
|
+
value: number;
|
|
441
|
+
price: number;
|
|
442
|
+
}>;
|
|
443
|
+
}>;
|
|
444
|
+
checkpoints?: Array<{
|
|
445
|
+
timestamp: string;
|
|
446
|
+
version: number;
|
|
447
|
+
fromVersion: number | null;
|
|
448
|
+
changelog: string | null;
|
|
449
|
+
added: Array<{
|
|
450
|
+
token: string;
|
|
451
|
+
mint: string;
|
|
452
|
+
allocation: number;
|
|
453
|
+
}>;
|
|
454
|
+
removed: Array<{
|
|
455
|
+
token: string;
|
|
456
|
+
mint: string;
|
|
457
|
+
allocation: number;
|
|
458
|
+
}>;
|
|
459
|
+
reweighted: Array<{
|
|
460
|
+
token: string;
|
|
461
|
+
mint: string;
|
|
462
|
+
fromPct: number;
|
|
463
|
+
toPct: number;
|
|
464
|
+
}>;
|
|
465
|
+
}>;
|
|
466
|
+
liquidationInfo?: {
|
|
467
|
+
hasLiquidations: boolean;
|
|
468
|
+
liquidationEvents: Array<{
|
|
469
|
+
timestamp: string;
|
|
470
|
+
asset: string;
|
|
471
|
+
liquidationPrice: number;
|
|
472
|
+
actualPrice: number;
|
|
473
|
+
}>;
|
|
474
|
+
liquidationThresholds: Array<{
|
|
475
|
+
asset: string;
|
|
476
|
+
mint: string;
|
|
477
|
+
liquidationPrice: number;
|
|
478
|
+
entryPrice: number;
|
|
479
|
+
leverage: number;
|
|
480
|
+
direction: 'LONG' | 'SHORT';
|
|
481
|
+
}>;
|
|
482
|
+
};
|
|
483
|
+
hasPredictionMarkets?: boolean;
|
|
484
|
+
predictionMarketEvents?: PredictionMarketEvent[];
|
|
485
|
+
incentives?: IncentiveOverlayCampaign[];
|
|
486
|
+
}
|
|
487
|
+
/** Prediction-market backtest chart — `GET /products/:id/graph` (prediction). */
|
|
488
|
+
interface PredictionMarketChart {
|
|
489
|
+
workflowId: string;
|
|
490
|
+
name: string;
|
|
491
|
+
predictionMarket: boolean;
|
|
492
|
+
markets: PredictionMarketEvent[];
|
|
493
|
+
incentives?: IncentiveOverlayCampaign[];
|
|
494
|
+
}
|
|
495
|
+
/** Union returned by the graph endpoint. Discriminate with {@link isPredictionMarketChart}. */
|
|
496
|
+
type ProductBacktestChart = BacktestChart | PredictionMarketChart;
|
|
497
|
+
/** `products.get(slug, { includeBacktestChart: true })` — detail with chart merged in. */
|
|
498
|
+
type ProductWithBacktestChart = ProductVersionResponse & {
|
|
499
|
+
backtestChart: ProductBacktestChart | null;
|
|
500
|
+
};
|
|
501
|
+
/** Type guard: is this chart the prediction-market variant? */
|
|
502
|
+
declare function isPredictionMarketChart(chart: ProductBacktestChart): chart is PredictionMarketChart;
|
|
503
|
+
|
|
504
|
+
interface ProductListParams {
|
|
505
|
+
/** Filter by category. */
|
|
506
|
+
category?: string;
|
|
507
|
+
/**
|
|
508
|
+
* Also fetch backtested performance (`GET /products/analytics`) and merge it
|
|
509
|
+
* onto each product as `backtest`. Fails gracefully → `backtest: null`.
|
|
510
|
+
*/
|
|
511
|
+
includeBacktest?: boolean;
|
|
512
|
+
}
|
|
513
|
+
interface ProductGetParams {
|
|
514
|
+
/**
|
|
515
|
+
* Also fetch the product's backtested value chart and attach it as `backtestChart`.
|
|
516
|
+
* Fails gracefully → `backtestChart: null`.
|
|
517
|
+
*/
|
|
518
|
+
includeBacktestChart?: boolean;
|
|
519
|
+
/** Chart window when `includeBacktestChart` is true. Default `'1y'`. */
|
|
520
|
+
chartTimeRange?: ChartTimeRange;
|
|
521
|
+
}
|
|
522
|
+
declare class Products extends APIResource {
|
|
523
|
+
/** List products. */
|
|
524
|
+
list(): Promise<ProductListItem[]>;
|
|
525
|
+
list(params: ProductListParams & {
|
|
526
|
+
includeBacktest?: false;
|
|
527
|
+
}, options?: RequestOptions): Promise<ProductListItem[]>;
|
|
528
|
+
list(params: ProductListParams & {
|
|
529
|
+
includeBacktest: true;
|
|
530
|
+
}, options?: RequestOptions): Promise<ProductWithBacktest[]>;
|
|
531
|
+
/** Get a product by slug. */
|
|
532
|
+
get(slug: string): Promise<ProductVersionResponse>;
|
|
533
|
+
get(slug: string, params: ProductGetParams & {
|
|
534
|
+
includeBacktestChart?: false;
|
|
535
|
+
}, options?: RequestOptions): Promise<ProductVersionResponse>;
|
|
536
|
+
get(slug: string, params: ProductGetParams & {
|
|
537
|
+
includeBacktestChart: true;
|
|
538
|
+
}, options?: RequestOptions): Promise<ProductWithBacktestChart>;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* The Cesto SDK client.
|
|
543
|
+
*
|
|
544
|
+
* @example
|
|
545
|
+
* ```ts
|
|
546
|
+
* const cesto = new Cesto({ apiKey: process.env.CESTO_API_KEY! });
|
|
547
|
+
* const products = await cesto.products.list({ includeBacktest: true });
|
|
548
|
+
* ```
|
|
549
|
+
*/
|
|
550
|
+
declare class Cesto {
|
|
551
|
+
readonly products: Products;
|
|
552
|
+
readonly positions: Positions;
|
|
553
|
+
private readonly core;
|
|
554
|
+
constructor(options?: ClientOptions);
|
|
555
|
+
static readonly CestoError: typeof CestoError;
|
|
556
|
+
static readonly APIError: typeof APIError;
|
|
557
|
+
static readonly BadRequestError: typeof BadRequestError;
|
|
558
|
+
static readonly AuthenticationError: typeof AuthenticationError;
|
|
559
|
+
static readonly PermissionDeniedError: typeof PermissionDeniedError;
|
|
560
|
+
static readonly NotFoundError: typeof NotFoundError;
|
|
561
|
+
static readonly ConflictError: typeof ConflictError;
|
|
562
|
+
static readonly UnprocessableEntityError: typeof UnprocessableEntityError;
|
|
563
|
+
static readonly RateLimitError: typeof RateLimitError;
|
|
564
|
+
static readonly InternalServerError: typeof InternalServerError;
|
|
565
|
+
static readonly APIConnectionError: typeof APIConnectionError;
|
|
566
|
+
static readonly APIConnectionTimeoutError: typeof APIConnectionTimeoutError;
|
|
567
|
+
static readonly APIUserAbortError: typeof APIUserAbortError;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
/** SDK version. Keep in sync with package.json `version`. */
|
|
571
|
+
declare const VERSION = "0.0.1";
|
|
572
|
+
|
|
573
|
+
export { APIConnectionError, APIConnectionTimeoutError, APIError, type APIErrorEnvelope, APIUserAbortError, AuthenticationError, type BacktestChart, type BacktestChartMetrics, type BacktestChartTimeSeriesPoint, BadRequestError, Cesto, type CestoEnvironment, CestoError, type ChartTimeRange, type ClientOptions, ConflictError, type GeoStatus, type IncentiveOverlayCampaign, InternalServerError, type MarketStatus, NotFoundError, type OndoTradingStatus, PermissionDeniedError, type Position, type PositionInvestment, type PositionProduct, type PositionValuation, type PositionVersion, type PositionsListParams, type PositionsResult, type PredictionMarketChart, type PredictionMarketEvent, type PredictionMarketState, type PredictionPerformance, type PredictionProtocol, type PredictionSide, type ProductBacktest, type ProductBacktestChart, type ProductCreator, type ProductGetParams, type ProductListItem, type ProductListParams, type ProductVersionResponse, type ProductWithBacktest, type ProductWithBacktestChart, RateLimitError, type RequestOptions, type TokenPerformance, UnprocessableEntityError, VERSION, isPredictionMarketChart };
|