|
@@ -10,6 +10,11 @@ import UIKit
|
|
|
import ReactiveCocoa
|
|
|
import ReactiveSwift
|
|
|
class MarketViewModel: BaseViewModel {
|
|
|
+ lazy var netParamList:[String] = {
|
|
|
+ let arr:[String] = ["09988.SZ","00700.SZ","00388.SZ","002230.SZ","AAPL.US","TSLA.US","NVDA.US","600519.SH","300750.SZ","002594.SZ","300059.SZ"];
|
|
|
+ return arr
|
|
|
+ }()
|
|
|
+
|
|
|
lazy var productGroupList:[MarketProductGroupModel] = {//交易对
|
|
|
let arr:[MarketProductGroupModel] = [MarketProductGroupModel]()
|
|
|
return arr
|
|
@@ -20,17 +25,36 @@ class MarketViewModel: BaseViewModel {
|
|
|
return arr
|
|
|
}()
|
|
|
|
|
|
+ lazy var collectionSymbolList:[KSymbolModel] = {//收藏
|
|
|
+ let arr:[KSymbolModel] = [KSymbolModel]()
|
|
|
+ return arr
|
|
|
+ }()
|
|
|
|
|
|
lazy var symbolList:[KSymbolModel] = {//交易对
|
|
|
let arr:[KSymbolModel] = [KSymbolModel]()
|
|
|
return arr
|
|
|
}()
|
|
|
|
|
|
+ lazy var recommendList:[KSymbolModel] = {//交易对
|
|
|
+ let arr:[KSymbolModel] = [KSymbolModel]()
|
|
|
+ return arr
|
|
|
+ }()
|
|
|
+
|
|
|
lazy var screenSymbolList:[KSymbolModel] = {//交易对
|
|
|
let arr:[KSymbolModel] = [KSymbolModel]()
|
|
|
return arr
|
|
|
}()
|
|
|
|
|
|
+ lazy var optionList:[OptionsListModel] = {//期权
|
|
|
+ let arr:[OptionsListModel] = [OptionsListModel]()
|
|
|
+ return arr
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var screenOptionList:[OptionsListModel] = {//期权
|
|
|
+ let arr:[OptionsListModel] = [OptionsListModel]()
|
|
|
+ return arr
|
|
|
+ }()
|
|
|
+
|
|
|
var screenText:String = ""{
|
|
|
didSet{
|
|
|
self.screenSymbolListAction()
|
|
@@ -40,18 +64,49 @@ class MarketViewModel: BaseViewModel {
|
|
|
var marketText : String = ""{
|
|
|
|
|
|
didSet {
|
|
|
+ self.netSymbolList(isUp: false)
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ var optionMarket : String = ""{
|
|
|
+
|
|
|
+ didSet {
|
|
|
+ self.netOptionProductListGroup(isUp: false)
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ var topIndex = 1{
|
|
|
+ didSet{
|
|
|
|
|
|
-// netSymbolList
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var index:Int = 0{
|
|
|
+ didSet{
|
|
|
+ if index == -2 {
|
|
|
+ self.netUserList()
|
|
|
+ }
|
|
|
+ else if index >= 0{
|
|
|
+ self.marketText = getCode()
|
|
|
+ }else{
|
|
|
+ self.screenSymbolListAction()
|
|
|
+ }
|
|
|
|
|
|
- self.netSymbolList()
|
|
|
-// self.screenSymbolListAction()
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- var index:Int = 1{
|
|
|
+ var optionsIndex = 0{
|
|
|
didSet{
|
|
|
- self.screenSymbolListAction()
|
|
|
+ let model = self.getOptionsMarketList()[optionsIndex]
|
|
|
+ self.optionMarket = model.market
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var optionsTimerIndex = 0{
|
|
|
+ didSet{
|
|
|
+ self.screenOptionListAction()
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -67,18 +122,53 @@ class MarketViewModel: BaseViewModel {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ var optionsIncreaseSort:Int = 0{//0 后台 , 1 increase 升序,2 increase 降序
|
|
|
+ didSet{
|
|
|
+ self.screenOptionListAction()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var optionsMeanSort:Int = 0{//0 后台 , 1 Mean 升序,2 Mean 降序
|
|
|
+ didSet{
|
|
|
+ self.screenOptionListAction()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var optionsVirtualSort:Int = 0{//0 后台 , 1 Virtual 升序,2 Virtual 降序
|
|
|
+ didSet{
|
|
|
+ self.screenOptionListAction()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var pageNum:Int = 1
|
|
|
+
|
|
|
+ var optionPageNum:Int = 1
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
let (signalScreen, observeScreen) = Signal<Bool, Never>.pipe()
|
|
|
let (signalSymbol, observeSymbol) = Signal<Bool, Never>.pipe()
|
|
|
//netForInsertProductUser
|
|
|
- //netForDeleteProductUser
|
|
|
+ //netForGetOptionProductListGroup
|
|
|
+
|
|
|
+ var recommendSymbolListAction: Action <(),(Bool),Never>!
|
|
|
var groupListAction: Action <(),(Bool),Never>!
|
|
|
var userListAction: Action <(),(Bool),Never>!
|
|
|
- var symbolListAction: Action <(),(Bool),Never>!
|
|
|
+ var symbolListAction: Action <(Bool),(Bool),Never>!
|
|
|
var updateScribeAction: Action <(),(Bool),Never>!
|
|
|
var insertProductUserAction: Action <(String),(Bool),Never>!
|
|
|
var deleteProductUserAction: Action <(String),(Bool),Never>!
|
|
|
|
|
|
+ var optionProductListGroupAction: Action <(Bool),(Bool),Never>!
|
|
|
+
|
|
|
override func initialize() {
|
|
|
+ recommendSymbolListAction = Action<(),(Bool),Never> {[weak self] _ in
|
|
|
+ return SignalProducer<(Bool),Never>{ observer, _ in
|
|
|
+ self?.requestRecommendSymbolList(observer: observer)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
groupListAction = Action<(),(Bool),Never> {[weak self] _ in
|
|
|
return SignalProducer<(Bool),Never>{ observer, _ in
|
|
|
self?.requestGroupList(observer: observer)
|
|
@@ -91,9 +181,9 @@ class MarketViewModel: BaseViewModel {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- symbolListAction = Action<(),(Bool),Never> {[weak self] _ in
|
|
|
+ symbolListAction = Action<(Bool),(Bool),Never> {[weak self] isUp in
|
|
|
return SignalProducer<(Bool),Never>{ observer, _ in
|
|
|
- self?.requestSymbolList(observer: observer)
|
|
|
+ self?.requestSymbolList(observer: observer,isUp:isUp)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -114,6 +204,12 @@ class MarketViewModel: BaseViewModel {
|
|
|
self?.requestDeleteProductUser(observer: observer,symbol:symbol)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ optionProductListGroupAction = Action<(Bool),(Bool),Never> {[weak self] isUp in
|
|
|
+ return SignalProducer<(Bool),Never>{ observer, _ in
|
|
|
+ self?.requestOptionProductListGroup(observer: observer,isUp:isUp)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
override func webSocketdidReceive(nofi: NSNotification) {
|
|
@@ -123,6 +219,47 @@ class MarketViewModel: BaseViewModel {
|
|
|
|
|
|
extension MarketViewModel {
|
|
|
|
|
|
+ //获取推荐交易对
|
|
|
+ func netRecommendSymbolList() {
|
|
|
+ recommendSymbolListAction.apply().start()
|
|
|
+ }
|
|
|
+ //
|
|
|
+ func requestRecommendSymbolList(observer: Signal< Bool, Never>.Observer) -> Void {
|
|
|
+
|
|
|
+ let parame:[String:Any] = [
|
|
|
+ "symbol":getJSONStringFromArray(array: self.netParamList as NSArray)
|
|
|
+ ]
|
|
|
+ NetWork.NetWorkInstance.requestData(requestType: .Post, URLString: netForHomeSymbolList,parameters: parame, success: { (code, result) in
|
|
|
+ if let list:[NSDictionary] = result?["list"] as? [NSDictionary] {
|
|
|
+ self.recommendList.removeAll()
|
|
|
+ for dic in list {
|
|
|
+ let model = KSymbolModel.deserialize(from: dic)
|
|
|
+ model?.isSelect = true
|
|
|
+ if model!.visible == 1{
|
|
|
+ var ask = model!.ask
|
|
|
+ if conerData(ask, .MyDouble).2! == 0{
|
|
|
+ ask = model!.open
|
|
|
+ }
|
|
|
+ model?.newPrice = precisionString(with: ask, precision: model!.digits)
|
|
|
+ let np = decimalNumber(A: model!.newPrice, B: model!.open, type: .Subtract, scale:model!.digits)
|
|
|
+ let increase = (conerData(np, .MyDouble).2!/conerData(model!.open, .MyDouble).2!)*100
|
|
|
+ model?.increase = String(format: "%.2f",increase)
|
|
|
+ self.recommendList.append(model!)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ observer.send(value: true)
|
|
|
+ }else{
|
|
|
+ observer.send(value: false)
|
|
|
+ ProgressHUD.showError(status:DataTypeErrorPrompt)
|
|
|
+ }
|
|
|
+ observer.sendCompleted()
|
|
|
+ }) { (code, result) in
|
|
|
+ ProgressHUD.showError(status: result as! String)
|
|
|
+ observer.send(value: false)
|
|
|
+ observer.sendCompleted()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//获取产品分组列表
|
|
|
func netGroupList() {
|
|
|
groupListAction.apply().start()
|
|
@@ -155,26 +292,65 @@ extension MarketViewModel {
|
|
|
func netUserList() {
|
|
|
if OperationalUserInfoData.getLogin(){
|
|
|
userListAction.apply().start()
|
|
|
- }else{
|
|
|
- self.collectionList.removeAll()
|
|
|
- for model in self.symbolList {
|
|
|
- model.isCollection = false
|
|
|
- }
|
|
|
- self.screenSymbolListAction()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func requestUserList(observer: Signal< Bool, Never>.Observer) -> Void {
|
|
|
-
|
|
|
+ ProgressHUD.showLoading()
|
|
|
NetWork.NetWorkInstance.requestData(requestType: .Post, URLString: netForProductUserList, success: { (code, result) in
|
|
|
-
|
|
|
+ ProgressHUD.hideHud()
|
|
|
if let list:[NSDictionary] = result?["list"] as? [NSDictionary] {
|
|
|
self.collectionList.removeAll()
|
|
|
for dic in list {
|
|
|
self.collectionList.append((dic["symbol"] as? String) ?? "")
|
|
|
}
|
|
|
- self.updateSymbolListCollection()
|
|
|
- self.screenSymbolListAction()
|
|
|
+ if list.count > 0 {
|
|
|
+ self.requestCollectionSymbolList(observer: observer)
|
|
|
+ }else{
|
|
|
+ observer.send(value: true)
|
|
|
+ observer.sendCompleted()
|
|
|
+ }
|
|
|
+
|
|
|
+ }else{
|
|
|
+ observer.send(value: false)
|
|
|
+ observer.sendCompleted()
|
|
|
+ ProgressHUD.showError(status:DataTypeErrorPrompt)
|
|
|
+ }
|
|
|
+
|
|
|
+ }) { (code, result) in
|
|
|
+ ProgressHUD.showError(status: result as! String)
|
|
|
+ observer.send(value: false)
|
|
|
+ observer.sendCompleted()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func requestCollectionSymbolList(observer: Signal< Bool, Never>.Observer) -> Void {
|
|
|
+ var list:[String] = [String]()
|
|
|
+ for symbol in self.collectionList{
|
|
|
+ list.append(symbol)
|
|
|
+ }
|
|
|
+ let parame:[String:Any] = [
|
|
|
+ "symbol":getJSONStringFromArray(array: list as NSArray)
|
|
|
+ ]
|
|
|
+ NetWork.NetWorkInstance.requestData(requestType: .Post, URLString: netForHomeSymbolList,parameters: parame, success: {[weak self] (code, result) in
|
|
|
+ if let list:[NSDictionary] = result?["list"] as? [NSDictionary] {
|
|
|
+ self?.collectionSymbolList.removeAll()
|
|
|
+ for dic in list {
|
|
|
+ let model = KSymbolModel.deserialize(from: dic)
|
|
|
+ model?.isSelect = true
|
|
|
+ if model!.visible == 1{
|
|
|
+ var ask = model!.ask
|
|
|
+ if conerData(ask, .MyDouble).2! == 0{
|
|
|
+ ask = model!.open
|
|
|
+ }
|
|
|
+ model?.newPrice = precisionString(with: ask, precision: model!.digits)
|
|
|
+ let np = decimalNumber(A: model!.newPrice, B: model!.open, type: .Subtract, scale:model!.digits)
|
|
|
+ let increase = (conerData(np, .MyDouble).2!/conerData(model!.open, .MyDouble).2!)*100
|
|
|
+ model?.increase = String(format: "%.2f",increase)
|
|
|
+ self?.collectionSymbolList.append(model!)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ self?.screenSymbolListAction()
|
|
|
observer.send(value: true)
|
|
|
}else{
|
|
|
observer.send(value: false)
|
|
@@ -188,71 +364,63 @@ extension MarketViewModel {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
//获取交易对
|
|
|
- func netSymbolList() {
|
|
|
- symbolListAction.apply().start()
|
|
|
+ func netSymbolList(isUp:Bool) {
|
|
|
+ symbolListAction.apply(isUp).start()
|
|
|
}
|
|
|
//
|
|
|
- func requestSymbolList(observer: Signal< Bool, Never>.Observer) -> Void {
|
|
|
- //读取缓存
|
|
|
- // if getSymbolList().count > 0 {
|
|
|
-// self.symbolList = getSymbolList()
|
|
|
-// self.screenSymbolListAction()
|
|
|
-// self.updateSymbolListCollection()
|
|
|
-// observer.send(value: true)
|
|
|
-// observer.sendCompleted()
|
|
|
-// return
|
|
|
-// }
|
|
|
- ProgressHUD.showMessage(status:"")
|
|
|
-
|
|
|
+ func requestSymbolList(observer: Signal< Bool, Never>.Observer,isUp:Bool) -> Void {
|
|
|
+ if !isUp{
|
|
|
+ self.pageNum = 1
|
|
|
+ }
|
|
|
let param : [String : Any] = [
|
|
|
|
|
|
- "pageNum" : "1",
|
|
|
+ "pageNum" : self.pageNum,
|
|
|
"pageSize" : "30",
|
|
|
"market" : self.marketText
|
|
|
]
|
|
|
-
|
|
|
- NetWork.NetWorkInstance.requestData(requestType: .Post, URLString: netForHomeSymbolList, parameters: param, success: { (code, result) in
|
|
|
+ ProgressHUD.showLoading()
|
|
|
+ NetWork.NetWorkInstance.requestData(requestType: .Post, URLString: netForHomeSymbolList, parameters: param, success: {[weak self](code, result) in
|
|
|
|
|
|
ProgressHUD.hideHud()
|
|
|
if let list:[NSDictionary] = result?["list"] as? [NSDictionary] {
|
|
|
- self.symbolList.removeAll()
|
|
|
- SaveData.shared().updateSymbolList(list: list as NSArray)
|
|
|
- self.symbolList = getSymbolList()
|
|
|
- self.screenSymbolListAction()
|
|
|
- self.updateSymbolListCollection()
|
|
|
- self.netUpdateSubscribes()
|
|
|
- observer.send(value: true)
|
|
|
- }else{
|
|
|
- observer.send(value: false)
|
|
|
- ProgressHUD.showError(status:DataTypeErrorPrompt)
|
|
|
+ if !isUp {
|
|
|
+ self?.symbolList.removeAll()
|
|
|
}
|
|
|
- observer.sendCompleted()
|
|
|
- }) { (code, result) in
|
|
|
- ProgressHUD.showError(status: result as! String)
|
|
|
+ self?.pageNum += 1
|
|
|
+ for dic in list {
|
|
|
+ let model = KSymbolModel.deserialize(from: dic)!
|
|
|
+ if model.visible == 1{
|
|
|
+ var ask = model.ask
|
|
|
+ if conerData(ask, .MyDouble).2! == 0{
|
|
|
+ ask = model.open
|
|
|
+ }
|
|
|
+ model.newPrice = precisionString(with: ask, precision: model.digits)
|
|
|
+ let np = decimalNumber(A: model.newPrice, B: model.open, type: .Subtract, scale:model.digits)
|
|
|
+ let increase = (conerData(np, .MyDouble).2!/conerData(model.open, .MyDouble).2!)*100
|
|
|
+ model.increase = String(format: "%.2f",increase)
|
|
|
+ self?.symbolList.append(model)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ self?.screenSymbolListAction()
|
|
|
+ self?.updateSymbolListCollection()
|
|
|
+ self?.netUpdateSubscribes()
|
|
|
+
|
|
|
+ let isNoData:Bool = (list.count < 30) ? true : false
|
|
|
+ observer.send(value:isNoData)
|
|
|
+
|
|
|
+ }else{
|
|
|
observer.send(value: false)
|
|
|
- observer.sendCompleted()
|
|
|
+ ProgressHUD.showError(status:DataTypeErrorPrompt)
|
|
|
}
|
|
|
+ observer.sendCompleted()
|
|
|
+ }) { (code, result) in
|
|
|
+ ProgressHUD.showError(status: result as! String)
|
|
|
+ observer.send(value: false)
|
|
|
+ observer.sendCompleted()
|
|
|
+ }
|
|
|
|
|
|
-// NetWork.NetWorkInstance.requestData(requestType: .Post, URLString: netForHomeSymbolList, success: { (code, result) in
|
|
|
-// ProgressHUD.hideHud()
|
|
|
-// if let list:[NSDictionary] = result?["list"] as? [NSDictionary] {
|
|
|
-// self.symbolList.removeAll()
|
|
|
-// SaveData.shared().updateSymbolList(list: list as NSArray)
|
|
|
-// self.symbolList = getSymbolList()
|
|
|
-// self.screenSymbolListAction()
|
|
|
-// self.updateSymbolListCollection()
|
|
|
-// observer.send(value: true)
|
|
|
-// }else{
|
|
|
-// observer.send(value: false)
|
|
|
-// ProgressHUD.showError(status:DataTypeErrorPrompt)
|
|
|
-// }
|
|
|
-// observer.sendCompleted()
|
|
|
-// }) { (code, result) in
|
|
|
-// ProgressHUD.showError(status: result as! String)
|
|
|
-// observer.send(value: false)
|
|
|
-// observer.sendCompleted()
|
|
|
-// }
|
|
|
}
|
|
|
|
|
|
//添加收藏
|
|
@@ -266,7 +434,7 @@ extension MarketViewModel {
|
|
|
}
|
|
|
|
|
|
func requestInsertProductUser(observer: Signal< Bool, Never>.Observer,symbol:String) -> Void {
|
|
|
-
|
|
|
+ ProgressHUD.showLoading()
|
|
|
let parame:[String:Any] = ["symbol":symbol]
|
|
|
NetWork.NetWorkInstance.requestData(requestType: .Post, URLString: netForInsertProductUser ,parameters: parame, success: { (code, result) in
|
|
|
ProgressHUD.showSuccess(status: switchLanguage("收藏成功"))
|
|
@@ -326,11 +494,17 @@ extension MarketViewModel {
|
|
|
func requestUpdateSubscribeAction(observer: Signal< Bool, Never>.Observer) -> Void {
|
|
|
|
|
|
var symbols : [String] = []
|
|
|
-
|
|
|
- for model in self.screenSymbolList{
|
|
|
- symbols.append(model.symbol)
|
|
|
+ if self.topIndex == 2 {
|
|
|
+ for model in self.screenOptionList{
|
|
|
+ symbols.append(model.code)
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ for model in self.screenSymbolList{
|
|
|
+ symbols.append(model.symbol)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
let param = [
|
|
|
|
|
|
"symbols": symbols
|
|
@@ -338,14 +512,12 @@ extension MarketViewModel {
|
|
|
|
|
|
print("symbols : \(param)")
|
|
|
NetWork.NetWorkInstance.requestData(requestType: .Post, URLString: netUpdateSubscribe, parameters: param) { (code, result) in
|
|
|
- print(code,result ?? "")
|
|
|
-
|
|
|
+
|
|
|
observer.send(value: true)
|
|
|
observer.sendCompleted()
|
|
|
|
|
|
} failured: { (code, result) in
|
|
|
- print(code,result ?? "")
|
|
|
-
|
|
|
+
|
|
|
ProgressHUD.showError(status: result as! String)
|
|
|
observer.send(value: false)
|
|
|
observer.sendCompleted()
|
|
@@ -354,6 +526,105 @@ extension MarketViewModel {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ //获取期权列表
|
|
|
+ func netOptionProductListGroup(isUp:Bool) {
|
|
|
+ optionProductListGroupAction.apply(isUp).start()
|
|
|
+ }
|
|
|
+ //
|
|
|
+ func requestOptionProductListGroup(observer: Signal< Bool, Never>.Observer,isUp:Bool) -> Void {
|
|
|
+ if !isUp{
|
|
|
+ self.optionPageNum = 1
|
|
|
+ }
|
|
|
+ let param : [String : Any] = [
|
|
|
+ "pageNum" : self.optionPageNum,
|
|
|
+ "pageSize" : "30",
|
|
|
+ "market" : self.optionMarket
|
|
|
+ ]
|
|
|
+ ProgressHUD.showLoading()
|
|
|
+ NetWork.NetWorkInstance.requestData(requestType: .Post, URLString: netForGetOptionProductListGroup, parameters: param, success: {[weak self](code, result) in
|
|
|
+
|
|
|
+ ProgressHUD.hideHud()
|
|
|
+ if let list:[NSDictionary] = result?["list"] as? [NSDictionary] {
|
|
|
+ if !isUp {
|
|
|
+ self?.optionList.removeAll()
|
|
|
+ }
|
|
|
+ self?.optionPageNum += 1
|
|
|
+ for dic in list {
|
|
|
+ let model = OptionsListModel.deserialize(from: dic)!
|
|
|
+ self?.optionList.append(model)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if self!.optionList.count > 0 {
|
|
|
+ let isNoData:Bool = (list.count < 30) ? true : false
|
|
|
+ self?.requestOptionProductListGroupSymbol(observer: observer,isNoData: isNoData)
|
|
|
+ }else{
|
|
|
+ observer.send(value:true)
|
|
|
+ observer.sendCompleted()
|
|
|
+ }
|
|
|
+
|
|
|
+ }else{
|
|
|
+ observer.send(value: false)
|
|
|
+ observer.sendCompleted()
|
|
|
+ ProgressHUD.showError(status:DataTypeErrorPrompt)
|
|
|
+ }
|
|
|
+
|
|
|
+ }) { (code, result) in
|
|
|
+ ProgressHUD.showError(status: result as! String)
|
|
|
+ observer.send(value: false)
|
|
|
+ observer.sendCompleted()
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ func requestOptionProductListGroupSymbol(observer: Signal< Bool, Never>.Observer,isNoData:Bool) -> Void {
|
|
|
+ var list:[String] = [String]()
|
|
|
+ for model in self.optionList{
|
|
|
+ list.append(model.code)
|
|
|
+ }
|
|
|
+ let param:[String:Any] = [
|
|
|
+ "symbol":getJSONStringFromArray(array: list as NSArray)
|
|
|
+ ]
|
|
|
+ ProgressHUD.showLoading()
|
|
|
+ NetWork.NetWorkInstance.requestData(requestType: .Post, URLString: netForHomeSymbolList,parameters: param, success: {[weak self] (code, result) in
|
|
|
+ ProgressHUD.hideHud()
|
|
|
+ if let list:[NSDictionary] = result?["list"] as? [NSDictionary] {
|
|
|
+ for dic in list {
|
|
|
+ let model = KSymbolModel.deserialize(from: dic)
|
|
|
+ var ask = model!.ask
|
|
|
+ if conerData(ask, .MyDouble).2! == 0{
|
|
|
+ ask = model!.open
|
|
|
+ }
|
|
|
+ model?.newPrice = precisionString(with: ask, precision: model!.digits)
|
|
|
+ let np = decimalNumber(A: model!.newPrice, B: model!.open, type: .Subtract, scale:model!.digits)
|
|
|
+ let increase = (conerData(np, .MyDouble).2!/conerData(model!.open, .MyDouble).2!)*100
|
|
|
+ model?.increase = String(format: "%.2f",increase)
|
|
|
+
|
|
|
+ for oModel in self!.optionList{
|
|
|
+ if oModel.code == model!.symbol{
|
|
|
+ oModel.symbolData = model!
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ self?.screenOptionListAction()
|
|
|
+ self?.netUpdateSubscribes()
|
|
|
+ observer.send(value: isNoData)
|
|
|
+ }else{
|
|
|
+ observer.send(value: false)
|
|
|
+ ProgressHUD.showError(status:DataTypeErrorPrompt)
|
|
|
+ }
|
|
|
+ observer.sendCompleted()
|
|
|
+ }) { (code, result) in
|
|
|
+ ProgressHUD.showError(status: result as! String)
|
|
|
+ observer.send(value: false)
|
|
|
+ observer.sendCompleted()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
extension MarketViewModel {
|
|
@@ -370,87 +641,33 @@ extension MarketViewModel {
|
|
|
}
|
|
|
|
|
|
func resetProductGroup() -> Void {
|
|
|
- let collectModel = MarketProductGroupModel()
|
|
|
- collectModel.id = "-2"
|
|
|
- collectModel.title = switchLanguage("自选")
|
|
|
- collectModel.code = "ZX"
|
|
|
- self.productGroupList.insert(collectModel, at: 0)
|
|
|
-
|
|
|
-// let hotModel = MarketProductGroupModel()
|
|
|
-// hotModel.id = "-1"
|
|
|
-// hotModel.title = switchLanguage("热门")
|
|
|
-// self.productGroupList.insert(hotModel, at: 1)
|
|
|
-//
|
|
|
+
|
|
|
let allModel = MarketProductGroupModel()
|
|
|
allModel.id = "0"
|
|
|
allModel.title = switchLanguage("全部")
|
|
|
- allModel.code = "ALL"
|
|
|
-// self.productGroupList.append(allModel)
|
|
|
- self.productGroupList.insert(allModel, at: 1)
|
|
|
+ allModel.code = ""
|
|
|
+ self.productGroupList.insert(allModel, at: 0)
|
|
|
self.screenSymbolListAction()
|
|
|
}
|
|
|
|
|
|
func screenSymbolListAction() -> Void {
|
|
|
self.screenSymbolList.removeAll()
|
|
|
- var groupList:[KSymbolModel] = [KSymbolModel]()
|
|
|
- let group = self.getGroup()
|
|
|
- let code = self.getCode()
|
|
|
- if group == "-2" {
|
|
|
- for model in self.symbolList {
|
|
|
- for symbol in self.collectionList{
|
|
|
- if model.symbol == symbol{
|
|
|
- groupList.append(model)
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- else if group == "-1"{
|
|
|
- for model in self.symbolList {
|
|
|
- if model.hot == 1 {
|
|
|
- groupList.append(model)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else if group == "0"{
|
|
|
- groupList = self.symbolList
|
|
|
- }else{
|
|
|
- for model in self.symbolList {
|
|
|
-// if group == model.groupid{
|
|
|
-// groupList.append(model)
|
|
|
-// }
|
|
|
-
|
|
|
- if code == model.market {
|
|
|
- groupList.append(model)
|
|
|
- }
|
|
|
-//
|
|
|
- }
|
|
|
-
|
|
|
- self.marketText = code
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+ if (index == -2){
|
|
|
+ self.screenSymbolList = self.collectionSymbolList
|
|
|
}
|
|
|
-
|
|
|
- var textList:[KSymbolModel] = [KSymbolModel]()
|
|
|
- if screenText.length == 0 {
|
|
|
- textList = groupList
|
|
|
- }else{
|
|
|
- for model in groupList{
|
|
|
- if model.title.uppercased().contains(screenText.uppercased()){
|
|
|
- textList.append(model)
|
|
|
- }
|
|
|
- }
|
|
|
+ else if (index >= 0){
|
|
|
+ self.screenSymbolList = self.symbolList
|
|
|
}
|
|
|
|
|
|
if symbolSort > 0 {
|
|
|
if symbolSort == 1 {
|
|
|
- textList.sort(by: {
|
|
|
+ self.screenSymbolList.sort(by: {
|
|
|
return $0.symbol > $1.symbol
|
|
|
})
|
|
|
}
|
|
|
else if symbolSort == 2{
|
|
|
- textList.sort(by: {
|
|
|
+ self.screenSymbolList.sort(by: {
|
|
|
return $0.symbol < $1.symbol
|
|
|
})
|
|
|
}
|
|
@@ -460,25 +677,48 @@ extension MarketViewModel {
|
|
|
|
|
|
if increaseSort > 0 {
|
|
|
if increaseSort == 1{
|
|
|
- textList.sort { (model1, model2) -> Bool in
|
|
|
+ self.screenSymbolList.sort { (model1, model2) -> Bool in
|
|
|
return conerData(model1.increase as Any, .MyDouble).2! > conerData(model2.increase as Any, .MyDouble).2!
|
|
|
}
|
|
|
}
|
|
|
else if increaseSort == 2 {
|
|
|
- textList.sort { (model1, model2) -> Bool in
|
|
|
+ self.screenSymbolList.sort { (model1, model2) -> Bool in
|
|
|
return conerData(model1.increase as Any, .MyDouble).2! < conerData(model2.increase as Any, .MyDouble).2!
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ self.observeScreen.send(value: true)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ func screenOptionListAction() -> Void {
|
|
|
+ self.screenOptionList.removeAll()
|
|
|
+
|
|
|
+ for model in self.optionList{
|
|
|
+ self.screenOptionList.append(model)
|
|
|
+ }
|
|
|
|
|
|
- self.screenSymbolList = textList
|
|
|
-
|
|
|
-
|
|
|
+ if optionsIncreaseSort > 0 {
|
|
|
+ if optionsIncreaseSort == 1{
|
|
|
+ self.screenOptionList.sort { (model1, model2) -> Bool in
|
|
|
+ return conerData(model1.symbolData.increase as Any, .MyDouble).2! > conerData(model2.symbolData.increase as Any, .MyDouble).2!
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if optionsIncreaseSort == 2 {
|
|
|
+ self.screenOptionList.sort { (model1, model2) -> Bool in
|
|
|
+ return conerData(model1.symbolData.increase as Any, .MyDouble).2! < conerData(model2.symbolData.increase as Any, .MyDouble).2!
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+
|
|
|
self.observeScreen.send(value: true)
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
func getGroup() -> String {
|
|
|
guard self.productGroupList.count > self.index else {
|
|
|
return "0"
|
|
@@ -492,14 +732,94 @@ extension MarketViewModel {
|
|
|
|
|
|
guard self.productGroupList.count > self.index else {
|
|
|
|
|
|
- return "ZX"
|
|
|
+ return ""
|
|
|
|
|
|
}
|
|
|
|
|
|
let model = self.productGroupList[self.index]
|
|
|
return model.code
|
|
|
|
|
|
+ }
|
|
|
+
|
|
|
+ func getOptionsMarketTitleList() -> [String] {
|
|
|
+ var list:[String] = [String]()
|
|
|
+ for model in self.getOptionsMarketList(){
|
|
|
+ list.append(model.title)
|
|
|
+ }
|
|
|
+ return list
|
|
|
+ }
|
|
|
+
|
|
|
+ func getOptionsMarketList() -> [OptionsMarketModel] {
|
|
|
+ let list = [
|
|
|
+ [
|
|
|
+ "market":"CN",
|
|
|
+ "title":switchLanguage("沪深"),
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ "market":"US",
|
|
|
+ "title":switchLanguage("美股"),
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ "market":"HK",
|
|
|
+ "title":switchLanguage("港股"),
|
|
|
+ ],
|
|
|
+ ]
|
|
|
|
|
|
+ var arr:[OptionsMarketModel] = [OptionsMarketModel]()
|
|
|
+ for dict in list {
|
|
|
+ let model = OptionsMarketModel.deserialize(from: dict)!
|
|
|
+ arr.append(model)
|
|
|
+ }
|
|
|
+
|
|
|
+ return arr
|
|
|
+ }
|
|
|
+
|
|
|
+ func getOptionsTimer() -> String {
|
|
|
+ let model = getOptionsTimerList()[self.optionsTimerIndex]
|
|
|
+ return model.timer
|
|
|
+ }
|
|
|
+
|
|
|
+ func getOptionsTimerList() -> [OptionsTimerModel] {
|
|
|
+ let list = [
|
|
|
+ [
|
|
|
+ "timer":"price_1m_list",
|
|
|
+ "title":"1M",
|
|
|
+ "isSelect":true
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ "timer":"price_2m_list",
|
|
|
+ "title":"2M",
|
|
|
+ "isSelect":false
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ "timer":"price_3m_list",
|
|
|
+ "title":"3M",
|
|
|
+ "isSelect":false
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ "timer":"price_4m_list",
|
|
|
+ "title":"4M",
|
|
|
+ "isSelect":false
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ "timer":"price_5m_list",
|
|
|
+ "title":"5M",
|
|
|
+ "isSelect":false
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ "timer":"price_6m_list",
|
|
|
+ "title":"6M",
|
|
|
+ "isSelect":false
|
|
|
+ ],
|
|
|
+ ]
|
|
|
+
|
|
|
+ var arr:[OptionsTimerModel] = [OptionsTimerModel]()
|
|
|
+ for dict in list {
|
|
|
+ let model = OptionsTimerModel.deserialize(from: dict)!
|
|
|
+ arr.append(model)
|
|
|
+ }
|
|
|
+
|
|
|
+ return arr
|
|
|
}
|
|
|
|
|
|
|
|
@@ -515,26 +835,82 @@ extension MarketViewModel{
|
|
|
if type == 0 {
|
|
|
if let currentSocket = dict.object(forKey: "currentSocket") as? NSDictionary {
|
|
|
var isReload = false
|
|
|
- for model in symbolList{
|
|
|
- guard let symbol = currentSocket["symbol"] as? String else{
|
|
|
- return
|
|
|
+
|
|
|
+ guard let symbol = currentSocket["symbol"] as? String else{
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if self.topIndex == 0 {
|
|
|
+ for model in collectionSymbolList{
|
|
|
+
|
|
|
+ if model.symbol == symbol {
|
|
|
+ model.newPrice = String(format:"%@",currentSocket["ask"] as! CVarArg)
|
|
|
+ let np = conerData(model.newPrice, .MyDouble).1! - conerData(model.open, .MyDouble).1!
|
|
|
+ let increase = (conerData("\(np)", .MyDouble).2!/conerData(model.open, .MyDouble).2!)*100
|
|
|
+ model.increase = String(format: "%.2f",increase)
|
|
|
+ for m in self.screenSymbolList{
|
|
|
+ if m.symbol == symbol{
|
|
|
+ m.newPrice = model.newPrice
|
|
|
+ m.increase = model.increase
|
|
|
+ isReload = true
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break
|
|
|
+ }
|
|
|
}
|
|
|
- if model.symbol == symbol {
|
|
|
- model.newPrice = String(format:"%@",currentSocket["ask"] as! CVarArg)
|
|
|
- let np = decimalNumber(A: model.newPrice, B: model.open, type: .Subtract, scale:model.digits)
|
|
|
- model.increase = decimalNumber(A: np, B: model.open, type: .Divid)
|
|
|
- model.increase = decimalNumber(A: model.increase, B: "100", type: .Multiply)
|
|
|
- for m in self.screenSymbolList{
|
|
|
- if m.symbol == symbol{
|
|
|
- m.newPrice = model.newPrice
|
|
|
- m.increase = model.increase
|
|
|
- isReload = true
|
|
|
- break
|
|
|
+
|
|
|
+ for model in recommendList{
|
|
|
+
|
|
|
+ if model.symbol == symbol {
|
|
|
+ model.newPrice = String(format:"%@",currentSocket["ask"] as! CVarArg)
|
|
|
+ let np = conerData(model.newPrice, .MyDouble).1! - conerData(model.open, .MyDouble).1!
|
|
|
+ let increase = (conerData("\(np)", .MyDouble).2!/conerData(model.open, .MyDouble).2!)*100
|
|
|
+ model.increase = String(format: "%.2f",increase)
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if self.topIndex == 1{
|
|
|
+ for model in symbolList{
|
|
|
+ if model.symbol == symbol {
|
|
|
+ model.newPrice = String(format:"%@",currentSocket["ask"] as! CVarArg)
|
|
|
+ let np = conerData(model.newPrice, .MyDouble).1! - conerData(model.open, .MyDouble).1!
|
|
|
+ let increase = (conerData("\(np)", .MyDouble).2!/conerData(model.open, .MyDouble).2!)*100
|
|
|
+ model.increase = String(format: "%.2f",increase)
|
|
|
+ for m in self.screenSymbolList{
|
|
|
+ if m.symbol == symbol{
|
|
|
+ m.newPrice = model.newPrice
|
|
|
+ m.increase = model.increase
|
|
|
+ isReload = true
|
|
|
+ break
|
|
|
+ }
|
|
|
}
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ else{
|
|
|
+ for model in optionList{
|
|
|
+ if model.symbolData.symbol == symbol {
|
|
|
+ model.symbolData.newPrice = String(format:"%@",currentSocket["ask"] as! CVarArg)
|
|
|
+ let np = conerData(model.symbolData.newPrice, .MyDouble).1! - conerData(model.symbolData.open, .MyDouble).1!
|
|
|
+ let increase = (conerData("\(np)", .MyDouble).2!/conerData(model.symbolData.open, .MyDouble).2!)*100
|
|
|
+ model.symbolData.increase = String(format: "%.2f",increase)
|
|
|
+ for m in self.screenOptionList{
|
|
|
+ if m.symbolData.symbol == symbol{
|
|
|
+ m.symbolData.newPrice = model.symbolData.newPrice
|
|
|
+ m.symbolData.increase = model.symbolData.increase
|
|
|
+ isReload = true
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break
|
|
|
}
|
|
|
- break
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
if isReload {
|
|
|
self.observeSymbol.send(value: true)
|
|
|
}
|