JSFiddle - React, Tailwind, and code Playground

by frogggeee McFrogggeee

JavaScript

const kalshiUrl = 'https://trading-api.kalshi.com/v1';
const ticker = 'pres';
const seriesTicker = 'presidential-elections'; // You may need to verify this
const startTs = Math.floor(Date.now() / 1000) - (24 * 60 * 60); // 24 hours ago
const endTs = Math.floor(Date.now() / 1000); // Current time
const periodInterval = 1; // 1 hour in minutes

async function getMarketCandlesticks() {
  try {
    const url = `${kalshiUrl}/markets/${ticker}/series/${seriesTicker}/candlesticks?start_ts=${startTs}&end_ts=${endTs}&period_interval=${periodInterval}`;
console.log(url)
    const response = await fetch(url, {
      method: 'GET',
      headers: {
        'Authorization': 'Cf2198cc-4535-4d42-96e8-ba96df3583d9',
        'Content-Type': 'application/json'
      }
    });

    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }

    const data = await response.json();
    console.log('Market candlesticks:', data);
    return data;
  } catch (error) {
    console.error('Error fetching market candlesticks:', error.message);
  }
}

getMarketCandlesticks();