MCPcopy Create free account
hub / github.com/TraderAlice/OpenAlice / decodeOrderStateFromProto

Function decodeOrderStateFromProto

packages/ibkr/src/decoder/orders.ts:370–421  ·  view source on GitHub ↗
(osp: OrderStateProto)

Source from the content-addressed store, hash-verified

368}
369
370function decodeOrderStateFromProto(osp: OrderStateProto): OrderState {
371 const os = new OrderState()
372 if (osp.status !== undefined) os.status = osp.status
373 if (osp.initMarginBefore !== undefined) os.initMarginBefore = decimalMaxString(new Decimal(osp.initMarginBefore))
374 if (osp.maintMarginBefore !== undefined) os.maintMarginBefore = decimalMaxString(new Decimal(osp.maintMarginBefore))
375 if (osp.equityWithLoanBefore !== undefined) os.equityWithLoanBefore = decimalMaxString(new Decimal(osp.equityWithLoanBefore))
376 if (osp.initMarginChange !== undefined) os.initMarginChange = decimalMaxString(new Decimal(osp.initMarginChange))
377 if (osp.maintMarginChange !== undefined) os.maintMarginChange = decimalMaxString(new Decimal(osp.maintMarginChange))
378 if (osp.equityWithLoanChange !== undefined) os.equityWithLoanChange = decimalMaxString(new Decimal(osp.equityWithLoanChange))
379 if (osp.initMarginAfter !== undefined) os.initMarginAfter = decimalMaxString(new Decimal(osp.initMarginAfter))
380 if (osp.maintMarginAfter !== undefined) os.maintMarginAfter = decimalMaxString(new Decimal(osp.maintMarginAfter))
381 if (osp.equityWithLoanAfter !== undefined) os.equityWithLoanAfter = decimalMaxString(new Decimal(osp.equityWithLoanAfter))
382 if (osp.commissionAndFees !== undefined) os.commissionAndFees = osp.commissionAndFees
383 if (osp.minCommissionAndFees !== undefined) os.minCommissionAndFees = osp.minCommissionAndFees
384 if (osp.maxCommissionAndFees !== undefined) os.maxCommissionAndFees = osp.maxCommissionAndFees
385 if (osp.commissionAndFeesCurrency !== undefined) os.commissionAndFeesCurrency = osp.commissionAndFeesCurrency
386 if (osp.warningText !== undefined) os.warningText = osp.warningText
387 if (osp.marginCurrency !== undefined) os.marginCurrency = osp.marginCurrency
388 if (osp.initMarginBeforeOutsideRTH !== undefined) os.initMarginBeforeOutsideRTH = osp.initMarginBeforeOutsideRTH
389 if (osp.maintMarginBeforeOutsideRTH !== undefined) os.maintMarginBeforeOutsideRTH = osp.maintMarginBeforeOutsideRTH
390 if (osp.equityWithLoanBeforeOutsideRTH !== undefined) os.equityWithLoanBeforeOutsideRTH = osp.equityWithLoanBeforeOutsideRTH
391 if (osp.initMarginChangeOutsideRTH !== undefined) os.initMarginChangeOutsideRTH = osp.initMarginChangeOutsideRTH
392 if (osp.maintMarginChangeOutsideRTH !== undefined) os.maintMarginChangeOutsideRTH = osp.maintMarginChangeOutsideRTH
393 if (osp.equityWithLoanChangeOutsideRTH !== undefined) os.equityWithLoanChangeOutsideRTH = osp.equityWithLoanChangeOutsideRTH
394 if (osp.initMarginAfterOutsideRTH !== undefined) os.initMarginAfterOutsideRTH = osp.initMarginAfterOutsideRTH
395 if (osp.maintMarginAfterOutsideRTH !== undefined) os.maintMarginAfterOutsideRTH = osp.maintMarginAfterOutsideRTH
396 if (osp.equityWithLoanAfterOutsideRTH !== undefined) os.equityWithLoanAfterOutsideRTH = osp.equityWithLoanAfterOutsideRTH
397 if (osp.suggestedSize !== undefined) os.suggestedSize = new Decimal(osp.suggestedSize)
398 if (osp.rejectReason !== undefined) os.rejectReason = osp.rejectReason
399
400 // order allocations
401 if (osp.orderAllocations && osp.orderAllocations.length > 0) {
402 const allocs: OrderAllocation[] = []
403 for (const oap of osp.orderAllocations) {
404 const oa = new OrderAllocation()
405 if (oap.account !== undefined) oa.account = oap.account
406 if (oap.position !== undefined) oa.position = new Decimal(oap.position)
407 if (oap.positionDesired !== undefined) oa.positionDesired = new Decimal(oap.positionDesired)
408 if (oap.positionAfter !== undefined) oa.positionAfter = new Decimal(oap.positionAfter)
409 if (oap.desiredAllocQty !== undefined) oa.desiredAllocQty = new Decimal(oap.desiredAllocQty)
410 if (oap.allowedAllocQty !== undefined) oa.allowedAllocQty = new Decimal(oap.allowedAllocQty)
411 if (oap.isMonetary !== undefined) oa.isMonetary = oap.isMonetary
412 allocs.push(oa)
413 }
414 os.orderAllocations = allocs
415 }
416
417 if (osp.completedTime !== undefined) os.completedTime = osp.completedTime
418 if (osp.completedStatus !== undefined) os.completedStatus = osp.completedStatus
419
420 return os
421}
422
423// ---------------------------------------------------------------------------
424// Apply handlers

Callers 1

applyOrderHandlersFunction · 0.85

Calls 2

pushMethod · 0.65
decimalMaxStringFunction · 0.50

Tested by

no test coverage detected