mirror of
https://github.com/multipleof4/KalBot.git
synced 2026-03-16 21:41:02 +00:00
Fix: Import kalshiFetch from correct module path
This commit is contained in:
@@ -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 { db } from '../db.js';
|
||||||
import { notify } from '../notify.js';
|
import { notify } from '../notify.js';
|
||||||
import crypto from 'crypto';
|
import crypto from 'crypto';
|
||||||
@@ -96,7 +96,7 @@ export class LiveEngine {
|
|||||||
async fetchBalance() {
|
async fetchBalance() {
|
||||||
try {
|
try {
|
||||||
const data = await kalshiFetch('GET', '/trade-api/v2/portfolio/balance');
|
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;
|
this._lastPortfolioValue = data.portfolio_value || 0;
|
||||||
return {
|
return {
|
||||||
balance: this._lastBalance,
|
balance: this._lastBalance,
|
||||||
@@ -133,7 +133,6 @@ export class LiveEngine {
|
|||||||
|
|
||||||
this._resetDailyLossIfNeeded();
|
this._resetDailyLossIfNeeded();
|
||||||
|
|
||||||
// Safety: daily loss limit
|
|
||||||
if (this._dailyLoss >= this._maxDailyLossCents) {
|
if (this._dailyLoss >= this._maxDailyLossCents) {
|
||||||
console.log(`[Live] Daily loss limit ($${(this._maxDailyLossCents/100).toFixed(2)}) reached — pausing`);
|
console.log(`[Live] Daily loss limit ($${(this._maxDailyLossCents/100).toFixed(2)}) reached — pausing`);
|
||||||
this.pause();
|
this.pause();
|
||||||
@@ -148,20 +147,15 @@ export class LiveEngine {
|
|||||||
const sizeDollars = signal.size;
|
const sizeDollars = signal.size;
|
||||||
const costCents = sizeDollars * 100;
|
const costCents = sizeDollars * 100;
|
||||||
|
|
||||||
// Safety: per-trade cost cap
|
|
||||||
if (costCents > this._maxLossPerTradeCents) {
|
if (costCents > this._maxLossPerTradeCents) {
|
||||||
console.log(`[Live] Trade cost $${sizeDollars} exceeds per-trade cap — skipping`);
|
console.log(`[Live] Trade cost $${sizeDollars} exceeds per-trade cap — skipping`);
|
||||||
return null;
|
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 priceInDollars = priceCents / 100;
|
||||||
const contracts = Math.max(1, Math.floor(sizeDollars / priceInDollars));
|
const contracts = Math.max(1, Math.floor(sizeDollars / priceInDollars));
|
||||||
|
|
||||||
const clientOrderId = crypto.randomUUID();
|
const clientOrderId = crypto.randomUUID();
|
||||||
|
|
||||||
const side = signal.side.toLowerCase();
|
const side = signal.side.toLowerCase();
|
||||||
|
|
||||||
const orderBody = {
|
const orderBody = {
|
||||||
@@ -171,10 +165,9 @@ export class LiveEngine {
|
|||||||
count: contracts,
|
count: contracts,
|
||||||
type: 'limit',
|
type: 'limit',
|
||||||
client_order_id: clientOrderId,
|
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') {
|
if (side === 'yes') {
|
||||||
orderBody.yes_price = priceCents;
|
orderBody.yes_price = priceCents;
|
||||||
} else {
|
} else {
|
||||||
@@ -259,7 +252,7 @@ export class LiveEngine {
|
|||||||
|
|
||||||
const won = order.side === result;
|
const won = order.side === result;
|
||||||
const fillCostCents = order.fillCost || order.costCents;
|
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;
|
const pnl = payout - fillCostCents;
|
||||||
|
|
||||||
order.settled = true;
|
order.settled = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user