Переглянути джерело

修复交易画面持仓列表现价

lintong 1 тиждень тому
батько
коміт
8e9e34f6e0

+ 12 - 4
Koala/Koala/Modular/Deal/V/Deal/DealListCell.swift

@@ -358,15 +358,23 @@ class DealListCell: BaseTableViewCell {
         self.shoushuLabel.attributedText = self.setAttributesForLots(title: switchLanguage("手数"), text: precisionString(with: model.volume, precision: "2"))
         
         var price = model.close_price
-        let prd = BaseProductList.shareInstance.productList[model.productBean.symbol]
-        if prd != nil && model.productBean.inTrading() {
-            let bid = prd!.bid
-            let ask = prd!.ask
+        if let prd = self.productList?[model.productBean.symbol] {
+            let bid = prd.bid
+            let ask = prd.ask
             price = bid
             if model.cmd == 1 || model.cmd == 3 || model.cmd == 5 {
                 price = ask
             }
         }
+//        let prd = self.productList![model.productBean.symbol]
+//        if prd != nil && model.productBean.inTrading() {
+//            let bid = prd!.bid
+//            let ask = prd!.ask
+//            price = bid
+//            if model.cmd == 1 || model.cmd == 3 || model.cmd == 5 {
+//                price = ask
+//            }
+//        }
         
         var xianjiaColor = color(242, 64, 64, 1)
         if Double(price ?? "0") ?? 0 < Double(model.open_price ?? "0") ?? 0 {

+ 2 - 1
Koala/Koala/Modular/Deal/V/Deal/DealView.swift

@@ -973,8 +973,9 @@ class DealView: BaseView {
         
         self.VM?.getDealProductActionBlock = { [weak self] in
             guard let self = self else { return }
+            self.tabHeaderView.VM = self.VM
             self.tableView.reloadData()
-            self.tabHeaderView.liteInfoView.submitView.bidNotSupport = self.VM?.selectSymbolModel.enable == "0"
+            
         }
         
         var issignalSymbol = true

+ 37 - 48
Koala/Koala/Modular/Deal/VM/DealViewModel.swift

@@ -1442,48 +1442,14 @@ extension DealViewModel {
                     }
                     PriceCalibrator.shareCalibrator.updateLastPriceTime()
                     print("symbol的值:\(symbol)")
-                    var isReload = false
-                    if self.selectIndex == 0 {
-                        if let positionModel = self.positionListDict[symbol] {
-                            positionModel.isUpdate = true
-                            positionModel.SymbolModel.ask = String(format: "%@", currentSocket["ask"] as! CVarArg)
-                            positionModel.SymbolModel.bid = String(format: "%@", currentSocket["bid"] as! CVarArg)
-                            
-//                            let ask = Double(positionModel.SymbolModel.ask) ?? 0.0
-//                            let bid = Double(positionModel.SymbolModel.bid) ?? 0.0
-//                            positionModel.close_price = positionModel.SymbolModel.close
-                            let promd = BaseProductList.shareInstance.productList[symbol]
-                            
-                            let promdc = self.productList[symbol]
-                            promd?.ask = String(format: "%@", currentSocket["ask"] as! CVarArg)
-                            promd?.bid = String(format: "%@", currentSocket["bid"] as! CVarArg)
-                            promdc?.ask = String(format: "%@", currentSocket["ask"] as! CVarArg)
-                            promdc?.bid = String(format: "%@", currentSocket["bid"] as! CVarArg)
-                            isReload = true
-                        }
-                    } else if self.selectIndex == 1 {
-                        if let positionModel = self.entrustListDict[symbol] {
-                            positionModel.SymbolModel.ask = String(format: "%@", currentSocket["ask"] as! CVarArg)
-                            positionModel.SymbolModel.bid = String(format: "%@", currentSocket["bid"] as! CVarArg)
-                            let promd = BaseProductList.shareInstance.productList[symbol]
-                            
-                            let promdc = self.productList[symbol]
-                            promd?.ask = String(format: "%@", currentSocket["ask"] as! CVarArg)
-                            promd?.bid = String(format: "%@", currentSocket["bid"] as! CVarArg)
-                            promdc?.ask = String(format: "%@", currentSocket["ask"] as! CVarArg)
-                            promdc?.bid = String(format: "%@", currentSocket["bid"] as! CVarArg)
-                            isReload = true
-                        }
-                    }
                     
                     let model = self.selectSymbolModel
                     if model.symbol == symbol {
-                        isReload = false
                         model.newPrice = "\(currentSocket["ask"] ?? "0")"
                         let np = conerData(model.newPrice, .MyDouble).2! - conerData(model.open, .MyDouble).2!
                         model.increase = "\(np / conerData(model.open, .MyDouble).2! * 100)"
-                        model.ask = "\(currentSocket["bid"] ?? "0")"
-                        model.bid = "\(currentSocket["ask"] ?? "0")"
+                        model.bid = "\(currentSocket["bid"] ?? "0")"
+                        model.ask = "\(currentSocket["ask"] ?? "0")"
                         
                         let curPrice = ((Double(model.ask) ?? 0) + (Double(model.bid) ?? 0)) / 2
                         self.price = "\(curPrice)"
@@ -1503,7 +1469,6 @@ extension DealViewModel {
                     
                         var period = KLinePeriod.minuteFor(kPeriod: KLinePeriod.getDefaultKLinePeriod())
                         period = period * 60
-                        isReload = true
                         if let firstModel = self.priceList.first {
                             let firstTime = conerData(firstModel.datetime as Any, .MyCLong).3! + period
                             
@@ -1535,18 +1500,9 @@ extension DealViewModel {
                             model.low = newPrice
                             self.priceList.insert(model, at: 0)
                         }
-                        if isReload {
-                            self.signalPriceBlock?()
-                            //                        self.observePrice.send(value: true)
-                            //                        if(self.refreshBlock != nil){
-                            //                            self.refreshBlock!()
-                            //                        }
-                        }
+                        self.signalPriceBlock?()
                     } else {
-                        if isReload {
-                            self.signalPositionBlock?()
-                            //                        self.observePosition.send(value: true)
-                        }
+                        self.signalPositionBlock?()
                     }
                 } else if currentType == "depth" {
                     guard let symbol = currentSocket["symbol"] as? String else {
@@ -1561,6 +1517,39 @@ extension DealViewModel {
                             self.getPriceDepthActionBlock?()
                         }
                     }
+                    
+                    if let marketDepthModel = MarketDepthModel.deserialize(from: currentSocket) {
+                        if self.selectIndex == 0 {
+                            if let positionModel = self.positionListDict[symbol] {
+                                positionModel.isUpdate = true
+                                positionModel.SymbolModel.ask = marketDepthModel.asks[0].price
+                                positionModel.SymbolModel.bid = marketDepthModel.bids[0].price
+                                
+                                let promd = BaseProductList.shareInstance.productList[symbol]
+                                let promdc = self.productList[symbol]
+                                
+                                promd?.ask = marketDepthModel.asks[0].price
+                                promd?.bid = marketDepthModel.bids[0].price
+                                promdc?.ask = marketDepthModel.asks[0].price
+                                promdc?.bid = marketDepthModel.bids[0].price
+                            }
+                        } else if self.selectIndex == 1 {
+                            if let positionModel = self.entrustListDict[symbol] {
+                                positionModel.SymbolModel.ask = marketDepthModel.asks[0].price
+                                positionModel.SymbolModel.bid = marketDepthModel.bids[0].price
+                                let promd = BaseProductList.shareInstance.productList[symbol]
+                                
+                                let promdc = self.productList[symbol]
+                                promd?.ask = marketDepthModel.asks[0].price
+                                promd?.bid = marketDepthModel.bids[0].price
+                                promdc?.ask = marketDepthModel.asks[0].price
+                                promdc?.bid = marketDepthModel.bids[0].price
+                            }
+                        }
+                        
+                        self.signalPositionBlock?()
+                    }
+                    
                 }
             } else if type == 1 {
                 guard let currentSocket = dict.object(forKey: "currentSocket") as? NSDictionary else { return }