package socket import ( "context" "encoding/json" "matchmaking-system/internal/data" "matchmaking-system/internal/data/memory" "matchmaking-system/internal/data/socket/optionData" "matchmaking-system/internal/data/tradedeal/option" "matchmaking-system/internal/pkg/flags" "matchmaking-system/internal/pkg/logging/applogger" "matchmaking-system/internal/pkg/setting" "time" ) // orderSubAdminOptionInrSubscribeByOrder // // @Description: 管理员期权-印度股|持仓订单订阅|持仓浮动盈亏订阅 // @receiver u // @param psgMsg func (u *Client) orderSubAdminOptionInrSubscribeByOrder(psgMsg *SymbolMessage) { for { if psgMsg.Symbol == setting.SubscribeAdminOptionInr { var hashList []option.OptionInrTallyCache for _, field := range psgMsg.Order { fieldStr, err := data.Reds.HGet(context.Background(), setting.AdminOptionInrSubscribe, field).Result() if err != nil { continue } var msg option.OptionInrTallyCache if err = json.Unmarshal([]byte(fieldStr), &msg); err != nil { time.Sleep(5 * time.Second) continue } hashList = append(hashList, msg) } for _, value := range hashList { orderModel := optionData.OptionInrOrderProcessing(1, value) if orderModel != nil { _, ok := u.symbol.Load(psgMsg.Symbol) if ok { // 清理[撤单|平仓]缓存队列 if orderModel.Status == flags.Cancel || orderModel.Status == flags.Close { if err := data.Reds.HDel(context.Background(), setting.AdminOptionInrSubscribe, orderModel.OrderId).Err(); err != nil { applogger.Error("AdminOptionInrSubscribe.HDel:%v", err) continue } } orderStr, err := json.Marshal(orderModel) if err != nil { applogger.Error("Administrator India stock subscription cache order error:%v", err) time.Sleep(5 * time.Second) continue } u.msg <- orderStr // 用户(挂单|持仓)订阅 } else { applogger.Info("Administrator cancels India order subscription.") return } } } } time.Sleep(600 * time.Millisecond) } } func (u *Client) orderSubAdminOptionInrSubscribeBySum(psgMsg *SymbolMessage) { for { if psgMsg.Symbol == setting.AdminOptionInrSumSubscribe { priceSum, err := memory.OptionInrFloating.Get(flags.FloatingOpi) if err != nil { continue } result := &SymbolSumResult{ Symbol: psgMsg.Symbol, Price: string(priceSum), } priceByte, err := json.Marshal(result) if err != nil { continue } _, ok := u.symbol.Load(psgMsg.Symbol) if ok { u.msg <- priceByte } else { applogger.Info("Administrator cancels Indian stock order subscription.") return } } time.Sleep(1 * time.Second) } }