Fix: Support Kalshi v2 fixed-point fill fields

This commit is contained in:
2026-03-16 13:14:27 -07:00
parent 6faad2b28e
commit 24f1405a93

View File

@@ -124,11 +124,6 @@ export class LiveEngine {
} }
} }
/**
* Determine the best executable price from the orderbook.
* For buying yes: best ask = 100 - best_no_bid (or lowest yes offer)
* For buying no: best ask = 100 - best_yes_bid (or lowest no offer)
*/
_getBestAskFromOrderbook(side, orderbook) { _getBestAskFromOrderbook(side, orderbook) {
if (!orderbook) return null; if (!orderbook) return null;
@@ -146,6 +141,20 @@ export class LiveEngine {
return null; return null;
} }
_getFillCount(order) {
if (!order) return 0;
const fp = order.taker_fill_count_fp ?? order.fill_count_fp;
if (fp != null) return Math.round(parseFloat(fp));
return order.taker_fill_count ?? order.fill_count ?? 0;
}
_getFillCostCents(order) {
if (!order) return 0;
const dollars = order.taker_fill_cost_dollars ?? order.fill_cost_dollars;
if (dollars != null) return Math.round(parseFloat(dollars) * 100);
return order.taker_fill_cost ?? order.fill_cost ?? 0;
}
/** /**
* Verify an order's actual fill status by polling Kalshi. * Verify an order's actual fill status by polling Kalshi.
* IOC responses can report 0 fills even when fills happened async. * IOC responses can report 0 fills even when fills happened async.
@@ -158,8 +167,8 @@ export class LiveEngine {
const order = data?.order; const order = data?.order;
if (!order) continue; if (!order) continue;
const fillCount = order.taker_fill_count || order.fill_count || 0; const fillCount = this._getFillCount(order);
const fillCost = order.taker_fill_cost || order.fill_cost || 0; const fillCost = this._getFillCostCents(order);
const status = (order.status || '').toLowerCase(); const status = (order.status || '').toLowerCase();
const isFinal = ['canceled', 'cancelled', 'executed', 'filled', 'closed'].includes(status); const isFinal = ['canceled', 'cancelled', 'executed', 'filled', 'closed'].includes(status);
@@ -255,8 +264,8 @@ export class LiveEngine {
return null; return null;
} }
let fillCount = order.taker_fill_count || 0; let fillCount = this._getFillCount(order);
let fillCost = order.taker_fill_cost || 0; let fillCost = this._getFillCostCents(order);
let status = (order.status || '').toLowerCase(); let status = (order.status || '').toLowerCase();
// If immediate response says 0 fills, verify with Kalshi to catch async fills // If immediate response says 0 fills, verify with Kalshi to catch async fills