mirror of
https://github.com/multipleof4/KalBot.git
synced 2026-03-16 21:41:02 +00:00
Fix: Support Kalshi v2 fixed-point fill fields
This commit is contained in:
@@ -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) {
|
||||
if (!orderbook) return null;
|
||||
|
||||
@@ -146,6 +141,20 @@ export class LiveEngine {
|
||||
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.
|
||||
* IOC responses can report 0 fills even when fills happened async.
|
||||
@@ -158,8 +167,8 @@ export class LiveEngine {
|
||||
const order = data?.order;
|
||||
if (!order) continue;
|
||||
|
||||
const fillCount = order.taker_fill_count || order.fill_count || 0;
|
||||
const fillCost = order.taker_fill_cost || order.fill_cost || 0;
|
||||
const fillCount = this._getFillCount(order);
|
||||
const fillCost = this._getFillCostCents(order);
|
||||
const status = (order.status || '').toLowerCase();
|
||||
const isFinal = ['canceled', 'cancelled', 'executed', 'filled', 'closed'].includes(status);
|
||||
|
||||
@@ -255,8 +264,8 @@ export class LiveEngine {
|
||||
return null;
|
||||
}
|
||||
|
||||
let fillCount = order.taker_fill_count || 0;
|
||||
let fillCost = order.taker_fill_cost || 0;
|
||||
let fillCount = this._getFillCount(order);
|
||||
let fillCost = this._getFillCostCents(order);
|
||||
let status = (order.status || '').toLowerCase();
|
||||
|
||||
// If immediate response says 0 fills, verify with Kalshi to catch async fills
|
||||
|
||||
Reference in New Issue
Block a user