|
@@ -72,9 +72,9 @@ class JDNewTradeAccountDetailViewModel {
|
|
var lastUpdate: TimeInterval = Date().timeIntervalSince1970
|
|
var lastUpdate: TimeInterval = Date().timeIntervalSince1970
|
|
|
|
|
|
// 持仓列表待更新的列表项
|
|
// 持仓列表待更新的列表项
|
|
- let holdUpdatedIndexPath = MutableProperty<IndexPath?>(nil)
|
|
|
|
|
|
+ let holdUpdatedIndexPath = MutableProperty<Array<IndexPath>?>(nil)
|
|
// 挂单列表待更新的列表项
|
|
// 挂单列表待更新的列表项
|
|
- let hangUpdatedIndexPath = MutableProperty<IndexPath?>(nil)
|
|
|
|
|
|
+ let hangUpdatedIndexPath = MutableProperty<Array<IndexPath>?>(nil)
|
|
|
|
|
|
|
|
|
|
init(accountModel: JDTradeAccountModel) {
|
|
init(accountModel: JDTradeAccountModel) {
|
|
@@ -410,7 +410,14 @@ extension JDNewTradeAccountDetailViewModel {
|
|
guard let currentSocket = dict.object(forKey: "currentSocket") as? NSDictionary else {return}
|
|
guard let currentSocket = dict.object(forKey: "currentSocket") as? NSDictionary else {return}
|
|
guard let symbol = currentSocket["symbol"] as? String else {return}
|
|
guard let symbol = currentSocket["symbol"] as? String else {return}
|
|
if type == 0 {
|
|
if type == 0 {
|
|
- updatePrice(symbol: currentSocket)
|
|
|
|
|
|
+ guard let currentSocket = dict.object(forKey: "currentSocket") as? NSDictionary else { return }
|
|
|
|
+ guard let currentType = currentSocket["type"] as? String else { return }
|
|
|
|
+
|
|
|
|
+ if(currentType == "depth"){
|
|
|
|
+ updateDepth(symbol: currentSocket)
|
|
|
|
+ }else if(currentType == "price"){
|
|
|
|
+ updatePrice(symbol: currentSocket)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
else if type == 1 {
|
|
else if type == 1 {
|
|
let isUpdateHold = positionList.contains {$0.symbol == symbol}
|
|
let isUpdateHold = positionList.contains {$0.symbol == symbol}
|
|
@@ -421,6 +428,50 @@ extension JDNewTradeAccountDetailViewModel {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ func updateDepth(symbol: NSDictionary){
|
|
|
|
+ guard let symbol_str = symbol["symbol"] as? String else {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if symbol_str.count == 0 {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if let marketDepthModel = MarketDepthModel.deserialize(from: symbol) {
|
|
|
|
+
|
|
|
|
+ guard let model = self.productList[symbol_str] else {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ model.ask = marketDepthModel.asks[0].price
|
|
|
|
+ model.bid = marketDepthModel.bids[0].price
|
|
|
|
+ BaseProductList.shareInstance.updateProductInfo(model: model)
|
|
|
|
+ if self.current_select_index == 0 {
|
|
|
|
+ let indices = self.positionList.enumerated().compactMap { (index, item) -> Int? in
|
|
|
|
+ if(item.symbol == symbol_str){
|
|
|
|
+ item.productBean.ask = model.ask
|
|
|
|
+ item.productBean.bid = model.bid
|
|
|
|
+ item.SymbolModel.ask = model.ask
|
|
|
|
+ item.SymbolModel.bid = model.bid
|
|
|
|
+ return index
|
|
|
|
+ }
|
|
|
|
+ return nil
|
|
|
|
+ }
|
|
|
|
+ // 将索引集合转换为 IndexPath 集合
|
|
|
|
+ let indexPaths = indices.map { IndexPath(row: $0, section: 0) }
|
|
|
|
+
|
|
|
|
+ self.holdUpdatedIndexPath.value = indexPaths
|
|
|
|
+ }else if(self.current_select_index == 1){
|
|
|
|
+ let indices = self.entrustList.enumerated().compactMap { (index, item) -> Int? in
|
|
|
|
+ return item.symbol == symbol_str ? index : nil
|
|
|
|
+ }
|
|
|
|
+ // 将索引集合转换为 IndexPath 集合
|
|
|
|
+ let indexPaths = indices.map { IndexPath(row: $0, section: 0) }
|
|
|
|
+
|
|
|
|
+ self.hangUpdatedIndexPath.value = indexPaths
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
func updatePrice(symbol: NSDictionary) {
|
|
func updatePrice(symbol: NSDictionary) {
|
|
guard let symbol_str = symbol["symbol"] as? String else {
|
|
guard let symbol_str = symbol["symbol"] as? String else {
|
|
@@ -461,11 +512,31 @@ extension JDNewTradeAccountDetailViewModel {
|
|
positionModel.productBean.ask = model.ask
|
|
positionModel.productBean.ask = model.ask
|
|
positionModel.productBean.bid = model.bid
|
|
positionModel.productBean.bid = model.bid
|
|
|
|
|
|
- self.holdUpdatedIndexPath.value = IndexPath.init(row: row, section: 0)
|
|
|
|
|
|
+ let indices = self.positionList.enumerated().compactMap { (index, item) -> Int? in
|
|
|
|
+ if(item.symbol == symbol_str){
|
|
|
|
+ item.productBean.ask = model.ask
|
|
|
|
+ item.productBean.bid = model.bid
|
|
|
|
+ item.SymbolModel.ask = model.ask
|
|
|
|
+ item.SymbolModel.bid = model.bid
|
|
|
|
+ return index
|
|
|
|
+ }
|
|
|
|
+ return nil
|
|
|
|
+ }
|
|
|
|
+ // 将索引集合转换为 IndexPath 集合
|
|
|
|
+ let indexPaths = indices.map { IndexPath(row: $0, section: 0) }
|
|
|
|
+
|
|
|
|
+ self.holdUpdatedIndexPath.value = indexPaths
|
|
}
|
|
}
|
|
else if self.current_select_index == 1 {
|
|
else if self.current_select_index == 1 {
|
|
guard let row = self.entrustList.firstIndex(where: {$0.symbol == symbol_str}) else {return}
|
|
guard let row = self.entrustList.firstIndex(where: {$0.symbol == symbol_str}) else {return}
|
|
- self.hangUpdatedIndexPath.value = IndexPath.init(row: row, section: 0)
|
|
|
|
|
|
+
|
|
|
|
+ let indices = self.entrustList.enumerated().compactMap { (index, item) -> Int? in
|
|
|
|
+ return item.symbol == symbol_str ? index : nil
|
|
|
|
+ }
|
|
|
|
+ // 将索引集合转换为 IndexPath 集合
|
|
|
|
+ let indexPaths = indices.map { IndexPath(row: $0, section: 0) }
|
|
|
|
+
|
|
|
|
+ self.hangUpdatedIndexPath.value = indexPaths
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|