11import { getErrorMessage } from '@sim/utils/errors'
22import { toRecord } from '@sim/utils/object'
3- import { kalshiCountNumber , kalshiOrderPath , kalshiOrderReadPath } from '@/tools/kalshi/orders'
3+ import {
4+ kalshiCountNumber ,
5+ kalshiLegacyOrder ,
6+ kalshiOrderPath ,
7+ kalshiOrderReadPath ,
8+ } from '@/tools/kalshi/orders'
49import type { KalshiAuthParams } from '@/tools/kalshi/types'
510import { buildKalshiAuthHeaders , buildKalshiUrl , handleKalshiError } from '@/tools/kalshi/types'
611import { KALSHI_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials'
@@ -80,7 +85,7 @@ export interface KalshiCancelOrderResponse {
8085 success : boolean
8186 error ?: string
8287 output : {
83- order : { order_id : string | null ; client_order_id : string | null ; ticker : string | null }
88+ order : Record < string , unknown >
8489 reducedBy : number
8590 }
8691}
@@ -131,19 +136,19 @@ export const kalshiCancelOrderTool: ToolConfig<KalshiCancelOrderParams, KalshiCa
131136 const data = await response . json ( )
132137
133138 if ( ! response . ok ) {
134- handleKalshiError ( data , 'cancel_order' )
139+ handleKalshiError ( data , params && cancelNeedsTicker ( params ) ? 'order read' : 'cancel_order' )
135140 }
136141
137142 // The order read that precedes a cancel with no ticker: postProcess cancels with its ticker.
138143 if ( params && cancelNeedsTicker ( params ) ) {
139144 return {
140145 success : true ,
141146 output : {
142- order : {
147+ order : kalshiLegacyOrder ( {
143148 order_id : params . orderId ,
144149 client_order_id : null ,
145150 ticker : readOrderTicker ( data ) ,
146- } ,
151+ } ) ,
147152 reducedBy : 0 ,
148153 } ,
149154 }
@@ -153,11 +158,11 @@ export const kalshiCancelOrderTool: ToolConfig<KalshiCancelOrderParams, KalshiCa
153158 return {
154159 success : true ,
155160 output : {
156- order : {
161+ order : kalshiLegacyOrder ( {
157162 order_id : data . order_id ?? null ,
158163 client_order_id : data . client_order_id ?? null ,
159164 ticker : params ?. ticker ?. trim ( ) || null ,
160- } ,
165+ } ) ,
161166 reducedBy : kalshiCountNumber ( data . reduced_by ) ?? 0 ,
162167 } ,
163168 }
@@ -283,7 +288,10 @@ export const kalshiCancelOrderV2Tool: ToolConfig<
283288 const data = await response . json ( )
284289
285290 if ( ! response . ok ) {
286- handleKalshiError ( data , 'cancel_order_v2' )
291+ handleKalshiError (
292+ data ,
293+ params && cancelNeedsTicker ( params ) ? 'order read' : 'cancel_order_v2'
294+ )
287295 }
288296
289297 // The order read that precedes a cancel with no ticker: postProcess cancels with its ticker.
0 commit comments