horizon-code 0.6.0 → 0.6.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.
@@ -111,7 +111,7 @@ export async function gammaEvents(opts: { query?: string; limit?: number } = {})
111
111
  }
112
112
 
113
113
  export async function gammaEventDetail(slug: string): Promise<any> {
114
- const events = await get(`${GAMMA}/events?slug=${slug}`);
114
+ const events = await get(`${GAMMA}/events?slug=${encodeURIComponent(slug)}`);
115
115
  const event = events?.[0];
116
116
  if (!event) throw new Error(`Event not found: ${slug}`);
117
117
 
@@ -149,7 +149,7 @@ export async function gammaEventDetail(slug: string): Promise<any> {
149
149
  }
150
150
 
151
151
  export async function clobPriceHistory(slug: string, interval = "1w", fidelity = 60): Promise<any> {
152
- const events = await get(`${GAMMA}/events?slug=${slug}`);
152
+ const events = await get(`${GAMMA}/events?slug=${encodeURIComponent(slug)}`);
153
153
  const market = events?.[0]?.markets?.[0];
154
154
  if (!market) throw new Error(`Market not found: ${slug}`);
155
155
 
@@ -174,7 +174,7 @@ export async function clobPriceHistory(slug: string, interval = "1w", fidelity =
174
174
  }
175
175
 
176
176
  export async function clobOrderBook(slug: string, marketIndex = 0, outcomeIndex = 0): Promise<any> {
177
- const events = await get(`${GAMMA}/events?slug=${slug}`);
177
+ const events = await get(`${GAMMA}/events?slug=${encodeURIComponent(slug)}`);
178
178
  const market = events?.[0]?.markets?.[marketIndex];
179
179
  if (!market) throw new Error(`Market not found: ${slug}`);
180
180
 
@@ -198,7 +198,7 @@ export async function clobOrderBook(slug: string, marketIndex = 0, outcomeIndex
198
198
  }
199
199
 
200
200
  export async function polymarketTrades(slug: string): Promise<any> {
201
- const events = await get(`${GAMMA}/events?slug=${slug}`);
201
+ const events = await get(`${GAMMA}/events?slug=${encodeURIComponent(slug)}`);
202
202
  const market = events?.[0]?.markets?.[0];
203
203
  if (!market) throw new Error(`Market not found: ${slug}`);
204
204
 
@@ -233,27 +233,27 @@ export async function polymarketTrades(slug: string): Promise<any> {
233
233
 
234
234
  /** Get recent trades for a market (up to 500) */
235
235
  export async function getMarketTrades(conditionId: string, limit = 200): Promise<any[]> {
236
- const data = await get(`${DATA_API}/trades?market=${conditionId}&limit=${Math.min(limit, 500)}`).catch(() => []);
236
+ const data = await get(`${DATA_API}/trades?market=${encodeURIComponent(conditionId)}&limit=${Math.min(limit, 500)}`).catch(() => []);
237
237
  return data ?? [];
238
238
  }
239
239
 
240
240
  /** Get trades for a specific wallet (up to 500) */
241
241
  export async function getWalletTrades(address: string, limit = 200, conditionId?: string): Promise<any[]> {
242
- let url = `${DATA_API}/trades?maker_address=${address}&limit=${Math.min(limit, 500)}`;
243
- if (conditionId) url += `&market=${conditionId}`;
242
+ let url = `${DATA_API}/trades?maker_address=${encodeURIComponent(address)}&limit=${Math.min(limit, 500)}`;
243
+ if (conditionId) url += `&market=${encodeURIComponent(conditionId)}`;
244
244
  const data = await get(url).catch(() => []);
245
245
  return data ?? [];
246
246
  }
247
247
 
248
248
  /** Get open positions for a wallet */
249
249
  export async function getWalletPositions(address: string, limit = 100): Promise<any[]> {
250
- const data = await get(`${DATA_API}/positions?user=${address}&limit=${Math.min(limit, 500)}&sort_by=TOKENS`).catch(() => []);
250
+ const data = await get(`${DATA_API}/positions?user=${encodeURIComponent(address)}&limit=${Math.min(limit, 500)}&sort_by=TOKENS`).catch(() => []);
251
251
  return data ?? [];
252
252
  }
253
253
 
254
254
  /** Get wallet profile from Gamma API */
255
255
  export async function getWalletProfile(address: string): Promise<any> {
256
- const data = await get(`${GAMMA}/users?address=${address}`).catch(() => null);
256
+ const data = await get(`${GAMMA}/users?address=${encodeURIComponent(address)}`).catch(() => null);
257
257
  const user = Array.isArray(data) ? data[0] : data;
258
258
  return user ? {
259
259
  address, name: user.pseudonym ?? user.name ?? "Anonymous",
@@ -264,7 +264,7 @@ export async function getWalletProfile(address: string): Promise<any> {
264
264
 
265
265
  /** Resolve market slug → conditionId */
266
266
  export async function resolveConditionId(slug: string): Promise<{ conditionId: string; title: string; market: any }> {
267
- const events = await get(`${GAMMA}/events?slug=${slug}`);
267
+ const events = await get(`${GAMMA}/events?slug=${encodeURIComponent(slug)}`);
268
268
  const market = events?.[0]?.markets?.[0];
269
269
  if (!market) throw new Error(`Market not found: ${slug}`);
270
270
  return { conditionId: market.conditionId, title: events[0].title, market };
@@ -443,7 +443,7 @@ function formatKalshiEvent(e: any): any {
443
443
  }
444
444
 
445
445
  export async function kalshiEventDetail(ticker: string): Promise<any> {
446
- const data = await get(`${KALSHI}/events/${ticker}?with_nested_markets=true`);
446
+ const data = await get(`${KALSHI}/events/${encodeURIComponent(ticker)}?with_nested_markets=true`);
447
447
  const event = data?.event ?? data;
448
448
  if (!event) throw new Error(`Kalshi event not found: ${ticker}`);
449
449
 
@@ -457,7 +457,7 @@ export async function kalshiEventDetail(ticker: string): Promise<any> {
457
457
  }
458
458
 
459
459
  export async function kalshiOrderBook(ticker: string): Promise<any> {
460
- const book = await get(`${KALSHI}/markets/${ticker}/orderbook`);
460
+ const book = await get(`${KALSHI}/markets/${encodeURIComponent(ticker)}/orderbook`);
461
461
  const ob = book?.orderbook ?? {};
462
462
  // yes array: [[price_cents, size], ...] — bids for YES outcome
463
463
  // no array: [[price_cents, size], ...] — asks (complement pricing)
@@ -489,7 +489,7 @@ export async function kalshiPriceHistory(ticker: string, period = "1w"): Promise
489
489
  const intervalMap: Record<string, number> = { "1h": 1, "6h": 1, "1d": 60, "1w": 60, "1m": 1440, "max": 1440 };
490
490
  const periodInterval = intervalMap[period] ?? 60;
491
491
 
492
- const data = await get(`${KALSHI}/markets/${ticker}/candlesticks?period_interval=${periodInterval}`).catch(() => ({ candlesticks: [] }));
492
+ const data = await get(`${KALSHI}/markets/${encodeURIComponent(ticker)}/candlesticks?period_interval=${periodInterval}`).catch(() => ({ candlesticks: [] }));
493
493
  const candles = data?.candlesticks ?? [];
494
494
 
495
495
  // Prices can be dollar strings or cent integers — normalize to decimal