From 9577e55c95b04ba4eb7361e5b844b5990c5e1e5a Mon Sep 17 00:00:00 2001 From: multipleof4 Date: Mon, 16 Mar 2026 11:38:38 -0700 Subject: [PATCH] Fix: Import kalshiFetch from correct module path --- lib/live/engine.js | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/lib/live/engine.js b/lib/live/engine.js index 29d9954..a7e817d 100644 --- a/lib/live/engine.js +++ b/lib/live/engine.js @@ -1,4 +1,4 @@ -import { kalshiFetch, KALSHI_API_BASE } from '../kalshi/rest.js'; +import { kalshiFetch } from '../kalshi/rest.js'; import { db } from '../db.js'; import { notify } from '../notify.js'; import crypto from 'crypto'; @@ -96,7 +96,7 @@ export class LiveEngine { async fetchBalance() { try { const data = await kalshiFetch('GET', '/trade-api/v2/portfolio/balance'); - this._lastBalance = data.balance || 0; // cents + this._lastBalance = data.balance || 0; this._lastPortfolioValue = data.portfolio_value || 0; return { balance: this._lastBalance, @@ -133,7 +133,6 @@ export class LiveEngine { this._resetDailyLossIfNeeded(); - // Safety: daily loss limit if (this._dailyLoss >= this._maxDailyLossCents) { console.log(`[Live] Daily loss limit ($${(this._maxDailyLossCents/100).toFixed(2)}) reached — pausing`); this.pause(); @@ -148,20 +147,15 @@ export class LiveEngine { const sizeDollars = signal.size; const costCents = sizeDollars * 100; - // Safety: per-trade cost cap if (costCents > this._maxLossPerTradeCents) { console.log(`[Live] Trade cost $${sizeDollars} exceeds per-trade cap — skipping`); return null; } - // Calculate contract count: cost / price per contract - // On Kalshi, buying 1 YES contract at 40¢ costs $0.40 - // To spend $1, buy floor($1 / $0.40) = 2 contracts const priceInDollars = priceCents / 100; const contracts = Math.max(1, Math.floor(sizeDollars / priceInDollars)); const clientOrderId = crypto.randomUUID(); - const side = signal.side.toLowerCase(); const orderBody = { @@ -171,10 +165,9 @@ export class LiveEngine { count: contracts, type: 'limit', client_order_id: clientOrderId, - buy_max_cost: costCents, // FoK behavior, max cost safety + buy_max_cost: costCents, }; - // Set price based on side if (side === 'yes') { orderBody.yes_price = priceCents; } else { @@ -259,7 +252,7 @@ export class LiveEngine { const won = order.side === result; const fillCostCents = order.fillCost || order.costCents; - const payout = won ? order.contracts * 100 : 0; // $1 per winning contract + const payout = won ? order.contracts * 100 : 0; const pnl = payout - fillCostCents; order.settled = true;