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.
99 lines
2.6 KiB
99 lines
2.6 KiB
2 months ago
|
package socket
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"encoding/json"
|
||
|
"matchmaking-system/internal/data"
|
||
|
"matchmaking-system/internal/data/memory"
|
||
|
"matchmaking-system/internal/data/socket/forexData"
|
||
|
"matchmaking-system/internal/data/tradedeal/forex"
|
||
|
"matchmaking-system/internal/pkg/flags"
|
||
|
"matchmaking-system/internal/pkg/logging/applogger"
|
||
|
"matchmaking-system/internal/pkg/setting"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
// orderSubAdminForexSubscribeByOrder
|
||
|
//
|
||
|
// @Description: 管理员外汇|持仓订单订阅|持仓浮动盈亏订阅
|
||
|
// @receiver u
|
||
|
// @param psgMsg
|
||
|
func (u *Client) orderSubAdminForexSubscribeByOrder(psgMsg *SymbolMessage) {
|
||
|
for {
|
||
|
if psgMsg.Symbol == setting.AdminForexSubscribe {
|
||
|
var hashList []forex.ForexTallyCache
|
||
|
for _, field := range psgMsg.Order {
|
||
|
fieldStr, err := data.Reds.HGet(context.Background(), setting.AdminForexSubscribe, field).Result()
|
||
|
if err != nil {
|
||
|
continue
|
||
|
}
|
||
|
var msg forex.ForexTallyCache
|
||
|
if err = json.Unmarshal([]byte(fieldStr), &msg); err != nil {
|
||
|
time.Sleep(5 * time.Second)
|
||
|
continue
|
||
|
}
|
||
|
hashList = append(hashList, msg)
|
||
|
}
|
||
|
|
||
|
for _, value := range hashList {
|
||
|
orderModel := forexData.ForexOrderProcessing(setting.AdminForexSubscribe, 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.AdminForexSubscribe, orderModel.OrderId).Err(); err != nil {
|
||
|
applogger.Error("AdminForexSubscribe.HDel:%v", err)
|
||
|
continue
|
||
|
}
|
||
|
}
|
||
|
orderStr, err := json.Marshal(orderModel)
|
||
|
if err != nil {
|
||
|
applogger.Error("Administrator Forex subscription cache order error:%v", err)
|
||
|
time.Sleep(5 * time.Second)
|
||
|
continue
|
||
|
}
|
||
|
|
||
|
u.msg <- orderStr // 用户(挂单|持仓)订阅
|
||
|
} else {
|
||
|
applogger.Info("Administrator cancels Forex order subscription.")
|
||
|
return
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
time.Sleep(600 * time.Millisecond)
|
||
|
}
|
||
|
}
|
||
|
func (u *Client) orderSubAdminForexSubscribeBySum(psgMsg *SymbolMessage) {
|
||
|
for {
|
||
|
if psgMsg.Symbol == setting.AdminForexSumSubscribe {
|
||
|
priceSum, err := memory.ForexFloating.Get(flags.FloatingWh)
|
||
|
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 Forex order subscription.")
|
||
|
return
|
||
|
}
|
||
|
}
|
||
|
|
||
|
time.Sleep(2 * time.Second)
|
||
|
}
|
||
|
}
|