You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
98 lines
2.7 KiB
98 lines
2.7 KiB
package socket
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"matchmaking-system/internal/data"
|
|
"matchmaking-system/internal/data/memory"
|
|
"matchmaking-system/internal/data/socket/moneyData"
|
|
"matchmaking-system/internal/data/tradedeal/money"
|
|
"matchmaking-system/internal/pkg/flags"
|
|
"matchmaking-system/internal/pkg/logging/applogger"
|
|
"matchmaking-system/internal/pkg/setting"
|
|
"time"
|
|
)
|
|
|
|
// orderSubAdminMoneySubscribeByOrder
|
|
//
|
|
// @Description: 管理员综合(现货|合约|外汇)|持仓订单订阅|持仓浮动盈亏订阅
|
|
// @receiver u
|
|
// @param psgMsg
|
|
func (u *Client) orderSubAdminMoneySubscribeByOrder(psgMsg *SymbolMessage) {
|
|
for {
|
|
if psgMsg.Symbol == setting.AdminMoneySubscribe {
|
|
var hashList []money.MoneyTallyCache
|
|
for _, field := range psgMsg.Order {
|
|
fieldStr, err := data.Reds.HGet(context.Background(), setting.AdminMoneySubscribe, field).Result()
|
|
if err != nil {
|
|
continue
|
|
}
|
|
var msg money.MoneyTallyCache
|
|
if err = json.Unmarshal([]byte(fieldStr), &msg); err != nil {
|
|
time.Sleep(5 * time.Second)
|
|
continue
|
|
}
|
|
hashList = append(hashList, msg)
|
|
}
|
|
|
|
for _, value := range hashList {
|
|
orderModel := moneyData.MoneyOrderProcessing(setting.AdminMoneySubscribe, 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.AdminMoneySubscribe, orderModel.OrderId).Err(); err != nil {
|
|
applogger.Error("AdminMoneySubscribe.HDel:%v", err)
|
|
continue
|
|
}
|
|
}
|
|
orderStr, err := json.Marshal(orderModel)
|
|
if err != nil {
|
|
applogger.Error("Administrator Money subscription cache order error:%v", err)
|
|
time.Sleep(5 * time.Second)
|
|
continue
|
|
}
|
|
|
|
u.msg <- orderStr // 用户(挂单|持仓)订阅
|
|
} else {
|
|
applogger.Info("Administrator cancels Money order subscription.")
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
time.Sleep(600 * time.Millisecond)
|
|
}
|
|
}
|
|
func (u *Client) orderSubAdminMoneySubscribeBySum(psgMsg *SymbolMessage) {
|
|
for {
|
|
if psgMsg.Symbol == setting.AdminMoneySumSubscribe {
|
|
priceSum, err := memory.MoneyTotalFloating.Get(flags.FloatingZh)
|
|
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 Money order subscription.")
|
|
return
|
|
}
|
|
}
|
|
|
|
time.Sleep(2 * time.Second)
|
|
}
|
|
}
|
|
|