@@ -84,7 +84,7 @@ internal class CtpTdApi(val config: CtpConfig, val kEvent: KEvent, val sourceId:
8484 /* *
8585 * 缓存的合约信息,key 为合约 code
8686 */
87- val instruments: MutableMap <String , Security > = mutableMapOf ()
87+ val instruments: MutableMap <String , SecurityInfo > = mutableMapOf ()
8888 /* *
8989 * 品种代码表,key 为合约 code,value 为品种代码(productId)。用于从 code 快速映射到 [productStatusMap]
9090 */
@@ -438,7 +438,7 @@ internal class CtpTdApi(val config: CtpConfig, val kEvent: KEvent, val sourceId:
438438 /* *
439439 * 查询某一特定合约的信息。[extras.queryFee: Boolean = false]【是否查询保证金率及手续费率,如果之前没查过,可能会耗时。当 useCache 为 false 时无效】
440440 */
441- suspend fun queryInstrument (code : String , useCache : Boolean = true, extras : Map <String , Any >? = null): Security ? {
441+ suspend fun queryInstrument (code : String , useCache : Boolean = true, extras : Map <String , Any >? = null): SecurityInfo ? {
442442 if (useCache) {
443443 val cachedInstrument = instruments[code]
444444 if (cachedInstrument != null ) {
@@ -464,13 +464,13 @@ internal class CtpTdApi(val config: CtpConfig, val kEvent: KEvent, val sourceId:
464464 /* *
465465 * 查询全市场合约的信息
466466 */
467- suspend fun queryAllInstruments (useCache : Boolean = true, extras : Map <String , Any >? = null): List <Security > {
467+ suspend fun queryAllInstruments (useCache : Boolean = true, extras : Map <String , Any >? = null): List <SecurityInfo > {
468468 if (useCache && instruments.isNotEmpty()) return instruments.values.toList()
469469 val qryField = CThostFtdcQryInstrumentField ()
470470 val requestId = nextRequestId()
471471 return runWithResultCheck({ tdApi.ReqQryInstrument (qryField, requestId) }, {
472472 suspendCoroutineWithTimeout(TIMEOUT_MILLS * 2 ) { continuation ->
473- requestMap[requestId] = RequestContinuation (requestId, continuation, data = mutableListOf<Security >())
473+ requestMap[requestId] = RequestContinuation (requestId, continuation, data = mutableListOf<SecurityInfo >())
474474 }
475475 })
476476 }
@@ -867,7 +867,7 @@ internal class CtpTdApi(val config: CtpConfig, val kEvent: KEvent, val sourceId:
867867 /* *
868868 * 获取缓存的期货/期权手续费率,如果没有,则查询后再获取
869869 */
870- private fun getOrQueryCommissionRate (instrument : Security ): CommissionRate ? {
870+ private fun getOrQueryCommissionRate (instrument : SecurityInfo ): CommissionRate ? {
871871 if (config.disableFeeCalculation) return null
872872 if (instrument.commissionRate == null ) {
873873 runBlocking { prepareFeeCalculation(instrument.code, false ) }
@@ -878,7 +878,7 @@ internal class CtpTdApi(val config: CtpConfig, val kEvent: KEvent, val sourceId:
878878 /* *
879879 * 获取缓存的期货保证金率,如果没有,则查询后再获取
880880 */
881- private fun getOrQueryMarginRate (instrument : Security ): MarginRate ? {
881+ private fun getOrQueryMarginRate (instrument : SecurityInfo ): MarginRate ? {
882882 if (config.disableFeeCalculation) return null
883883 if (instrument.marginRate == null ) {
884884 runBlocking { prepareFeeCalculation(instrument.code, false ) }
@@ -991,7 +991,7 @@ internal class CtpTdApi(val config: CtpConfig, val kEvent: KEvent, val sourceId:
991991 /* *
992992 * 计算期货保证金
993993 */
994- private fun calculateFuturesMargin (instrument : Security , direction : Direction , yesterdayVolume : Int , todayVolume : Int , avgOpenPrice : Double , fallback : Double ): Double {
994+ private fun calculateFuturesMargin (instrument : SecurityInfo , direction : Direction , yesterdayVolume : Int , todayVolume : Int , avgOpenPrice : Double , fallback : Double ): Double {
995995 if (yesterdayVolume + todayVolume == 0 ) return 0.0
996996 val marginRate = getOrQueryMarginRate(instrument) ? : return fallback
997997 val (tick, isLatestTick) = getOrQueryTick(instrument.code)
@@ -1032,7 +1032,7 @@ internal class CtpTdApi(val config: CtpConfig, val kEvent: KEvent, val sourceId:
10321032 /* *
10331033 * 计算期权保证金
10341034 */
1035- private fun calculateOptionsMargin (instrument : Security , direction : Direction , volume : Int , avgOpenPrice : Double , fallback : Double , isOpen : Boolean ): Double {
1035+ private fun calculateOptionsMargin (instrument : SecurityInfo , direction : Direction , volume : Int , avgOpenPrice : Double , fallback : Double , isOpen : Boolean ): Double {
10361036 if (volume == 0 ) return 0.0
10371037 when (direction) {
10381038 Direction .LONG -> { // 买方
@@ -1986,7 +1986,7 @@ internal class CtpTdApi(val config: CtpConfig, val kEvent: KEvent, val sourceId:
19861986 checkRspInfo(pRspInfo, {
19871987 // 如果是查询单个合约
19881988 if (reqData is String ) {
1989- val con = request.continuation as Continuation <Security ?>
1989+ val con = request.continuation as Continuation <SecurityInfo ?>
19901990 if (instrument == null ) {
19911991 con.resume(null )
19921992 requestMap.remove(nRequestID)
@@ -2002,10 +2002,10 @@ internal class CtpTdApi(val config: CtpConfig, val kEvent: KEvent, val sourceId:
20022002 }
20032003 }
20042004 } else { // 如果是查询多个合约
2005- val insList = request.data as MutableList <Security >
2005+ val insList = request.data as MutableList <SecurityInfo >
20062006 if (instrument != null ) insList.add(instrument)
20072007 if (bIsLast) {
2008- (request.continuation as Continuation <List <Security >>).resume(insList)
2008+ (request.continuation as Continuation <List <SecurityInfo >>).resume(insList)
20092009 requestMap.remove(nRequestID)
20102010 }
20112011 }
0 commit comments