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.
2249 lines
53 KiB
2249 lines
53 KiB
package data
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"github.com/go-kratos/kratos/v2/transport"
|
|
"github.com/shopspring/decimal"
|
|
"matchmaking-system/internal/biz/structure"
|
|
"matchmaking-system/internal/data/redis"
|
|
"matchmaking-system/internal/data/tradedeal/option"
|
|
"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/logging/common"
|
|
"matchmaking-system/internal/pkg/utils"
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
|
|
forexd "matchmaking-system/internal/data/tradedeal/forex"
|
|
moneyd "matchmaking-system/internal/data/tradedeal/money"
|
|
models "matchmaking-system/internal/pkg/model"
|
|
)
|
|
|
|
// CheckToken
|
|
//
|
|
// @Description: Verify token
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @return int
|
|
// @return error
|
|
func (uo *userOrderRepo) CheckToken(ctx context.Context) (int, error) {
|
|
tr, checkBool := transport.FromServerContext(ctx)
|
|
if !checkBool {
|
|
return 0, nil
|
|
}
|
|
header := tr.RequestHeader()
|
|
|
|
var token string
|
|
switch flags.CheckNetwork {
|
|
case flags.CheckTest: // locale
|
|
authorization := header.Get(flags.TokenTest)
|
|
authorizationLen := len(authorization)
|
|
if len(authorization) >= 7 {
|
|
token = authorization[7:authorizationLen]
|
|
}
|
|
case flags.CheckOnLine: // Online environment(test|onLine)
|
|
token = header.Get(flags.TokenOnLine)
|
|
default:
|
|
applogger.Error("CheckToken:Please enter the initialized environment variable.")
|
|
}
|
|
|
|
tokenStr := fmt.Sprintf("%v%v", flags.UserToken, token)
|
|
|
|
if !flags.CheckSetting {
|
|
applogger.Debug("Splicing Token Information:%v", tokenStr)
|
|
}
|
|
|
|
userId, err := redis.GetCacheData(ctx, uo.data.redisDB, tokenStr)
|
|
if err != nil || len(userId) == 0 {
|
|
return 0, err
|
|
}
|
|
|
|
userID, err := strconv.Atoi(userId)
|
|
if err != nil || userID == 0 {
|
|
return 0, err
|
|
}
|
|
|
|
return userID, nil
|
|
}
|
|
|
|
// GetBotUser
|
|
//
|
|
// @Description: get user id
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param token
|
|
// @return int
|
|
// @return error
|
|
func (uo *userOrderRepo) GetBotUser(token string) (int, error) {
|
|
var userModel []models.BotUsers
|
|
if err := uo.data.mysqlDB.Table(flags.BotUsers).
|
|
Where("access_token = ?", token).
|
|
Where("status = 1").
|
|
Find(&userModel); err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
var userId int
|
|
for _, value := range userModel {
|
|
userId = int(value.UserId)
|
|
}
|
|
|
|
return userId, nil
|
|
}
|
|
|
|
// GetBotUserIsRealByUserId
|
|
//
|
|
// @Description: Query user identity authentication based on user ID
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param userId
|
|
// @return bool
|
|
// @return error
|
|
func (uo *userOrderRepo) GetBotUserIsRealByUserId(ctx context.Context, userId int) bool {
|
|
var checkBool bool
|
|
var userModel []models.BotUsers
|
|
if err := uo.data.mysqlDB.Table(flags.BotUsers).
|
|
Where("user_id = ?", userId).
|
|
Where("status = 1").
|
|
Find(&userModel); err != nil {
|
|
return checkBool
|
|
}
|
|
|
|
for _, value := range userModel {
|
|
switch value.IsReal {
|
|
case 0: // 未实名
|
|
checkBool = false
|
|
case 1: // 实名
|
|
checkBool = true
|
|
default:
|
|
checkBool = false
|
|
}
|
|
}
|
|
|
|
return checkBool
|
|
}
|
|
|
|
// GetBotStockListByStockName
|
|
//
|
|
// @Description:
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param stockId
|
|
// @return string
|
|
// @return error
|
|
func (uo *userOrderRepo) GetBotStockListByStockName(ctx context.Context, stockId string) (string, error) {
|
|
var stockList []models.BotStockList
|
|
if err := uo.data.mysqlDB.Table(flags.BotStockList).
|
|
Where("stock_name = ?", stockId).
|
|
Find(&stockList); err != nil {
|
|
return flags.SetNull, err
|
|
}
|
|
|
|
for _, value := range stockList {
|
|
return value.StockName, nil
|
|
}
|
|
|
|
return flags.SetNull, nil
|
|
}
|
|
|
|
// GetBotDigitalListByDigitalName
|
|
//
|
|
// @Description:
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param digitalId
|
|
// @return string
|
|
// @return error
|
|
func (uo *userOrderRepo) GetBotDigitalListByDigitalName(ctx context.Context, digitalId string) (string, error) {
|
|
var digitalList []models.BotDigitalList
|
|
if err := uo.data.mysqlDB.Table(flags.BotDigitalList).
|
|
Where("trade_name = ?", digitalId).
|
|
Find(&digitalList); err != nil {
|
|
return flags.SetNull, err
|
|
}
|
|
|
|
for _, value := range digitalList {
|
|
return value.TradeName, nil
|
|
}
|
|
|
|
return flags.SetNull, nil
|
|
}
|
|
|
|
// GetBotContractListByContractName
|
|
//
|
|
// @Description:
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param contractId
|
|
// @return string
|
|
// @return error
|
|
func (uo *userOrderRepo) GetBotContractListByContractName(ctx context.Context, contractId string) (string, error) {
|
|
var contractList []models.BotContractList
|
|
if err := uo.data.mysqlDB.Table(flags.BotContractList).
|
|
Where("trade_name = ?", contractId).
|
|
Find(&contractList); err != nil {
|
|
return flags.SetNull, err
|
|
}
|
|
for _, value := range contractList {
|
|
return value.TradeName, nil
|
|
}
|
|
|
|
return flags.SetNull, nil
|
|
}
|
|
|
|
// GetBotUserStockByStockId
|
|
//
|
|
// @Description:
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param userId
|
|
// @param stockId
|
|
// @return *models.BotUserStock
|
|
// @return error
|
|
func (uo *userOrderRepo) GetBotUserStockByStockId(ctx context.Context, userId, stockId int64) (*models.BotUserStock, error) {
|
|
var botUserStockList []models.BotUserStock
|
|
if err := uo.data.mysqlDB.Table(flags.BotUserStock).
|
|
Where("user_id = ?", userId).
|
|
Where("stock_id = ?", stockId).
|
|
Find(&botUserStockList); err != nil {
|
|
return nil, err
|
|
}
|
|
var botUserStock models.BotUserStock
|
|
for _, value := range botUserStockList {
|
|
botUserStock = value
|
|
}
|
|
|
|
return &botUserStock, nil
|
|
}
|
|
|
|
// GetBotUserDigitalByDigitalId
|
|
//
|
|
// @Description:
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param userId
|
|
// @param stockId
|
|
// @return *models.BotUserDigital
|
|
// @return error
|
|
func (uo *userOrderRepo) GetBotUserDigitalByDigitalId(ctx context.Context, userId, stockId int64) (*models.BotUserDigital, error) {
|
|
var botUserDigitalList []models.BotUserDigital
|
|
if err := uo.data.mysqlDB.Table(flags.BotUserDigital).
|
|
Where("user_id = ?", userId).
|
|
Where("digital_id = ?", stockId).
|
|
Find(&botUserDigitalList); err != nil {
|
|
return nil, err
|
|
}
|
|
var botUserDigital models.BotUserDigital
|
|
for _, value := range botUserDigitalList {
|
|
botUserDigital = value
|
|
}
|
|
|
|
return &botUserDigital, nil
|
|
}
|
|
|
|
// GetBotUserContractByContractId
|
|
//
|
|
// @Description:
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param userId
|
|
// @param stockId
|
|
// @return *models.BotUserContract
|
|
// @return error
|
|
func (uo *userOrderRepo) GetBotUserContractByContractId(ctx context.Context, userId, stockId int64) (*models.BotUserContract, error) {
|
|
var botUserContractList []models.BotUserContract
|
|
if err := uo.data.mysqlDB.Table(flags.BotUserContract).
|
|
Where("user_id = ?", userId).
|
|
Where("contract_id = ?", stockId).
|
|
Find(&botUserContractList); err != nil {
|
|
return nil, err
|
|
}
|
|
var botUserContract models.BotUserContract
|
|
for _, value := range botUserContractList {
|
|
botUserContract = value
|
|
}
|
|
|
|
return &botUserContract, nil
|
|
}
|
|
|
|
// HSetRedisKey
|
|
//
|
|
// @Description: Write cache list data
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param key
|
|
// @param value
|
|
// @return error
|
|
func (uo *userOrderRepo) HSetRedisKey(ctx context.Context, key, value string) error {
|
|
code := strings.ToUpper(value)
|
|
if err := uo.data.redisDB.HSet(ctx, key, code, code).Err(); err != nil {
|
|
applogger.Error("HSetRedisKey.HSet:%v", err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// UpdateSpotsSubscribeStatusHashByOrderId
|
|
//
|
|
// @Description: 更新(用户)现货订阅缓存hash列表订单状态
|
|
// @param userId
|
|
// @param orderId
|
|
// @param updateKey
|
|
// @param status
|
|
// @return error
|
|
func UpdateSpotsSubscribeStatusHashByOrderId(userId int64, orderId, updateKey, status string) error {
|
|
// 查询hash缓存列表数据
|
|
cacheKey := virtual.OrderIdListKey(updateKey, userId)
|
|
order, err := Reds.HGet(context.Background(), cacheKey, orderId).Result()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// 序列化json数据
|
|
var orderModel virtual.SpotsTallyCache
|
|
if err = json.Unmarshal([]byte(order), &orderModel); err != nil {
|
|
return err
|
|
}
|
|
|
|
// 修改数据状态
|
|
orderModel.Status = status
|
|
orderStr, err := json.Marshal(&orderModel)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// 更新hash订阅缓存数据
|
|
err = Reds.HSet(context.Background(), cacheKey, orderId, string(orderStr)).Err()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// UpdateContractSubscribeHashStatusByOrderId
|
|
//
|
|
// @Description: 更新(用户|管理员)合约订阅缓存列表订单状态
|
|
// @param orderId
|
|
// @param updateKey
|
|
// @param status
|
|
// @return error
|
|
func UpdateContractSubscribeHashStatusByOrderId(orderId, updateKey, status, closePrice string) error {
|
|
order, err := Reds.HGet(context.Background(), updateKey, orderId).Result()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var orderModel virtual.ContractTallyCache
|
|
if err = json.Unmarshal([]byte(order), &orderModel); err != nil {
|
|
return err
|
|
}
|
|
|
|
orderModel.Status = status
|
|
if len(utils.ReplaceStr(orderModel.ClosingPrice)) == 0 {
|
|
orderModel.ClosingPrice = closePrice
|
|
}
|
|
orderStr, err := json.Marshal(&orderModel)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = Reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// UpdateForexSubscribeHashStatusByOrderId
|
|
//
|
|
// @Description: 更新(用户|管理员)外汇订阅缓存列表订单状态
|
|
// @param orderId
|
|
// @param updateKey
|
|
// @param status
|
|
// @param closePrice
|
|
// @return error
|
|
func UpdateForexSubscribeHashStatusByOrderId(orderId, updateKey, status, closePrice string) error {
|
|
order, err := Reds.HGet(context.Background(), updateKey, orderId).Result()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var orderModel forexd.ForexTallyCache
|
|
if err = json.Unmarshal([]byte(order), &orderModel); err != nil {
|
|
return err
|
|
}
|
|
|
|
orderModel.Status = status
|
|
if len(utils.ReplaceStr(orderModel.ClosingPrice)) == 0 {
|
|
orderModel.ClosingPrice = closePrice
|
|
}
|
|
orderStr, err := json.Marshal(&orderModel)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = Reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// UpdateMoneySubscribeHashStatusByOrderId
|
|
//
|
|
// @Description: 更新(用户|管理员)综合(现货|合约|外汇)订阅缓存列表订单状态
|
|
// @param orderId
|
|
// @param updateKey
|
|
// @param status
|
|
// @param closePrice
|
|
// @return error
|
|
func UpdateMoneySubscribeHashStatusByOrderId(orderId, updateKey, status, closePrice string) error {
|
|
order, err := Reds.HGet(context.Background(), updateKey, orderId).Result()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var orderModel moneyd.MoneyTallyCache
|
|
if err = json.Unmarshal([]byte(order), &orderModel); err != nil {
|
|
return err
|
|
}
|
|
|
|
orderModel.Status = status
|
|
if len(utils.ReplaceStr(orderModel.ClosingPrice)) == 0 {
|
|
orderModel.ClosingPrice = closePrice
|
|
}
|
|
orderStr, err := json.Marshal(&orderModel)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = Reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// UpdateShareUsSubscribeHashStatusByOrderId
|
|
//
|
|
// @Description: 更新(用户|管理员)美股订阅缓存列表订单状态
|
|
// @param orderId
|
|
// @param updateKey
|
|
// @param status
|
|
// @return error
|
|
func UpdateShareUsSubscribeHashStatusByOrderId(orderId, updateKey, status, openPrice string) error {
|
|
order, err := Reds.HGet(context.Background(), updateKey, orderId).Result()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var orderModel share.ShareUsTallyCache
|
|
if err = json.Unmarshal([]byte(order), &orderModel); err != nil {
|
|
return err
|
|
}
|
|
|
|
orderModel.Status = status
|
|
if status == flags.Position {
|
|
orderModel.OpenPrice = openPrice
|
|
}
|
|
orderStr, err := json.Marshal(&orderModel)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = Reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// UpdateShareIdnSubscribeHashStatusByOrderId
|
|
//
|
|
// @Description: 更新(用户|管理员)印尼股订阅缓存列表订单状态
|
|
// @param orderId
|
|
// @param updateKey
|
|
// @param status
|
|
// @return error
|
|
func UpdateShareIdnSubscribeHashStatusByOrderId(orderId, updateKey, status, openPrice string) error {
|
|
order, err := Reds.HGet(context.Background(), updateKey, orderId).Result()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var orderModel share.ShareIdnTallyCache
|
|
if err = json.Unmarshal([]byte(order), &orderModel); err != nil {
|
|
return err
|
|
}
|
|
|
|
orderModel.Status = status
|
|
if status == flags.Position {
|
|
orderModel.OpenPrice = openPrice
|
|
}
|
|
orderStr, err := json.Marshal(&orderModel)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = Reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// UpdateShareHkdSubscribeHashStatusByOrderId
|
|
//
|
|
// @Description:
|
|
// @param orderId
|
|
// @param updateKey
|
|
// @param status
|
|
// @param openPrice
|
|
// @return error
|
|
func UpdateShareHkdSubscribeHashStatusByOrderId(orderId, updateKey, status, openPrice string) error {
|
|
order, err := Reds.HGet(context.Background(), updateKey, orderId).Result()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var orderModel share.ShareHkdTallyCache
|
|
if err = json.Unmarshal([]byte(order), &orderModel); err != nil {
|
|
return err
|
|
}
|
|
|
|
orderModel.Status = status
|
|
if status == flags.Position {
|
|
orderModel.OpenPrice = openPrice
|
|
}
|
|
orderStr, err := json.Marshal(&orderModel)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = Reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// UpdateShareInrSubscribeHashStatusByOrderId
|
|
//
|
|
// @Description: 更新(用户|管理员)印度股订阅缓存列表订单状态
|
|
// @param orderId
|
|
// @param updateKey
|
|
// @param status
|
|
// @return error
|
|
func UpdateShareInrSubscribeHashStatusByOrderId(orderId, updateKey, status, openPrice string) error {
|
|
order, err := Reds.HGet(context.Background(), updateKey, orderId).Result()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var orderModel share.ShareInrTallyCache
|
|
if err = json.Unmarshal([]byte(order), &orderModel); err != nil {
|
|
return err
|
|
}
|
|
|
|
orderModel.Status = status
|
|
if status == flags.Position {
|
|
orderModel.OpenPrice = openPrice
|
|
}
|
|
orderStr, err := json.Marshal(&orderModel)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = Reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// UpdateShareGbxSubscribeHashStatusByOrderId
|
|
//
|
|
// @Description: 更新(用户|管理员)英股订阅缓存列表订单状态
|
|
// @param orderId
|
|
// @param updateKey
|
|
// @param status
|
|
// @param openPrice
|
|
// @return error
|
|
func UpdateShareGbxSubscribeHashStatusByOrderId(orderId, updateKey, status, openPrice string) error {
|
|
order, err := Reds.HGet(context.Background(), updateKey, orderId).Result()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var orderModel share.ShareGbxTallyCache
|
|
if err = json.Unmarshal([]byte(order), &orderModel); err != nil {
|
|
return err
|
|
}
|
|
|
|
orderModel.Status = status
|
|
if status == flags.Position {
|
|
orderModel.OpenPrice = openPrice
|
|
}
|
|
orderStr, err := json.Marshal(&orderModel)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = Reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// UpdateOptionInrSubscribeHashStatusByOrderId
|
|
//
|
|
// @Description:
|
|
// @param orderId
|
|
// @param updateKey
|
|
// @param status
|
|
// @param openPrice
|
|
// @return error
|
|
func UpdateOptionInrSubscribeHashStatusByOrderId(orderId, updateKey, status, openPrice string) error {
|
|
order, err := Reds.HGet(context.Background(), updateKey, orderId).Result()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var orderModel option.OptionInrTallyCache
|
|
if err = json.Unmarshal([]byte(order), &orderModel); err != nil {
|
|
return err
|
|
}
|
|
|
|
orderModel.Status = status
|
|
if status == flags.Position {
|
|
orderModel.OpenPrice = openPrice
|
|
}
|
|
orderStr, err := json.Marshal(&orderModel)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = Reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// UpdateShareMysSubscribeHashStatusByOrderId
|
|
//
|
|
// @Description: 更新(用户|管理员)马股订阅缓存列表订单状态
|
|
// @param orderId
|
|
// @param updateKey
|
|
// @param status
|
|
// @return error
|
|
func UpdateShareMysSubscribeHashStatusByOrderId(orderId, updateKey, status, openPrice string) error {
|
|
order, err := Reds.HGet(context.Background(), updateKey, orderId).Result()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var orderModel share.ShareMysTallyCache
|
|
if err = json.Unmarshal([]byte(order), &orderModel); err != nil {
|
|
return err
|
|
}
|
|
|
|
orderModel.Status = status
|
|
if status == flags.Position {
|
|
orderModel.OpenPrice = openPrice
|
|
}
|
|
orderStr, err := json.Marshal(&orderModel)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = Reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// UpdateShareThaSubscribeHashStatusByOrderId
|
|
//
|
|
// @Description: 更新(用户|管理员)泰股订阅缓存列表订单状态
|
|
// @param orderId
|
|
// @param updateKey
|
|
// @param status
|
|
// @return error
|
|
func UpdateShareThaSubscribeHashStatusByOrderId(orderId, updateKey, status, openPrice string) error {
|
|
order, err := Reds.HGet(context.Background(), updateKey, orderId).Result()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var orderModel share.ShareThaTallyCache
|
|
if err = json.Unmarshal([]byte(order), &orderModel); err != nil {
|
|
return err
|
|
}
|
|
|
|
orderModel.Status = status
|
|
if status == flags.Position {
|
|
orderModel.OpenPrice = openPrice
|
|
}
|
|
orderStr, err := json.Marshal(&orderModel)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = Reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// UpdateShareSgdSubscribeHashStatusByOrderId
|
|
//
|
|
// @Description: 更新(用户|管理员)泰股订阅缓存列表订单状态
|
|
// @param orderId
|
|
// @param updateKey
|
|
// @param status
|
|
// @param openPrice
|
|
// @return error
|
|
func UpdateShareSgdSubscribeHashStatusByOrderId(orderId, updateKey, status, openPrice string) error {
|
|
order, err := Reds.HGet(context.Background(), updateKey, orderId).Result()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var orderModel share.ShareSgdTallyCache
|
|
if err = json.Unmarshal([]byte(order), &orderModel); err != nil {
|
|
return err
|
|
}
|
|
|
|
orderModel.Status = status
|
|
if status == flags.Position {
|
|
orderModel.OpenPrice = openPrice
|
|
}
|
|
orderStr, err := json.Marshal(&orderModel)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = Reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// UpdateShareEurSubscribeHashStatusByOrderId
|
|
//
|
|
// @Description: 更新(用户|管理员)德股订阅缓存列表订单状态
|
|
// @param orderId
|
|
// @param updateKey
|
|
// @param status
|
|
// @param openPrice
|
|
// @return error
|
|
func UpdateShareEurSubscribeHashStatusByOrderId(orderId, updateKey, status, openPrice string) error {
|
|
order, err := Reds.HGet(context.Background(), updateKey, orderId).Result()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var orderModel share.ShareEurTallyCache
|
|
if err = json.Unmarshal([]byte(order), &orderModel); err != nil {
|
|
return err
|
|
}
|
|
|
|
orderModel.Status = status
|
|
if status == flags.Position {
|
|
orderModel.OpenPrice = openPrice
|
|
}
|
|
orderStr, err := json.Marshal(&orderModel)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = Reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// UpdateShareBrlSubscribeHashStatusByOrderId
|
|
//
|
|
// @Description: 更新(用户|管理员)巴西股订阅缓存列表订单状态
|
|
// @param orderId
|
|
// @param updateKey
|
|
// @param status
|
|
// @param openPrice
|
|
// @return error
|
|
func UpdateShareBrlSubscribeHashStatusByOrderId(orderId, updateKey, status, openPrice string) error {
|
|
order, err := Reds.HGet(context.Background(), updateKey, orderId).Result()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var orderModel share.ShareBrlTallyCache
|
|
if err = json.Unmarshal([]byte(order), &orderModel); err != nil {
|
|
return err
|
|
}
|
|
|
|
orderModel.Status = status
|
|
if status == flags.Position {
|
|
orderModel.OpenPrice = openPrice
|
|
}
|
|
orderStr, err := json.Marshal(&orderModel)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = Reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// UpdateShareFurSubscribeHashStatusByOrderId
|
|
//
|
|
// @Description: 更新(用户|管理员)法股订阅缓存列表订单状态
|
|
// @param orderId
|
|
// @param updateKey
|
|
// @param status
|
|
// @param openPrice
|
|
// @return error
|
|
func UpdateShareFurSubscribeHashStatusByOrderId(orderId, updateKey, status, openPrice string) error {
|
|
order, err := Reds.HGet(context.Background(), updateKey, orderId).Result()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var orderModel share.ShareFurTallyCache
|
|
if err = json.Unmarshal([]byte(order), &orderModel); err != nil {
|
|
return err
|
|
}
|
|
|
|
orderModel.Status = status
|
|
if status == flags.Position {
|
|
orderModel.OpenPrice = openPrice
|
|
}
|
|
orderStr, err := json.Marshal(&orderModel)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = Reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// UpdateShareJpySubscribeHashStatusByOrderId
|
|
//
|
|
// @Description: 更新(用户|管理员)日股订阅缓存列表订单状态
|
|
// @param orderId
|
|
// @param updateKey
|
|
// @param status
|
|
// @param openPrice
|
|
// @return error
|
|
func UpdateShareJpySubscribeHashStatusByOrderId(orderId, updateKey, status, openPrice string) error {
|
|
order, err := Reds.HGet(context.Background(), updateKey, orderId).Result()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var orderModel share.ShareJpyTallyCache
|
|
if err = json.Unmarshal([]byte(order), &orderModel); err != nil {
|
|
return err
|
|
}
|
|
|
|
orderModel.Status = status
|
|
if status == flags.Position {
|
|
orderModel.OpenPrice = openPrice
|
|
}
|
|
orderStr, err := json.Marshal(&orderModel)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = Reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// GetBotDigitalList
|
|
//
|
|
// @Description:
|
|
// @param ctx
|
|
// @param uo
|
|
// @return []string
|
|
// @return error
|
|
func GetBotDigitalList(ctx context.Context, uo *Data) ([]string, error) {
|
|
var digitalList []models.BotDigitalList
|
|
if err := uo.mysqlDB.Table(flags.BotDigitalList).
|
|
Where("status = 1").
|
|
Find(&digitalList); err != nil {
|
|
return []string{}, err
|
|
}
|
|
|
|
var codeList []string
|
|
for _, value := range digitalList {
|
|
codeList = append(codeList, value.TradeName)
|
|
}
|
|
|
|
return codeList, nil
|
|
}
|
|
|
|
// GetBotContractList
|
|
//
|
|
// @Description:
|
|
// @param ctx
|
|
// @param uo
|
|
// @return []string
|
|
// @return error
|
|
func GetBotContractList(ctx context.Context, uo *Data) ([]string, error) {
|
|
var contractList []models.BotContractList
|
|
if err := uo.mysqlDB.Table(flags.BotContractList).
|
|
Where("status = 1").
|
|
Find(&contractList); err != nil {
|
|
return []string{}, err
|
|
}
|
|
|
|
var codeList []string
|
|
for _, value := range contractList {
|
|
codeList = append(codeList, value.TradeName)
|
|
}
|
|
|
|
return codeList, nil
|
|
}
|
|
|
|
// GetBotForexList
|
|
//
|
|
// @Description:
|
|
// @param ctx
|
|
// @param uo
|
|
// @return []string
|
|
// @return error
|
|
func GetBotForexList(ctx context.Context, uo *Data) ([]string, error) {
|
|
var forexList []models.BotForexList
|
|
if err := uo.mysqlDB.Table(flags.BotForexList).
|
|
Where("status = 1").
|
|
Find(&forexList); err != nil {
|
|
return []string{}, err
|
|
}
|
|
|
|
var codeList []string
|
|
for _, value := range forexList {
|
|
codeList = append(codeList, value.TradeName)
|
|
}
|
|
|
|
return codeList, nil
|
|
}
|
|
|
|
// GetBotMoneyList
|
|
//
|
|
// @Description: 联合查询统计合约|现货|外汇交易对列表
|
|
// @param ctx
|
|
// @param uo
|
|
// @return []string
|
|
// @return error
|
|
func GetBotMoneyList(ctx context.Context, uo *Data) ([]string, error) {
|
|
// 外汇数据
|
|
var forexList []models.BotForexList
|
|
if err := uo.mysqlDB.Table(flags.BotForexList).Where("status = 1").Find(&forexList); err != nil {
|
|
return []string{}, err
|
|
}
|
|
|
|
var codeList []string
|
|
for _, value := range forexList {
|
|
codeList = append(codeList, value.TradeName)
|
|
}
|
|
// 合约数据
|
|
var contractList []models.BotContractList
|
|
if err := uo.mysqlDB.Table(flags.BotContractList).Where("status = 1").Find(&contractList); err != nil {
|
|
return []string{}, err
|
|
}
|
|
for _, value := range contractList {
|
|
codeList = append(codeList, strings.Replace(strings.ToUpper(value.TradeName), "USDT", "USD", -1))
|
|
}
|
|
// 现货数据
|
|
var spotsList []models.BotDigitalList
|
|
if err := uo.mysqlDB.Table(flags.BotDigitalList).Where("status = 1").Find(&spotsList); err != nil {
|
|
return []string{}, err
|
|
}
|
|
for _, value := range spotsList {
|
|
codeList = append(codeList, strings.Replace(strings.ToUpper(value.TradeName), "USDT", "USD", -1))
|
|
}
|
|
|
|
return codeList, nil
|
|
}
|
|
|
|
// GetBotStockList
|
|
//
|
|
// @Description:
|
|
// @param ctx
|
|
// @param uo
|
|
// @return []string
|
|
// @return error
|
|
func GetBotStockList(ctx context.Context, uo *Data) ([]string, error) {
|
|
var stockList []models.BotStockList
|
|
if err := uo.mysqlDB.Table(flags.BotStockList).
|
|
Where("status = 1").
|
|
Find(&stockList); err != nil {
|
|
return []string{}, err
|
|
}
|
|
|
|
var codeList []string
|
|
for _, value := range stockList {
|
|
codeList = append(codeList, value.StockCode)
|
|
}
|
|
|
|
return codeList, nil
|
|
}
|
|
|
|
// GetBotStockListByStockId
|
|
//
|
|
// @Description: 查询交易订单股票类型用来订阅行情
|
|
// @param ctx
|
|
// @param uo
|
|
// @return []string
|
|
// @return error
|
|
func GetBotStockListByStockId(ctx context.Context, uo *Data) ([]string, error) {
|
|
var stockList []models.BotStockTrade
|
|
if err := uo.mysqlDB.Table(flags.BotStockTrade).
|
|
Distinct("stock_id").
|
|
Find(&stockList); err != nil {
|
|
return []string{}, err
|
|
}
|
|
|
|
var codeList []string
|
|
for _, value := range stockList {
|
|
codeList = append(codeList, value.StockId)
|
|
}
|
|
|
|
return codeList, nil
|
|
}
|
|
|
|
// GetBotStockMysList
|
|
//
|
|
// @Description:
|
|
// @param ctx
|
|
// @param uo
|
|
// @return []string
|
|
// @return error
|
|
func GetBotStockMysList(ctx context.Context, uo *Data) ([]string, error) {
|
|
var stockList []models.BotStockMysList
|
|
if err := uo.mysqlDB.Table(flags.BotStockMysList).
|
|
Where("status = 1").
|
|
Find(&stockList); err != nil {
|
|
return []string{}, err
|
|
}
|
|
|
|
var codeList []string
|
|
for _, value := range stockList {
|
|
codeList = append(codeList, value.StockCode)
|
|
}
|
|
|
|
return codeList, nil
|
|
}
|
|
|
|
// GetBotStockMysListByStockId
|
|
//
|
|
// @Description:
|
|
// @param ctx
|
|
// @param uo
|
|
// @return []string
|
|
// @return error
|
|
func GetBotStockMysListByStockId(ctx context.Context, uo *Data) ([]string, error) {
|
|
var stockList []models.BotStockMysTrade
|
|
if err := uo.mysqlDB.Table(flags.BotStockMysTrade).
|
|
Distinct("stock_id").
|
|
Find(&stockList); err != nil {
|
|
return []string{}, err
|
|
}
|
|
|
|
var codeList []string
|
|
for _, value := range stockList {
|
|
codeList = append(codeList, value.StockId)
|
|
}
|
|
|
|
return codeList, nil
|
|
}
|
|
|
|
// GetBotStockIdnList
|
|
//
|
|
// @Description:
|
|
// @param ctx
|
|
// @param uo
|
|
// @return []string
|
|
// @return error
|
|
func GetBotStockIdnList(ctx context.Context, uo *Data) ([]string, error) {
|
|
var stockList []models.BotStockIdnList
|
|
if err := uo.mysqlDB.Table(flags.BotStockIdnList).
|
|
Where("status = 1").
|
|
Find(&stockList); err != nil {
|
|
return []string{}, err
|
|
}
|
|
|
|
var codeList []string
|
|
for _, value := range stockList {
|
|
codeList = append(codeList, value.StockCode)
|
|
}
|
|
|
|
return codeList, nil
|
|
}
|
|
|
|
// GetBotStockIdnListByStockId
|
|
//
|
|
// @Description:
|
|
// @param ctx
|
|
// @param uo
|
|
// @return []string
|
|
// @return error
|
|
func GetBotStockIdnListByStockId(ctx context.Context, uo *Data) ([]string, error) {
|
|
var stockList []models.BotStockIdnTrade
|
|
if err := uo.mysqlDB.Table(flags.BotStockIdnTrade).
|
|
Distinct("stock_id").
|
|
Find(&stockList); err != nil {
|
|
return []string{}, err
|
|
}
|
|
|
|
var codeList []string
|
|
for _, value := range stockList {
|
|
codeList = append(codeList, value.StockId)
|
|
}
|
|
|
|
return codeList, nil
|
|
}
|
|
|
|
// GetBotStockHkdList
|
|
//
|
|
// @Description:
|
|
// @param ctx
|
|
// @param uo
|
|
// @return []string
|
|
// @return error
|
|
func GetBotStockHkdList(ctx context.Context, uo *Data) ([]string, error) {
|
|
var stockList []models.BotStockHkdList
|
|
if err := uo.mysqlDB.Table(flags.BotStockHkdList).
|
|
Where("status = 1").
|
|
Find(&stockList); err != nil {
|
|
return []string{}, err
|
|
}
|
|
|
|
var codeList []string
|
|
for _, value := range stockList {
|
|
codeList = append(codeList, value.StockCode)
|
|
}
|
|
|
|
return codeList, nil
|
|
}
|
|
|
|
// GetBotStockHkdListByStockId
|
|
//
|
|
// @Description:
|
|
// @param ctx
|
|
// @param uo
|
|
// @return []string
|
|
// @return error
|
|
func GetBotStockHkdListByStockId(ctx context.Context, uo *Data) ([]string, error) {
|
|
var stockList []models.BotStockHkdTrade
|
|
if err := uo.mysqlDB.Table(flags.BotStockHkdTrade).
|
|
Distinct("stock_id").
|
|
Find(&stockList); err != nil {
|
|
return []string{}, err
|
|
}
|
|
|
|
var codeList []string
|
|
for _, value := range stockList {
|
|
codeList = append(codeList, value.StockId)
|
|
}
|
|
|
|
return codeList, nil
|
|
}
|
|
|
|
// GetBotStockBlockList
|
|
//
|
|
// @Description:
|
|
// @param ctx
|
|
// @param uo
|
|
// @return []string
|
|
// @return error
|
|
func GetBotStockBlockList(ctx context.Context, uo *Data) (map[int64][]string, error) {
|
|
var stockList []models.BotStockBlockList
|
|
if err := uo.mysqlDB.Table(flags.BotStockBlockList).
|
|
Where("status = 1").
|
|
Find(&stockList); err != nil {
|
|
return map[int64][]string{}, err
|
|
}
|
|
|
|
codeList := make(map[int64][]string, 0)
|
|
|
|
for _, value := range stockList {
|
|
typeStatus := int64(value.Type)
|
|
codeList[typeStatus] = append(codeList[int64(value.Type)], value.StockCode)
|
|
}
|
|
|
|
return codeList, nil
|
|
}
|
|
|
|
// GetBotStockBlockListByStockId
|
|
//
|
|
// @Description:
|
|
// @param ctx
|
|
// @param uo
|
|
// @return map[int64][]string
|
|
// @return error
|
|
func GetBotStockBlockListByStockId(ctx context.Context, uo *Data) (map[int64][]string, error) {
|
|
var stockList []models.BotStockBlockTrade
|
|
if err := uo.mysqlDB.Table(flags.BotStockBlockTrade).
|
|
Distinct("stock_id").
|
|
Find(&stockList); err != nil {
|
|
return map[int64][]string{}, err
|
|
}
|
|
|
|
codeList := make(map[int64][]string, 0)
|
|
|
|
for _, value := range stockList {
|
|
typeStatus := int64(value.Type)
|
|
codeList[typeStatus] = append(codeList[int64(value.Type)], value.StockId)
|
|
}
|
|
|
|
return codeList, nil
|
|
}
|
|
|
|
// GetBotStockInList
|
|
//
|
|
// @Description:
|
|
// @param ctx
|
|
// @param uo
|
|
// @return []string
|
|
// @return error
|
|
func GetBotStockInList(ctx context.Context, uo *Data) ([]string, error) {
|
|
var stockList []models.BotStockInList
|
|
if err := uo.mysqlDB.Table(flags.BotStockInList).
|
|
Where("status = 1").
|
|
Find(&stockList); err != nil {
|
|
return []string{}, err
|
|
}
|
|
|
|
var codeList []string
|
|
for _, value := range stockList {
|
|
codeList = append(codeList, value.StockCode)
|
|
}
|
|
|
|
return codeList, nil
|
|
}
|
|
|
|
// GetBotStockInListByStockId
|
|
//
|
|
// @Description:
|
|
// @param ctx
|
|
// @param uo
|
|
// @return []string
|
|
// @return error
|
|
func GetBotStockInListByStockId(ctx context.Context, uo *Data) ([]string, error) {
|
|
var stockList []models.BotStockInTrade
|
|
if err := uo.mysqlDB.Table(flags.BotStockInTrade).
|
|
Distinct("stock_id").
|
|
Find(&stockList); err != nil {
|
|
return []string{}, err
|
|
}
|
|
|
|
var codeList []string
|
|
for _, value := range stockList {
|
|
codeList = append(codeList, value.StockId)
|
|
}
|
|
|
|
return codeList, nil
|
|
}
|
|
|
|
// GetBotStockGbxListByStockId
|
|
//
|
|
// @Description:
|
|
// @param ctx
|
|
// @param uo
|
|
// @return []string
|
|
// @return error
|
|
func GetBotStockGbxListByStockId(ctx context.Context, uo *Data) ([]string, error) {
|
|
var stockList []models.BotStockGbxTrade
|
|
if err := uo.mysqlDB.Table(flags.BotStockGbxTrade).
|
|
Distinct("stock_id").
|
|
Find(&stockList); err != nil {
|
|
return []string{}, err
|
|
}
|
|
|
|
var codeList []string
|
|
for _, value := range stockList {
|
|
codeList = append(codeList, value.StockId)
|
|
}
|
|
|
|
return codeList, nil
|
|
}
|
|
|
|
// GetBotStockOptionInrList
|
|
//
|
|
// @Description:
|
|
// @param ctx
|
|
// @param uo
|
|
// @return []string
|
|
// @return error
|
|
func GetBotStockOptionInrList(ctx context.Context, uo *Data) ([]string, error) {
|
|
var stockList []models.BotStockOptionInrList
|
|
if err := uo.mysqlDB.Table(flags.BotStockOptionInrList).
|
|
Where("status = 1").
|
|
Find(&stockList); err != nil {
|
|
return []string{}, err
|
|
}
|
|
|
|
var codeList []string
|
|
for _, value := range stockList {
|
|
codeList = append(codeList, value.StockCode)
|
|
}
|
|
|
|
return codeList, nil
|
|
}
|
|
|
|
// GetBotStockOptionInrListByStockId
|
|
//
|
|
// @Description:
|
|
// @param ctx
|
|
// @param uo
|
|
// @return []string
|
|
// @return error
|
|
func GetBotStockOptionInrListByStockId(ctx context.Context, uo *Data) ([]string, error) {
|
|
var stockList []models.BotStockOptionInrTrade
|
|
if err := uo.mysqlDB.Table(flags.BotStockOptionInrTrade).
|
|
Distinct("stock_id").
|
|
Find(&stockList); err != nil {
|
|
return []string{}, err
|
|
}
|
|
|
|
var codeList []string
|
|
for _, value := range stockList {
|
|
codeList = append(codeList, value.StockCode)
|
|
}
|
|
|
|
return codeList, nil
|
|
}
|
|
|
|
// GetBotStockThaList
|
|
//
|
|
// @Description:
|
|
// @param ctx
|
|
// @param uo
|
|
// @return []string
|
|
// @return error
|
|
func GetBotStockThaList(ctx context.Context, uo *Data) ([]string, error) {
|
|
var stockList []models.BotStockThaList
|
|
if err := uo.mysqlDB.Table(flags.BotStockThaList).
|
|
Where("status = 1").
|
|
Find(&stockList); err != nil {
|
|
return []string{}, err
|
|
}
|
|
|
|
var codeList []string
|
|
for _, value := range stockList {
|
|
codeList = append(codeList, value.StockCode)
|
|
}
|
|
|
|
return codeList, nil
|
|
}
|
|
|
|
// GetBotStockThaListByStockId
|
|
//
|
|
// @Description:
|
|
// @param ctx
|
|
// @param uo
|
|
// @return []string
|
|
// @return error
|
|
func GetBotStockThaListByStockId(ctx context.Context, uo *Data) ([]string, error) {
|
|
var stockList []models.BotStockThaTrade
|
|
if err := uo.mysqlDB.Table(flags.BotStockThaTrade).
|
|
Distinct("stock_id").
|
|
Find(&stockList); err != nil {
|
|
return []string{}, err
|
|
}
|
|
|
|
var codeList []string
|
|
for _, value := range stockList {
|
|
codeList = append(codeList, value.StockId)
|
|
}
|
|
|
|
return codeList, nil
|
|
}
|
|
|
|
// GetBotStockSgdList
|
|
//
|
|
// @Description:
|
|
// @param ctx
|
|
// @param uo
|
|
// @return []string
|
|
// @return error
|
|
func GetBotStockSgdList(ctx context.Context, uo *Data) ([]string, error) {
|
|
var stockList []models.BotStockSgdList
|
|
if err := uo.mysqlDB.Table(flags.BotStockSgdList).
|
|
Where("status = 1").
|
|
Find(&stockList); err != nil {
|
|
return []string{}, err
|
|
}
|
|
|
|
var codeList []string
|
|
for _, value := range stockList {
|
|
codeList = append(codeList, value.StockCode)
|
|
}
|
|
|
|
return codeList, nil
|
|
}
|
|
|
|
// GetBotStockSgdListByStockId
|
|
//
|
|
// @Description:
|
|
// @param ctx
|
|
// @param uo
|
|
// @return []string
|
|
// @return error
|
|
func GetBotStockSgdListByStockId(ctx context.Context, uo *Data) ([]string, error) {
|
|
var stockList []models.BotStockSgdTrade
|
|
if err := uo.mysqlDB.Table(flags.BotStockSgdTrade).
|
|
Distinct("stock_id").
|
|
Find(&stockList); err != nil {
|
|
return []string{}, err
|
|
}
|
|
|
|
var codeList []string
|
|
for _, value := range stockList {
|
|
codeList = append(codeList, value.StockId)
|
|
}
|
|
|
|
return codeList, nil
|
|
}
|
|
|
|
// GetBotStockEurListByStockId
|
|
//
|
|
// @Description:
|
|
// @param ctx
|
|
// @param uo
|
|
// @return []string
|
|
// @return error
|
|
func GetBotStockEurListByStockId(ctx context.Context, uo *Data) ([]string, error) {
|
|
var stockList []models.BotStockEurTrade
|
|
if err := uo.mysqlDB.Table(flags.BotStockEurTrade).
|
|
Distinct("stock_id").
|
|
Find(&stockList); err != nil {
|
|
return []string{}, err
|
|
}
|
|
|
|
var codeList []string
|
|
for _, value := range stockList {
|
|
codeList = append(codeList, value.StockId)
|
|
}
|
|
|
|
return codeList, nil
|
|
}
|
|
|
|
// GetBotStockBrlListByStockId
|
|
//
|
|
// @Description:
|
|
// @param ctx
|
|
// @param uo
|
|
// @return []string
|
|
// @return error
|
|
func GetBotStockBrlListByStockId(ctx context.Context, uo *Data) ([]string, error) {
|
|
var stockList []models.BotStockBrlTrade
|
|
if err := uo.mysqlDB.Table(flags.BotStockBrlTrade).
|
|
Distinct("stock_id").
|
|
Find(&stockList); err != nil {
|
|
return []string{}, err
|
|
}
|
|
|
|
var codeList []string
|
|
for _, value := range stockList {
|
|
codeList = append(codeList, value.StockId)
|
|
}
|
|
|
|
return codeList, nil
|
|
}
|
|
|
|
// GetBotStockFurListByStockId
|
|
//
|
|
// @Description:
|
|
// @param ctx
|
|
// @param uo
|
|
// @return []string
|
|
// @return error
|
|
func GetBotStockFurListByStockId(ctx context.Context, uo *Data) ([]string, error) {
|
|
var stockList []models.BotStockFurTrade
|
|
if err := uo.mysqlDB.Table(flags.BotStockFurTrade).
|
|
Distinct("stock_id").
|
|
Find(&stockList); err != nil {
|
|
return []string{}, err
|
|
}
|
|
|
|
var codeList []string
|
|
for _, value := range stockList {
|
|
codeList = append(codeList, value.StockId)
|
|
}
|
|
|
|
return codeList, nil
|
|
}
|
|
|
|
// GetBotStockJpyListByStockId
|
|
//
|
|
// @Description:
|
|
// @param ctx
|
|
// @param uo
|
|
// @return []string
|
|
// @return error
|
|
func GetBotStockJpyListByStockId(ctx context.Context, uo *Data) ([]string, error) {
|
|
var stockList []models.BotStockJpTrade
|
|
if err := uo.mysqlDB.Table(flags.BotStockJpyTrade).
|
|
Distinct("stock_id").
|
|
Find(&stockList); err != nil {
|
|
return []string{}, err
|
|
}
|
|
|
|
var codeList []string
|
|
for _, value := range stockList {
|
|
codeList = append(codeList, value.StockId)
|
|
}
|
|
|
|
return codeList, nil
|
|
}
|
|
|
|
// NegativeValue
|
|
//
|
|
// @Description: Negative Number Definition Prefix
|
|
// @param value
|
|
// @return string
|
|
func NegativeValue(value string) string {
|
|
return fmt.Sprintf("-%v", value)
|
|
}
|
|
|
|
// GetContractSystemSetUp
|
|
//
|
|
// @Description: Contract Order System Settings
|
|
// @param symbol
|
|
// @return *structure.ContractSystem
|
|
// @return error
|
|
func GetContractSystemSetUp(symbol string) (*structure.ContractSystem, error) {
|
|
keySymbol := fmt.Sprintf("%v%v", flags.ContractSystemSetUpKey, symbol)
|
|
|
|
symbolMap, err := Reds.HGetAll(context.Background(), keySymbol).Result()
|
|
if err != nil {
|
|
applogger.Error("%v GetContractSystemSetUp.HGetAll", common.ErrContract, err)
|
|
return nil, err
|
|
}
|
|
var systemModel structure.ContractSystem
|
|
for filed, value := range symbolMap {
|
|
switch filed {
|
|
case "face_value":
|
|
systemModel.FaceValue = decimal.RequireFromString("1")
|
|
case "max_pry":
|
|
systemModel.MaxPry = decimal.RequireFromString(value)
|
|
case "min_pry":
|
|
systemModel.MinPry = decimal.RequireFromString(value)
|
|
case "compel_num":
|
|
systemModel.CompelNum = decimal.RequireFromString(flags.SetOne).Sub(decimal.RequireFromString(value))
|
|
default:
|
|
|
|
}
|
|
}
|
|
|
|
return &systemModel, nil
|
|
}
|
|
|
|
// GetForexSystemSetUp
|
|
//
|
|
// @Description:
|
|
// @param symbol
|
|
// @return *structure.ForexSystem
|
|
// @return error
|
|
func GetForexSystemSetUp(symbol string) (*structure.ForexSystem, error) {
|
|
keySymbol := fmt.Sprintf("%v%v", flags.ForexSystemSetUpKey, symbol)
|
|
|
|
symbolMap, err := Reds.HGetAll(context.Background(), keySymbol).Result()
|
|
if err != nil {
|
|
applogger.Error("%v GetForexSystemSetUp.HGetAll", common.ErrForex, err)
|
|
return nil, err
|
|
}
|
|
var systemModel structure.ForexSystem
|
|
for filed, value := range symbolMap {
|
|
switch filed {
|
|
case "face_value":
|
|
systemModel.FaceValue = decimal.RequireFromString("1")
|
|
case "max_pry":
|
|
systemModel.MaxPry = decimal.RequireFromString(value)
|
|
case "min_pry":
|
|
systemModel.MinPry = decimal.RequireFromString(value)
|
|
case "compel_num":
|
|
systemModel.CompelNum = decimal.RequireFromString(flags.SetOne).Sub(decimal.RequireFromString(value))
|
|
default:
|
|
}
|
|
}
|
|
|
|
return &systemModel, nil
|
|
}
|
|
|
|
// GetContractSystemSecond
|
|
//
|
|
// @Description: System settings for second contract orders
|
|
// @return map[int64]structure.ProportionSystem
|
|
// @return error
|
|
func GetContractSystemSecond() (map[int64]structure.ProportionSystem, error) {
|
|
symbolMap, err := Reds.Get(context.Background(), flags.ContractSystemSecond).Result()
|
|
if err != nil {
|
|
applogger.Error("%v GetContractSystemSecond.Get:%v", common.ErrSecond, err)
|
|
return nil, err
|
|
}
|
|
|
|
var statusTime []structure.ContractTimeSetting
|
|
if err = json.Unmarshal([]byte(symbolMap), &statusTime); err != nil {
|
|
applogger.Error("%v GetContractSystemSecond.Unmarshal:%v", common.ErrSecond, err)
|
|
return nil, err
|
|
}
|
|
|
|
systemModel := make(map[int64]structure.ProportionSystem)
|
|
for _, value := range statusTime {
|
|
if value.TimeStep == 0 {
|
|
continue
|
|
}
|
|
model := structure.ProportionSystem{
|
|
Value: strconv.Itoa(int(value.EarningsNum)),
|
|
}
|
|
systemModel[value.TimeStep] = model
|
|
}
|
|
|
|
return systemModel, nil
|
|
}
|
|
|
|
// GetKeepDecimal
|
|
//
|
|
// @Description: (合约|现货|股票)交易对保留小数
|
|
// @param steUpKey
|
|
// @param symbol
|
|
// @return int
|
|
func GetKeepDecimal(steUpKey, symbol string) int {
|
|
keySymbol := fmt.Sprintf("%v%v", steUpKey, symbol)
|
|
|
|
kDStr, err := Reds.HGet(context.Background(), keySymbol, "keep_decimal").Result()
|
|
if err != nil {
|
|
//applogger.Error("GetCacheKeepDecimal.HGetAll:%v", err)
|
|
return 0
|
|
}
|
|
|
|
keepDecimal, err := strconv.Atoi(kDStr)
|
|
if err != nil {
|
|
return 0
|
|
}
|
|
|
|
return keepDecimal
|
|
}
|
|
|
|
// GetStockName
|
|
//
|
|
// @Description:
|
|
// @param steUpKey
|
|
// @param symbol
|
|
// @return string
|
|
func GetStockName(steUpKey, symbol string) string {
|
|
keySymbol := fmt.Sprintf("%v%v", steUpKey, symbol)
|
|
|
|
sNStr, err := Reds.HGet(context.Background(), keySymbol, "stock_name").Result()
|
|
if err != nil {
|
|
applogger.Error("GetStockName.HGet:%v", err)
|
|
return symbol
|
|
}
|
|
|
|
return sNStr
|
|
}
|
|
|
|
// GetCacheForcedClosure
|
|
//
|
|
// @Description: Setting the Strong Leveling Threshold for Stock Trading
|
|
// @param steUpKey
|
|
// @param symbol
|
|
// @return decimal.Decimal
|
|
func GetCacheForcedClosure(steUpKey, symbol string) decimal.Decimal {
|
|
keySymbol := fmt.Sprintf("%v%v", steUpKey, symbol)
|
|
|
|
symbolMap, err := Reds.HGetAll(context.Background(), keySymbol).Result()
|
|
if err != nil {
|
|
applogger.Error("GetCacheForcedClosure.HGetAll:%v", err)
|
|
return decimal.RequireFromString(flags.ForcedClosure)
|
|
}
|
|
|
|
var forcedClosure decimal.Decimal
|
|
for filed, value := range symbolMap {
|
|
switch filed {
|
|
case "forced_closure":
|
|
forcedClosure = decimal.RequireFromString(flags.DecimalOne).Sub(decimal.RequireFromString(value))
|
|
default:
|
|
|
|
}
|
|
}
|
|
|
|
if forcedClosure.IsZero() {
|
|
return decimal.RequireFromString(flags.ForcedClosure)
|
|
}
|
|
|
|
return forcedClosure
|
|
}
|
|
|
|
// GetCacheNumericCode
|
|
//
|
|
// @Description:
|
|
// @param steUpKey
|
|
// @param symbol
|
|
// @return string
|
|
func GetCacheNumericCode(keys string) string {
|
|
symbolMap, err := Reds.HGetAll(context.Background(), keys).Result()
|
|
if err != nil {
|
|
applogger.Error("GetCacheNumericCode.HGetAll:%v", err)
|
|
return ""
|
|
}
|
|
|
|
var numericCode string
|
|
for filed, value := range symbolMap {
|
|
switch filed {
|
|
case "numeric_code":
|
|
numericCode = value
|
|
default:
|
|
|
|
}
|
|
}
|
|
|
|
return numericCode
|
|
}
|
|
|
|
// GetOptionInrForcedClosure
|
|
//
|
|
// @Description: 获取期权保证金比例
|
|
// @param steUpKey
|
|
// @param symbol
|
|
// @return decimal.Decimal
|
|
func GetOptionInrForcedClosure(steUpKey, symbol string) decimal.Decimal {
|
|
keySymbol := fmt.Sprintf("%v%v", steUpKey, symbol)
|
|
|
|
symbolMap, err := Reds.HGetAll(context.Background(), keySymbol).Result()
|
|
if err != nil {
|
|
applogger.Error("GetCacheForcedClosure.HGetAll:%v", err)
|
|
return decimal.RequireFromString(flags.ForcedRate)
|
|
}
|
|
|
|
var forcedClosure decimal.Decimal
|
|
for filed, value := range symbolMap {
|
|
switch filed {
|
|
case "rate":
|
|
forcedClosure = decimal.RequireFromString(flags.DecimalOne).Sub(decimal.RequireFromString(value))
|
|
default:
|
|
|
|
}
|
|
}
|
|
|
|
if forcedClosure.IsZero() {
|
|
return decimal.RequireFromString(flags.ForcedRate)
|
|
}
|
|
|
|
return forcedClosure
|
|
}
|
|
|
|
// GetCacheLimitOrDown
|
|
//
|
|
// @Description: Setting the limit up and down threshold for stock trading
|
|
// @param steUpKey
|
|
// @param symbol
|
|
// @return decimal.Decimal
|
|
func GetCacheLimitOrDown(steUpKey, symbol string) decimal.Decimal {
|
|
keySymbol := fmt.Sprintf("%v%v", steUpKey, symbol)
|
|
|
|
symbolMap, err := Reds.HGetAll(context.Background(), keySymbol).Result()
|
|
if err != nil {
|
|
applogger.Error("GetCacheForcedClosure.HGetAll:%v", err)
|
|
return decimal.RequireFromString(flags.LimitTen)
|
|
}
|
|
|
|
var limit decimal.Decimal
|
|
for filed, value := range symbolMap {
|
|
switch filed {
|
|
case "up_limit":
|
|
limit = decimal.RequireFromString(value)
|
|
case "down_limit":
|
|
limit = decimal.RequireFromString(value)
|
|
default:
|
|
limit = decimal.RequireFromString(flags.LimitTen)
|
|
}
|
|
}
|
|
|
|
return limit
|
|
}
|
|
|
|
// GetCacheStockMarketStatus
|
|
//
|
|
// @Description: 股市交易设置
|
|
// @param steUpKey
|
|
// @param symbol
|
|
// @return bool
|
|
func GetCacheStockMarketStatus(steUpKey, symbol string) bool {
|
|
keySymbol := fmt.Sprintf("%v%v", steUpKey, symbol)
|
|
|
|
symbolMap, err := Reds.HGetAll(context.Background(), keySymbol).Result()
|
|
if err != nil {
|
|
//applogger.Error("GetCacheKeepDecimal.HGetAll:%v", err)
|
|
return false
|
|
}
|
|
|
|
var status bool
|
|
for filed, value := range symbolMap {
|
|
switch filed {
|
|
case "status":
|
|
switch value {
|
|
case flags.SetOne: // 启用
|
|
status = false
|
|
case flags.SetTwo: // 禁用
|
|
status = true
|
|
default:
|
|
status = true
|
|
}
|
|
default:
|
|
|
|
}
|
|
}
|
|
|
|
return status
|
|
}
|
|
|
|
// GetCacheStockBlockStatus
|
|
//
|
|
// @Description: 大宗交易设置
|
|
// @param steUpKey
|
|
// @param symbol
|
|
// @return bool
|
|
func GetCacheStockBlockStatus(steUpKey, symbol string) (bool, string, int, time.Time) {
|
|
keySymbol := fmt.Sprintf("%v%v", steUpKey, symbol)
|
|
|
|
symbolMap, err := Reds.HGetAll(context.Background(), keySymbol).Result()
|
|
if err != nil {
|
|
//applogger.Error("GetCacheKeepDecimal.HGetAll:%v", err)
|
|
return false, "", 0, time.Now()
|
|
}
|
|
|
|
var status bool
|
|
var minNum, today int
|
|
var startTime, endTime, openPrice string
|
|
for filed, value := range symbolMap {
|
|
if len(value) == 0 {
|
|
continue
|
|
}
|
|
switch filed {
|
|
case "status":
|
|
switch value {
|
|
case flags.SetOne: // 启用
|
|
status = false
|
|
case flags.SetTwo: // 禁用
|
|
status = true
|
|
default:
|
|
status = true
|
|
}
|
|
case "min":
|
|
minNum, err = strconv.Atoi(value)
|
|
if err != nil {
|
|
minNum = 0
|
|
}
|
|
case "start_time":
|
|
startTime = value
|
|
case "end_time":
|
|
endTime = value
|
|
case "price":
|
|
openPrice = value
|
|
case "today_add":
|
|
today, err = strconv.Atoi(value)
|
|
if err != nil {
|
|
today = 0
|
|
}
|
|
default:
|
|
}
|
|
}
|
|
|
|
// 判定时间
|
|
if !utils.CheckTimeUTC(startTime, endTime) {
|
|
return true, "", 0, time.Now()
|
|
}
|
|
// 处理大宗交易开仓价格
|
|
if utils.ReplaceStr(openPrice) == "" {
|
|
openPrice = "0"
|
|
}
|
|
|
|
return status, openPrice, minNum, utils.TimeAddDayZero(today)
|
|
}
|
|
|
|
// GetCacheStockMarketStatusT
|
|
//
|
|
// @Description: 股票收盘交易设置
|
|
// @param steUpKey
|
|
// @param symbol
|
|
// @return int
|
|
func GetCacheStockMarketStatusT(steUpKey, symbol string) int {
|
|
keySymbol := fmt.Sprintf("%v%v", steUpKey, symbol)
|
|
|
|
symbolMap, err := Reds.HGetAll(context.Background(), keySymbol).Result()
|
|
if err != nil {
|
|
//applogger.Error("GetCacheKeepDecimal.HGetAll:%v", err)
|
|
return 0
|
|
}
|
|
|
|
var checkTime int
|
|
for filed, value := range symbolMap {
|
|
switch filed {
|
|
case "trade_day_type":
|
|
switch value {
|
|
case flags.CloseOne: // T+0
|
|
checkTime = 0
|
|
case flags.CloseTwo: // T+1
|
|
checkTime = 1
|
|
case flags.CloseThree: // T+2
|
|
checkTime = 2
|
|
case flags.CloseFour: // T+3
|
|
checkTime = 3
|
|
default:
|
|
checkTime = 0
|
|
}
|
|
default:
|
|
|
|
}
|
|
}
|
|
|
|
return checkTime
|
|
}
|
|
|
|
// GetCacheStockMarketLeverStatus
|
|
//
|
|
// @Description: 股票市场设置
|
|
// @param key
|
|
// @param code
|
|
// @return *structure.ShareSystem
|
|
func GetCacheStockMarketLeverStatus(key, code string) *structure.ShareSystem {
|
|
keySymbol := fmt.Sprintf("%v%v", key, code)
|
|
|
|
symbolMap, err := Reds.HGetAll(context.Background(), keySymbol).Result()
|
|
if err != nil {
|
|
//applogger.Error("GetCacheKeepDecimal.HGetAll:%v", err)
|
|
return nil
|
|
}
|
|
|
|
var shareSystem structure.ShareSystem
|
|
for filed, value := range symbolMap {
|
|
if len(utils.StrReplace(value)) == 0 {
|
|
continue
|
|
}
|
|
switch filed {
|
|
case "lever_status": // 杠杆状态
|
|
shareSystem.Status = decimal.RequireFromString(value)
|
|
case "stock_min": // 触发杠杆最小值
|
|
shareSystem.StockMin = decimal.RequireFromString(value)
|
|
case "lever_min": // 杠杆最小值
|
|
shareSystem.LevelMin = decimal.RequireFromString(value)
|
|
case "lever_max": // 杠杆最大值
|
|
shareSystem.LevelMax = decimal.RequireFromString(value)
|
|
default:
|
|
|
|
}
|
|
}
|
|
|
|
return &shareSystem
|
|
}
|
|
|
|
// SystemTimeGenerate
|
|
//
|
|
// @Description: Obtain individual stock system settings
|
|
// @param market
|
|
// @param share
|
|
// @param orderTime
|
|
// @return time.Time
|
|
func SystemTimeGenerate(market, share string, orderTime time.Time) time.Time {
|
|
to := GetCacheStockMarketStatusT(market, share)
|
|
timeNewAfterTwoDays := orderTime.AddDate(0, 0, to)
|
|
|
|
return timeNewAfterTwoDays
|
|
}
|
|
|
|
// SystemShareMarketLeverStatus
|
|
//
|
|
// @Description: Obtain stock market system settings
|
|
// @param market
|
|
// @param code
|
|
// @return structure.ShareSystem
|
|
func SystemShareMarketLeverStatus(market, code string, userId int64) *structure.ShareSystem {
|
|
shareLever := GetCacheStockMarketLeverStatus(market, code)
|
|
if shareLever == nil {
|
|
return &structure.ShareSystem{}
|
|
}
|
|
|
|
// Determine whether the user has activated the lever
|
|
cacheKey := fmt.Sprintf("%v%v", flags.StockTradePryNum, userId)
|
|
setV, err := Reds.Get(context.Background(), cacheKey).Result()
|
|
if err != nil || setV != flags.SetThree {
|
|
return &structure.ShareSystem{}
|
|
}
|
|
|
|
shareLever.UserStatus = setV
|
|
|
|
return shareLever
|
|
}
|
|
|
|
// SystemDealWithLever
|
|
//
|
|
// @Description: Handling leverage values
|
|
// @param order
|
|
// @return decimal.Decimal
|
|
func SystemDealWithLever(order structure.ShareOrder) decimal.Decimal {
|
|
// 杠杆设定缓存值
|
|
pryNum, err := Reds.Get(context.Background(), fmt.Sprintf("%v%v", flags.StockTradePryNumSet, order.UserId)).Result()
|
|
if err != nil {
|
|
pryNum, err = Reds.Get(context.Background(), fmt.Sprintf("%v%v", flags.StockTradePryNumSet, 0)).Result()
|
|
if err != nil {
|
|
pryNum = flags.SetOne
|
|
}
|
|
}
|
|
pryNumValue := decimal.RequireFromString(pryNum)
|
|
|
|
orderNumber := decimal.RequireFromString(order.OrderNumber)
|
|
switch order.System.Status.String() {
|
|
case flags.SetOne: // 开启
|
|
// 判定用户是否开启杠杆
|
|
if order.System.UserStatus != flags.SetThree {
|
|
return pryNumValue
|
|
}
|
|
|
|
// 判定是否达到最小面值
|
|
if orderNumber.IsZero() {
|
|
return pryNumValue
|
|
}
|
|
if orderNumber.Cmp(order.System.StockMin) < 0 {
|
|
return pryNumValue
|
|
}
|
|
|
|
// 判定杠杆范围
|
|
if len(utils.ReplaceStr(pryNum)) == 0 || !utils.IsNumberInt(pryNum) {
|
|
return pryNumValue
|
|
}
|
|
if pryNumValue.Cmp(order.System.LevelMin) < 0 || pryNumValue.Cmp(order.System.LevelMax) > 0 {
|
|
return pryNumValue
|
|
}
|
|
}
|
|
|
|
return pryNumValue
|
|
}
|
|
|
|
// CheckShareSystemTime
|
|
//
|
|
// @Description: Check if the stock system setting time requires closing positions
|
|
// @param timeStr
|
|
// @return bool
|
|
func CheckShareSystemTime(timeStr time.Time) bool {
|
|
timeNew := time.Now().Format(flags.TimeFormat)
|
|
timeOld := timeStr.Format(flags.TimeFormat)
|
|
|
|
if timeNew >= timeOld {
|
|
return true
|
|
} else {
|
|
return false
|
|
}
|
|
}
|
|
|
|
// GetStrongFlatteningThreshold
|
|
//
|
|
// @Description: Determine whether there is a strong balance
|
|
// @return bool
|
|
func GetStrongFlatteningThreshold(userId int64) bool {
|
|
keys := fmt.Sprintf("%v%v", flags.StockTradePryNum, strconv.Itoa(int(userId)))
|
|
setV, err := Reds.Get(context.Background(), keys).Result()
|
|
if err != nil {
|
|
return false
|
|
}
|
|
|
|
if setV == flags.SetThree {
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
// CheckTypeStatus
|
|
//
|
|
// @Description: 大宗交易判定
|
|
// @param status
|
|
// @return bool
|
|
func CheckTypeStatus(status int64) bool {
|
|
if status <= 0 {
|
|
return false
|
|
} else {
|
|
return true
|
|
}
|
|
}
|
|
|
|
// PryNumInit
|
|
//
|
|
// @Description: 杠杆初始化
|
|
// @param order
|
|
// @return structure.ShareOrder
|
|
func PryNumInit(order structure.ShareOrder) structure.ShareOrder {
|
|
if len(utils.ReplaceStr(order.PryNum)) == 0 || order.PryNum == flags.SetZero {
|
|
order.PryNum = flags.SetOne
|
|
}
|
|
return order
|
|
}
|
|
|
|
// GetBotUserArrears
|
|
//
|
|
// @Description:
|
|
// @param ctx
|
|
// @param userId
|
|
// @return map[string]string
|
|
// @return error
|
|
func GetBotUserArrears(ctx context.Context) (map[int64]int64, error) {
|
|
var botInr []models.BotUserArrears
|
|
if err := Msql.Table(flags.BotUserArrears).
|
|
Distinct("user_id").
|
|
Where("status = 0").
|
|
Find(&botInr); err != nil {
|
|
applogger.Error("GetBotUserArrears Find:%v", err)
|
|
return nil, err
|
|
}
|
|
|
|
inrMap := make(map[int64]int64, 0)
|
|
for _, value := range botInr {
|
|
inrMap[int64(value.UserId)] = int64(value.UserId)
|
|
}
|
|
|
|
return inrMap, nil
|
|
}
|
|
|
|
// QuerySystemCache
|
|
//
|
|
// @Description: 系统配置开闭盘时间
|
|
// @return amOpenTime
|
|
// @return pmOpenTime
|
|
// @return amCloseTime
|
|
// @return pmCloseTime
|
|
func QuerySystemCache(marketType int) (timeValue flags.TimeValue) {
|
|
// 判定开闭盘时间
|
|
usMarkerCacheKey := fmt.Sprintf("%v%v", flags.StockMarketList, marketType)
|
|
symbol, err := Reds.HGetAll(context.Background(), usMarkerCacheKey).Result()
|
|
if err != nil {
|
|
applogger.Error("InitShareUsCloseNewPrice.HGetAll:%v", err)
|
|
return
|
|
}
|
|
var amOpenTime, amCloseTime, pmOpenTime, pmCloseTime time.Time
|
|
for filed, value := range symbol {
|
|
switch filed {
|
|
case "am_open_time":
|
|
amOpenTime, _ = time.Parse(flags.LayoutOne, value)
|
|
case "am_close_time":
|
|
amCloseTime, _ = time.Parse(flags.LayoutOne, value)
|
|
case "pm_open_time":
|
|
pmOpenTime, _ = time.Parse(flags.LayoutOne, value)
|
|
case "pm_close_time":
|
|
pmCloseTime, _ = time.Parse(flags.LayoutOne, value)
|
|
default:
|
|
}
|
|
}
|
|
|
|
return flags.TimeValue{
|
|
AmOpenTime: amOpenTime,
|
|
AmCloseTime: amCloseTime,
|
|
PmOpenTime: pmOpenTime,
|
|
PmCloseTime: pmCloseTime,
|
|
}
|
|
}
|
|
|
|
// MarketCheckOpenAndCloseTime
|
|
//
|
|
// @Description: 市场真实开闭盘时间
|
|
// @param marketType
|
|
// @return amOpenTime
|
|
// @return pmOpenTime
|
|
// @return amCloseTime
|
|
// @return pmCloseTime
|
|
func MarketCheckOpenAndCloseTime(marketType int) (timeValue flags.TimeValue, checkWeekday bool) {
|
|
var week int
|
|
var weekDayCheck bool
|
|
var weekday = time.Now().Weekday()
|
|
switch weekday {
|
|
case time.Monday: // 星期一
|
|
week = 1
|
|
weekDayCheck = true
|
|
case time.Tuesday: // 星期二
|
|
week = 2
|
|
weekDayCheck = true
|
|
case time.Wednesday: // 星期三
|
|
week = 3
|
|
weekDayCheck = true
|
|
case time.Thursday: // 星期四
|
|
week = 4
|
|
weekDayCheck = true
|
|
case time.Friday: // 星期五
|
|
week = 5
|
|
weekDayCheck = true
|
|
default: // 星期六|星期天|未知星期
|
|
//return timeValue, weekDayCheck
|
|
weekDayCheck = true
|
|
}
|
|
|
|
switch marketType {
|
|
case flags.ShareIdnMarketType: // 印尼
|
|
if week != 5 {
|
|
// 类型4: (周一到周四) 10:00 - 13:00(上午盘) 14:30 - 17:10(下午盘)
|
|
timeValue = TimeResult(marketType)
|
|
} else {
|
|
// 类型40: (周五) 10:00 - 12:30(上午盘) 15:00 - 17:10(下午盘)
|
|
timeValue = TimeResult(40)
|
|
}
|
|
default:
|
|
timeValue = TimeResult(marketType)
|
|
}
|
|
|
|
return timeValue, weekDayCheck
|
|
}
|
|
|
|
// TimeResult
|
|
//
|
|
// @Description:
|
|
// @param marketType
|
|
// @return amOpenTime
|
|
// @return pmOpenTime
|
|
// @return amCloseTime
|
|
// @return pmCloseTime
|
|
func TimeResult(marketType int) flags.TimeValue {
|
|
amOpenTime, _ := time.Parse(flags.LayoutOne, flags.TimeMapType[marketType].AmOpenTime)
|
|
amCloseTime, _ := time.Parse(flags.LayoutOne, flags.TimeMapType[marketType].AmCloseTime)
|
|
pmOpenTime, _ := time.Parse(flags.LayoutOne, flags.TimeMapType[marketType].PmOpenTime)
|
|
pmCloseTime, _ := time.Parse(flags.LayoutOne, flags.TimeMapType[marketType].PmCloseTime)
|
|
|
|
return flags.TimeValue{AmOpenTime: amOpenTime, AmCloseTime: amCloseTime, PmOpenTime: pmOpenTime, PmCloseTime: pmCloseTime}
|
|
}
|
|
|