|
|
@@ -23,7 +23,7 @@ class QuoteAdapter {
|
|
|
fun buildSubscriptPacket(
|
|
|
goodsCodes: Set<String>,
|
|
|
token: String,
|
|
|
- loginID: Int
|
|
|
+ loginID: Long
|
|
|
): Packet40 {
|
|
|
// 订阅商品列表
|
|
|
val quoteSubscriptGoodsIfs: ArrayList<MoQuoteSubscriptGoodsInfo> =
|
|
|
@@ -59,7 +59,7 @@ class QuoteAdapter {
|
|
|
}
|
|
|
|
|
|
// 判断订阅是否成功
|
|
|
- val count = ByteBuffer.wrap(packet.content.sliceArray(0..4), 1, 4)
|
|
|
+ val count = ByteBuffer.wrap(packet.content.sliceArray(0 until 4), 0, 4)
|
|
|
.order(ByteOrder.BIG_ENDIAN).int
|
|
|
if (count == -1 || count == -2 || count == -3) {
|
|
|
// 订阅失败, Token校验失败, 无对应商品信息
|
|
|
@@ -72,21 +72,320 @@ class QuoteAdapter {
|
|
|
}
|
|
|
|
|
|
// 获取商品订阅信息
|
|
|
- val quoteSubscriptGoodsInfos: ArrayList<MoQuoteSubscriptGoodsInfo> = ArrayList()
|
|
|
+ val quoteSubscriptGoodsIfs: ArrayList<MoQuoteSubscriptGoodsInfo> = ArrayList()
|
|
|
try {
|
|
|
- for (i in 4..packet.content.size step 66) {
|
|
|
- quoteSubscriptGoodsInfos.add(
|
|
|
+ for (i in 4 until packet.content.size step 66) {
|
|
|
+ quoteSubscriptGoodsIfs.add(
|
|
|
MoQuoteSubscriptGoodsInfo(
|
|
|
- data = packet.content.sliceArray(
|
|
|
- i..i + 66
|
|
|
- )
|
|
|
+ data = packet.content.sliceArray(i until i + 66)
|
|
|
)
|
|
|
)
|
|
|
}
|
|
|
} catch (e: Exception) {
|
|
|
+ print(e)
|
|
|
}
|
|
|
|
|
|
- return Triple(true, null, quoteSubscriptGoodsInfos)
|
|
|
+ return Triple(true, null, quoteSubscriptGoodsIfs)
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分解实时行情数据
|
|
|
+ * @param data ByteArray 实时行情二进制数据
|
|
|
+ * @return List<Map<String, String>>? 分解后行情列表数据
|
|
|
+ */
|
|
|
+ fun splitQuoteGoods(data: ByteArray): List<Map<String, String>>? {
|
|
|
+ // 可能会传入空数组
|
|
|
+ if (data.isEmpty()) {
|
|
|
+ return null
|
|
|
+ }
|
|
|
+
|
|
|
+ // 分解行正则
|
|
|
+ val regRow = """/10\s.*?11/""".toRegex()
|
|
|
+ // 分解单行 key 正则
|
|
|
+ val regKey = """/01\s.*?02/""".toRegex()
|
|
|
+ // 分解单行 value 正则
|
|
|
+ val regValue = """/02\s.*?01|02\s.*?11/""".toRegex()
|
|
|
+
|
|
|
+ // ByteArray to Hex string
|
|
|
+ // FF 10 01 55 02 45 46 47 48 01 66 02 48 47 46 45 11 10 01 77 02 AA BB CC DD 11 00
|
|
|
+ val hexString =
|
|
|
+ data.joinToString(separator = " ") { Integer.toHexString(it.toInt()) }
|
|
|
+
|
|
|
+ val goodsQuoteTiks = arrayListOf<Map<String, String>>()
|
|
|
+
|
|
|
+ // 获取单行行情
|
|
|
+ val rows = regRow.findAll(hexString).toList().flatMap(MatchResult::groupValues)
|
|
|
+ for (row in rows) {
|
|
|
+ // 单行行情: 0x10 ... 0x01 key 0x02 value 0x01 key 0x02 value ... 0x11
|
|
|
+ // 10 01 55 02 45 46 47 48 01 66 02 48 47 46 45 11
|
|
|
+ // 获取 key value 表列
|
|
|
+ val keys = regKey.findAll(row).toList().flatMap(MatchResult::groupValues)
|
|
|
+ val values = regValue.findAll(row).toList().flatMap(MatchResult::groupValues)
|
|
|
+
|
|
|
+ // 将 key value 写入map中
|
|
|
+ val goodsQuoteTik = mutableMapOf<String, String>()
|
|
|
+ for (i in keys.indices) {
|
|
|
+ // 01 55 02
|
|
|
+ // Hex string to Int
|
|
|
+ val key = keys[i].substring(3, 5).toInt(16)
|
|
|
+
|
|
|
+ // 02 45 46 47 48 01
|
|
|
+ // 02 48 47 46 45 11
|
|
|
+ val value = values[i].split(" ").map { it.toByte(16) }.toString()
|
|
|
+ getQuoteTikField(goodsQuoteTik, key, value)
|
|
|
+ }
|
|
|
+
|
|
|
+ goodsQuoteTiks.add(goodsQuoteTik)
|
|
|
+ }
|
|
|
+
|
|
|
+ return goodsQuoteTiks
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun getQuoteTikField(goodsQuoteTik: MutableMap<String, String>, key: Int, value: String) {
|
|
|
+ when (key) {
|
|
|
+ 0x56 -> {
|
|
|
+ goodsQuoteTik["ExchangeCode"] = value }
|
|
|
+ 0x21 -> {
|
|
|
+ goodsQuoteTik["GoodsCode"] = value }
|
|
|
+ 0x24 -> {
|
|
|
+ goodsQuoteTik["Last"] = value }
|
|
|
+ 0x5B -> {
|
|
|
+ goodsQuoteTik["HoldVolume"] = value }
|
|
|
+ 0x25 -> {
|
|
|
+ goodsQuoteTik["LastVolume"] = value }
|
|
|
+ 0x3C -> {
|
|
|
+ goodsQuoteTik["PreHoldVolume"] = value }
|
|
|
+ 0x32 -> {
|
|
|
+ goodsQuoteTik["PreSettle"] = value }
|
|
|
+ 0x33 -> {
|
|
|
+ goodsQuoteTik["Settle"] = value }
|
|
|
+ 0x29 -> {
|
|
|
+ goodsQuoteTik["TotalTurnover"] = value }
|
|
|
+ 0x28 -> {
|
|
|
+ goodsQuoteTik["TotalVolume"] = value }
|
|
|
+ 0x35 -> {
|
|
|
+ goodsQuoteTik["LimitHigh"] = value }
|
|
|
+ 0x36 -> {
|
|
|
+ goodsQuoteTik["LimitLow"] = value }
|
|
|
+ "L".toInt() -> {
|
|
|
+ goodsQuoteTik["Ask"] = value }
|
|
|
+ "M".toInt() -> {
|
|
|
+ goodsQuoteTik["Ask2"] = value }
|
|
|
+ "N".toInt() -> {
|
|
|
+ goodsQuoteTik["Ask3"] = value }
|
|
|
+ "O".toInt() -> {
|
|
|
+ goodsQuoteTik["Ask4"] = value }
|
|
|
+ "P".toInt() -> {
|
|
|
+ goodsQuoteTik["Ask5"] = value }
|
|
|
+ "Q".toInt() -> {
|
|
|
+ goodsQuoteTik["AskVolume"] = value }
|
|
|
+ "R".toInt() -> {
|
|
|
+ goodsQuoteTik["AskVolume2"] = value }
|
|
|
+ "S".toInt() -> {
|
|
|
+ goodsQuoteTik["AskVolume3"] = value }
|
|
|
+ "T".toInt() -> {
|
|
|
+ goodsQuoteTik["AskVolume4"] = value }
|
|
|
+ "U".toInt() -> {
|
|
|
+ goodsQuoteTik["AskVolume5"] = value }
|
|
|
+ "B".toInt() -> {
|
|
|
+ goodsQuoteTik["Bid"] = value }
|
|
|
+ "C".toInt() -> {
|
|
|
+ goodsQuoteTik["Bid2"] = value }
|
|
|
+ "D".toInt() -> {
|
|
|
+ goodsQuoteTik["Bid3"] = value }
|
|
|
+ "E".toInt() -> {
|
|
|
+ goodsQuoteTik["Bid4"] = value }
|
|
|
+ "F".toInt() -> {
|
|
|
+ goodsQuoteTik["Bid5"] = value }
|
|
|
+ "G".toInt() -> {
|
|
|
+ goodsQuoteTik["BidVolume"] = value }
|
|
|
+ "H".toInt() -> {
|
|
|
+ goodsQuoteTik["BidVolume2"] = value }
|
|
|
+ "I".toInt() -> {
|
|
|
+ goodsQuoteTik["BidVolume3"] = value }
|
|
|
+ "J".toInt() -> {
|
|
|
+ goodsQuoteTik["BidVolume4"] = value }
|
|
|
+ "K".toInt() -> {
|
|
|
+ goodsQuoteTik["BidVolume5"] = value }
|
|
|
+ ",".toInt() -> {
|
|
|
+ goodsQuoteTik["Highest"] = value }
|
|
|
+ "-".toInt() -> {
|
|
|
+ goodsQuoteTik["Lowest"] = value }
|
|
|
+ "@".toInt() -> {
|
|
|
+ goodsQuoteTik["Date"] = value }
|
|
|
+ "A".toInt() -> {
|
|
|
+ goodsQuoteTik["Time"] = value }
|
|
|
+ "+".toInt() -> {
|
|
|
+ goodsQuoteTik["PreClose"] = value }
|
|
|
+ ".".toInt() -> {
|
|
|
+ goodsQuoteTik["Opened"] = value }
|
|
|
+ 0x5C -> {
|
|
|
+ goodsQuoteTik["ExercisePrice"] = value }
|
|
|
+ 0x7A -> {
|
|
|
+ goodsQuoteTik["Inventory"] = value }
|
|
|
+ 0x7C -> {
|
|
|
+ goodsQuoteTik["ExchangeDate"] = value }
|
|
|
+ 0x70 -> { // 1011 新增
|
|
|
+ goodsQuoteTik["strBidOrder"] = value }
|
|
|
+ 0x71 -> {
|
|
|
+ goodsQuoteTik["strBidOrder2"] = value }
|
|
|
+ 0x72 -> {
|
|
|
+ goodsQuoteTik["strBidOrder3"] = value }
|
|
|
+ 0x73 -> {
|
|
|
+ goodsQuoteTik["strBidOrder4"] = value }
|
|
|
+ 0x74 -> {
|
|
|
+ goodsQuoteTik["strBidOrder5"] = value }
|
|
|
+ 0x75 -> {
|
|
|
+ goodsQuoteTik["strAskOrder"] = value }
|
|
|
+ 0x76 -> {
|
|
|
+ goodsQuoteTik["strAskOrder2"] = value }
|
|
|
+ 0x77 -> {
|
|
|
+ goodsQuoteTik["strAskOrder3"] = value }
|
|
|
+ 0x78 -> {
|
|
|
+ goodsQuoteTik["strAskOrder4"] = value }
|
|
|
+ 0x79 -> {
|
|
|
+ goodsQuoteTik["strAskOrder5"] = value }
|
|
|
+ 0x7D -> {
|
|
|
+ goodsQuoteTik["putOptionPremiums"] = value }
|
|
|
+ 0x7E -> {
|
|
|
+ goodsQuoteTik["putOptionPremiums2"] = value }
|
|
|
+ 0x80 -> {
|
|
|
+ goodsQuoteTik["putOptionPremiums3"] = value }
|
|
|
+ 0x81 -> {
|
|
|
+ goodsQuoteTik["putOptionPremiums4"] = value }
|
|
|
+ 0x82 -> {
|
|
|
+ goodsQuoteTik["putOptionPremiums5"] = value }
|
|
|
+ 0x83 -> {
|
|
|
+ goodsQuoteTik["callOptionPremiums"] = value }
|
|
|
+ 0x84 -> {
|
|
|
+ goodsQuoteTik["callOptionPremiums2"] = value }
|
|
|
+ 0x85 -> {
|
|
|
+ goodsQuoteTik["callOptionPremiums3"] = value }
|
|
|
+ 0x86 -> {
|
|
|
+ goodsQuoteTik["callOptionPremiums4"] = value }
|
|
|
+ 0x87 -> {
|
|
|
+ goodsQuoteTik["callOptionPremiums5"] = value }
|
|
|
+ 0x7B -> {
|
|
|
+ goodsQuoteTik["orderID "] = value }
|
|
|
+ 0x88 -> { // 非交易成交总量
|
|
|
+ goodsQuoteTik["nonTotalVolume"] = value }
|
|
|
+ 0x89 -> { // 非交易总持仓量
|
|
|
+ goodsQuoteTik["nonTotalHolderVolume"] = value }
|
|
|
+ 0x8A -> { // 非交易成交总金额
|
|
|
+ goodsQuoteTik["nonTotalTurnover"] = value }
|
|
|
+ 0x8B -> { // 非交易成交总数
|
|
|
+ goodsQuoteTik["nonTotalLot"] = value }
|
|
|
+ 0x8C -> {
|
|
|
+ goodsQuoteTik["markPrice"] = value }
|
|
|
+ 0x8D -> {
|
|
|
+ goodsQuoteTik["fundSrate"] = value }
|
|
|
+ 0x92 -> {
|
|
|
+ goodsQuoteTik["BidVolume6"] = value }
|
|
|
+ 0x93 -> {
|
|
|
+ goodsQuoteTik["BidVolume7"] = value }
|
|
|
+ 0x94 -> {
|
|
|
+ goodsQuoteTik["BidVolume8"] = value }
|
|
|
+ 0x95 -> {
|
|
|
+ goodsQuoteTik["BidVolume9"] = value }
|
|
|
+ 0x96 -> {
|
|
|
+ goodsQuoteTik["BidVolume10"] = value }
|
|
|
+ 0x97 -> {
|
|
|
+ goodsQuoteTik["Ask6"] = value }
|
|
|
+ 0x98 -> {
|
|
|
+ goodsQuoteTik["Ask7"] = value }
|
|
|
+ 0x99 -> {
|
|
|
+ goodsQuoteTik["Ask8"] = value }
|
|
|
+ 0x9A -> {
|
|
|
+ goodsQuoteTik["Ask9"] = value }
|
|
|
+ 0x9B -> {
|
|
|
+ goodsQuoteTik["Ask10"] = value }
|
|
|
+ 0x9C -> {
|
|
|
+ goodsQuoteTik["AskVolume6"] = value }
|
|
|
+ 0x9D -> {
|
|
|
+ goodsQuoteTik["AskVolume7"] = value }
|
|
|
+ 0x9E -> {
|
|
|
+ goodsQuoteTik["AskVolume8"] = value }
|
|
|
+ 0xA0 -> {
|
|
|
+ goodsQuoteTik["AskVolume9"] = value }
|
|
|
+ 0xA1 -> {
|
|
|
+ goodsQuoteTik["AskVolume10"] = value }
|
|
|
+ 0xA2 -> {
|
|
|
+ goodsQuoteTik["strBidOrder6"] = value }
|
|
|
+ 0xA3 -> {
|
|
|
+ goodsQuoteTik["strBidOrder7"] = value }
|
|
|
+ 0xA4 -> {
|
|
|
+ goodsQuoteTik["strBidOrder8"] = value }
|
|
|
+ 0xA5 -> {
|
|
|
+ goodsQuoteTik["strBidOrder9"] = value }
|
|
|
+ 0xA6 -> {
|
|
|
+ goodsQuoteTik["strBidOrder10"] = value }
|
|
|
+ 0xA7 -> {
|
|
|
+ goodsQuoteTik["strAskOrder6"] = value }
|
|
|
+ 0xA8 -> {
|
|
|
+ goodsQuoteTik["strAskOrder7"] = value }
|
|
|
+ 0xA9 -> {
|
|
|
+ goodsQuoteTik["strAskOrder8"] = value }
|
|
|
+ 0xAA -> {
|
|
|
+ goodsQuoteTik["strAskOrder9"] = value }
|
|
|
+ 0xAB -> {
|
|
|
+ goodsQuoteTik["strAskOrder10"] = value }
|
|
|
+ 0xAC -> {
|
|
|
+ goodsQuoteTik["Bid6"] = value }
|
|
|
+ 0xAD -> {
|
|
|
+ goodsQuoteTik["Bid7"] = value }
|
|
|
+ 0x8E -> {
|
|
|
+ goodsQuoteTik["Bid8"] = value }
|
|
|
+ 0x90 -> {
|
|
|
+ goodsQuoteTik["Bid9"] = value }
|
|
|
+ 0x91 -> {
|
|
|
+ goodsQuoteTik["Bid10"] = value }
|
|
|
+ 0xAE -> { // 买2的订单数量
|
|
|
+ goodsQuoteTik["bidOrderVol1"] = value }
|
|
|
+ 0xAF -> { // 买2的订单数量
|
|
|
+ goodsQuoteTik["bidOrderVol2"] = value }
|
|
|
+ 0xB0 -> { // 买3的订单数量
|
|
|
+ goodsQuoteTik["bidOrderVol3"] = value }
|
|
|
+ 0xB1 -> { // 买4的订单数量
|
|
|
+ goodsQuoteTik["bidOrderVol4"] = value }
|
|
|
+ 0xB2 -> { // 买5的订单数量
|
|
|
+ goodsQuoteTik["bidOrderVol5"] = value }
|
|
|
+ 0xB3 -> { // 买6的订单数量
|
|
|
+ goodsQuoteTik["bidOrderVol6"] = value }
|
|
|
+ 0xB4 -> { // 买7的订单数量
|
|
|
+ goodsQuoteTik["bidOrderVol7"] = value }
|
|
|
+ 0xB5 -> { // 买8的订单数量
|
|
|
+ goodsQuoteTik["bidOrderVol8"] = value }
|
|
|
+ 0xB6 -> { // 买9的订单数量
|
|
|
+ goodsQuoteTik["bidOrderVol9"] = value }
|
|
|
+ 0xB7 -> { // 买10的订单数量
|
|
|
+ goodsQuoteTik["bidOrderVol10"] = value }
|
|
|
+ 0xB8 -> { // 卖1的订单数量
|
|
|
+ goodsQuoteTik["askOrderVol1"] = value }
|
|
|
+ 0xB9 -> { // 卖2的订单数量
|
|
|
+ goodsQuoteTik["askOrderVol2"] = value }
|
|
|
+ 0xBA -> { // 卖3的订单数量
|
|
|
+ goodsQuoteTik["askOrderVol3"] = value }
|
|
|
+ 0xBB -> { // 卖4的订单数量
|
|
|
+ goodsQuoteTik["askOrderVol4"] = value }
|
|
|
+ 0xBC -> { // 卖5的订单数量
|
|
|
+ goodsQuoteTik["askOrderVol5"] = value }
|
|
|
+ 0xBD -> { // 卖6的订单数量
|
|
|
+ goodsQuoteTik["askOrderVol6"] = value }
|
|
|
+ 0xBE -> { // 卖7的订单数量
|
|
|
+ goodsQuoteTik["askOrderVol7"] = value }
|
|
|
+ 0xBF -> { // 卖8的订单数量
|
|
|
+ goodsQuoteTik["askOrderVol8"] = value }
|
|
|
+ 0xC0 -> { // 卖9的订单数量
|
|
|
+ goodsQuoteTik["askOrderVol9"] = value }
|
|
|
+ 0xC1 -> { // 卖10的订单数量
|
|
|
+ goodsQuoteTik["askOrderVol10"] = value }
|
|
|
+ 0x59 -> { // 买经济盘数据
|
|
|
+ goodsQuoteTik["bidQueueInfo"] = value }
|
|
|
+ 0x5A -> { // 卖经济盘数据
|
|
|
+ goodsQuoteTik["askQueueInfo"] = value }
|
|
|
+ 0x6B -> { // 交易类型
|
|
|
+ goodsQuoteTik["publicTradetype"] = value }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|