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.
74 lines
2.2 KiB
74 lines
2.2 KiB
package socket
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"matchmaking-system/internal/data"
|
|
"matchmaking-system/internal/data/socket/shareData"
|
|
"matchmaking-system/internal/data/tradedeal/share"
|
|
"matchmaking-system/internal/data/tradedeal/virtual"
|
|
"matchmaking-system/internal/pkg/flags"
|
|
"matchmaking-system/internal/pkg/logging/applogger"
|
|
"matchmaking-system/internal/pkg/setting"
|
|
"time"
|
|
)
|
|
|
|
// orderSubShareHkdSubscribe
|
|
//
|
|
// @Description: 用户大宗交易股订单订阅
|
|
// @receiver u
|
|
// @param psgMsg
|
|
func (u *Client) orderSubShareBlkSubscribe(psgMsg *SymbolMessage) {
|
|
for {
|
|
userId, err := GetUserIdByToken(u.token)
|
|
if err != nil {
|
|
time.Sleep(5 * time.Second)
|
|
cleanSubscriptionKey(u)
|
|
break
|
|
}
|
|
|
|
if userId != flags.AdministratorsId && psgMsg.Symbol == setting.SubscribeShareBlk {
|
|
orderTokenKey := virtual.OrderIdListKey(setting.ShareBlkSubscribe, userId)
|
|
orderList, err := data.Reds.HGetAll(context.Background(), orderTokenKey).Result()
|
|
if err != nil {
|
|
time.Sleep(5 * time.Second)
|
|
continue
|
|
}
|
|
|
|
for _, value := range orderList {
|
|
var msg share.ShareBlkTallyCache
|
|
if err = json.Unmarshal([]byte(value), &msg); err != nil {
|
|
time.Sleep(5 * time.Second)
|
|
continue
|
|
}
|
|
orderModel := shareData.ShareBlkOrderProcessing(setting.ShareBlkSubscribe, 0, msg)
|
|
if orderModel != nil {
|
|
_, ok := u.symbol.Load(psgMsg.Symbol)
|
|
if ok {
|
|
// 清理股票股订阅缓存订单中(撤单|平仓)状态的订单
|
|
if orderModel.Status == flags.Cancel || orderModel.Status == flags.Close {
|
|
err = data.Reds.HDel(context.Background(), orderTokenKey, msg.OrderId).Err()
|
|
if err != nil {
|
|
time.Sleep(5 * time.Second)
|
|
applogger.Error("ShareBlkSubscribe.HDel:%v", err)
|
|
continue
|
|
}
|
|
}
|
|
orderStr, err := json.Marshal(orderModel)
|
|
if err != nil {
|
|
applogger.Error("User's block stock subscription cache order error:%v", err)
|
|
time.Sleep(5 * time.Second)
|
|
continue
|
|
}
|
|
u.msg <- orderStr // 用户(挂单|持仓)订阅
|
|
} else {
|
|
applogger.Info("User cancels block stock order subscription.")
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
time.Sleep(600 * time.Millisecond)
|
|
}
|
|
}
|
|
|