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.
4588 lines
120 KiB
4588 lines
120 KiB
2 months ago
|
package convert
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"fmt"
|
||
|
"github.com/shopspring/decimal"
|
||
|
"matchmaking-system/internal/biz/structure"
|
||
|
"matchmaking-system/internal/pkg/flags"
|
||
|
"math/rand"
|
||
|
"strconv"
|
||
|
"time"
|
||
|
|
||
|
models "matchmaking-system/internal/pkg/model"
|
||
|
)
|
||
|
|
||
|
// CreateRandCodeOrder
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param n
|
||
|
// @return string
|
||
|
func CreateRandCodeOrder(n int) string {
|
||
|
timestamp := time.Now().UnixNano() / 1000000 // 毫秒级时间戳
|
||
|
|
||
|
code := flags.SetNull
|
||
|
for i := 0; i < n; i++ {
|
||
|
code = fmt.Sprintf("%s%d", code, rand.Intn(10))
|
||
|
}
|
||
|
|
||
|
return fmt.Sprintf("%d%s", timestamp, code)
|
||
|
}
|
||
|
|
||
|
// BotStockTrade
|
||
|
//
|
||
|
// @Description: (美股下单|美股设置止损止盈|美股撤单|美股平仓)
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param orderId
|
||
|
// @param order
|
||
|
// @return models.BotStockTrade
|
||
|
func BotStockTrade(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockTrade {
|
||
|
marketPrice := decimal.RequireFromString(order.MarketMoney)
|
||
|
cost := decimal.RequireFromString(order.ServiceCost)
|
||
|
pryNum, err := strconv.Atoi(order.PryNum)
|
||
|
if err != nil {
|
||
|
pryNum = 1
|
||
|
}
|
||
|
|
||
|
var lp, mp string
|
||
|
switch order.DealType {
|
||
|
case flags.DealTypeLimited: // 限价
|
||
|
if len(order.LimitPrice) != 0 {
|
||
|
lp = order.LimitPrice
|
||
|
mp = order.LimitPrice
|
||
|
}
|
||
|
case flags.DealTypeMarket: // 市价
|
||
|
if len(order.MarketPrice) != 0 {
|
||
|
lp = order.MarketPrice
|
||
|
mp = order.MarketPrice
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if order.StopWinPrice == flags.SetNull {
|
||
|
order.StopWinPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.StopLossPrice == flags.SetNull {
|
||
|
order.StopLossPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.LimitPrice == flags.SetNull {
|
||
|
order.LimitPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.MarketPrice == flags.SetNull {
|
||
|
order.MarketPrice = decimal.Zero.String()
|
||
|
}
|
||
|
|
||
|
// total order Money
|
||
|
orderMoney := marketPrice.Add(cost)
|
||
|
|
||
|
return models.BotStockTrade{
|
||
|
UserId: int(userId),
|
||
|
TradeType: int(order.TradeType),
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StockId: order.StockId,
|
||
|
Status: flags.EntrustStatus,
|
||
|
ServiceCost: order.ServiceCost,
|
||
|
OrderNumber: order.OrderNumber,
|
||
|
OrderMoney: orderMoney.String(),
|
||
|
OrderId: orderId,
|
||
|
MarketMoney: order.MarketMoney,
|
||
|
LimitPrice: lp,
|
||
|
MarketPrice: mp,
|
||
|
DealType: int(order.DealType),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
ClosingCost: decimal.Zero.String(),
|
||
|
OvernightCost: decimal.Zero.String(),
|
||
|
ClosingPrice: decimal.Zero.String(),
|
||
|
DealPrice: decimal.Zero.String(),
|
||
|
PryNum: pryNum,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockBlockTrade
|
||
|
//
|
||
|
// @Description: 大宗(美股|马股|泰股|印尼股|印度股|新加坡股|港股)交易订单表
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param orderId
|
||
|
// @param order
|
||
|
// @return models.BotStockBlockTrade
|
||
|
func BotStockBlockTrade(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockBlockTrade {
|
||
|
marketPrice := decimal.RequireFromString(order.MarketMoney)
|
||
|
cost := decimal.RequireFromString(order.ServiceCost)
|
||
|
pryNum, err := strconv.Atoi(order.PryNum)
|
||
|
if err != nil {
|
||
|
pryNum = 1
|
||
|
}
|
||
|
|
||
|
var lp, mp string
|
||
|
switch order.DealType {
|
||
|
case flags.DealTypeLimited: // 限价
|
||
|
if len(order.LimitPrice) != 0 {
|
||
|
lp = order.LimitPrice
|
||
|
mp = order.LimitPrice
|
||
|
}
|
||
|
case flags.DealTypeMarket: // 市价
|
||
|
if len(order.MarketPrice) != 0 {
|
||
|
lp = order.MarketPrice
|
||
|
mp = order.MarketPrice
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if order.StopWinPrice == flags.SetNull {
|
||
|
order.StopWinPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.StopLossPrice == flags.SetNull {
|
||
|
order.StopLossPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.LimitPrice == flags.SetNull {
|
||
|
order.LimitPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.MarketPrice == flags.SetNull {
|
||
|
order.MarketPrice = decimal.Zero.String()
|
||
|
}
|
||
|
|
||
|
// total order Money
|
||
|
orderMoney := marketPrice.Add(cost)
|
||
|
|
||
|
return models.BotStockBlockTrade{
|
||
|
UserId: int(userId),
|
||
|
TradeType: int(order.TradeType),
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StockId: order.StockId,
|
||
|
Status: flags.EntrustStatus,
|
||
|
ServiceCost: order.ServiceCost,
|
||
|
OrderNumber: order.OrderNumber,
|
||
|
OrderMoney: orderMoney.String(),
|
||
|
OrderId: orderId,
|
||
|
MarketMoney: order.MarketMoney,
|
||
|
LimitPrice: lp,
|
||
|
MarketPrice: mp,
|
||
|
DealType: int(order.DealType),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
ClosingCost: decimal.Zero.String(),
|
||
|
OvernightCost: decimal.Zero.String(),
|
||
|
ClosingPrice: decimal.Zero.String(),
|
||
|
DealPrice: decimal.Zero.String(),
|
||
|
PryNum: pryNum,
|
||
|
Type: int(order.Type),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockHkdTrade
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param orderId
|
||
|
// @param order
|
||
|
// @return models.BotStockTrade
|
||
|
func BotStockHkdTrade(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockHkdTrade {
|
||
|
marketPrice := decimal.RequireFromString(order.MarketMoney)
|
||
|
cost := decimal.RequireFromString(order.ServiceCost)
|
||
|
pryNum, err := strconv.Atoi(order.PryNum)
|
||
|
if err != nil {
|
||
|
pryNum = 1
|
||
|
}
|
||
|
|
||
|
var lp, mp string
|
||
|
switch order.DealType {
|
||
|
case flags.DealTypeLimited: // 限价
|
||
|
if len(order.LimitPrice) != 0 {
|
||
|
lp = order.LimitPrice
|
||
|
mp = order.LimitPrice
|
||
|
}
|
||
|
case flags.DealTypeMarket: // 市价
|
||
|
if len(order.MarketPrice) != 0 {
|
||
|
lp = order.MarketPrice
|
||
|
mp = order.MarketPrice
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if order.StopWinPrice == flags.SetNull {
|
||
|
order.StopWinPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.StopLossPrice == flags.SetNull {
|
||
|
order.StopLossPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.LimitPrice == flags.SetNull {
|
||
|
order.LimitPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.MarketPrice == flags.SetNull {
|
||
|
order.MarketPrice = decimal.Zero.String()
|
||
|
}
|
||
|
|
||
|
// total order Money
|
||
|
orderMoney := marketPrice.Add(cost)
|
||
|
|
||
|
return models.BotStockHkdTrade{
|
||
|
UserId: int(userId),
|
||
|
TradeType: int(order.TradeType),
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StockId: order.StockId,
|
||
|
Status: flags.EntrustStatus,
|
||
|
ServiceCost: order.ServiceCost,
|
||
|
OrderNumber: order.OrderNumber,
|
||
|
OrderMoney: orderMoney.String(),
|
||
|
OrderId: orderId,
|
||
|
MarketMoney: order.MarketMoney,
|
||
|
LimitPrice: lp,
|
||
|
MarketPrice: mp,
|
||
|
DealType: int(order.DealType),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
ClosingCost: decimal.Zero.String(),
|
||
|
OvernightCost: decimal.Zero.String(),
|
||
|
ClosingPrice: decimal.Zero.String(),
|
||
|
DealPrice: decimal.Zero.String(),
|
||
|
PryNum: pryNum,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockStopByOrderId
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param order
|
||
|
// @return models.BotStockTrade
|
||
|
func BotStockStopByOrderId(ctx context.Context, order structure.StopOrder) models.BotStockTrade {
|
||
|
return models.BotStockTrade{
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockBlockStopByOrderId
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param order
|
||
|
// @return models.BotStockBlockTrade
|
||
|
func BotStockBlockStopByOrderId(ctx context.Context, order structure.StopOrder) models.BotStockBlockTrade {
|
||
|
return models.BotStockBlockTrade{
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockStopHkdByOrderId
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param order
|
||
|
// @return models.BotStockHkdTrade
|
||
|
func BotStockStopHkdByOrderId(ctx context.Context, order structure.StopOrder) models.BotStockHkdTrade {
|
||
|
return models.BotStockHkdTrade{
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockCancelByOrderId
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @return models.BotStockTrade
|
||
|
func BotStockCancelByOrderId(ctx context.Context) models.BotStockTrade {
|
||
|
return models.BotStockTrade{
|
||
|
Status: flags.CancelStatus,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockBlockCancelByOrderId
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @return models.BotStockBlockTrade
|
||
|
func BotStockBlockCancelByOrderId(ctx context.Context) models.BotStockBlockTrade {
|
||
|
return models.BotStockBlockTrade{
|
||
|
Status: flags.CancelStatus,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockHkdCancelByOrderId
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @return models.BotStockHkdTrade
|
||
|
func BotStockHkdCancelByOrderId(ctx context.Context) models.BotStockHkdTrade {
|
||
|
return models.BotStockHkdTrade{
|
||
|
Status: flags.CancelStatus,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateBotUserStock
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStock
|
||
|
func UpdateBotUserStock(ctx context.Context, usableNum, frozenNum string) models.BotUserStock {
|
||
|
return models.BotUserStock{
|
||
|
UpdateTime: time.Now(),
|
||
|
FrozenNum: frozenNum,
|
||
|
UsableNum: usableNum,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateBotUserStockHkd
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockHkd
|
||
|
func UpdateBotUserStockHkd(ctx context.Context, usableNum, frozenNum string) models.BotUserStockHkd {
|
||
|
return models.BotUserStockHkd{
|
||
|
UpdateTime: time.Now(),
|
||
|
FrozenNum: frozenNum,
|
||
|
UsableNum: usableNum,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreateBotUserStock
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param stockId
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStock
|
||
|
func CreateBotUserStock(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStock {
|
||
|
return models.BotUserStock{
|
||
|
UserId: int(userId),
|
||
|
StockId: stockId,
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreateBotUserStockHkd
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param stockId
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockHkd
|
||
|
func CreateBotUserStockHkd(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockHkd {
|
||
|
return models.BotUserStockHkd{
|
||
|
UserId: int(userId),
|
||
|
StockId: stockId,
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateOpenBotStockTrade
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param price
|
||
|
// @param orderNumber
|
||
|
// @param totalMoney
|
||
|
// @param serviceCost
|
||
|
// @return models.BotStockTrade
|
||
|
func UpdateOpenBotStockTrade(ctx context.Context, price, orderNumber, totalMoney, serviceCost, marketMoney string) models.BotStockTrade {
|
||
|
return models.BotStockTrade{
|
||
|
OpenTime: time.Now(),
|
||
|
DealPrice: price,
|
||
|
ServiceCost: serviceCost,
|
||
|
OrderNumber: orderNumber,
|
||
|
OrderMoney: totalMoney,
|
||
|
MarketMoney: marketMoney,
|
||
|
Status: flags.PositionStatus,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateOpenBotStockBlockTrade
|
||
|
//
|
||
|
// @Description: 大宗(美股)交易
|
||
|
// @param ctx
|
||
|
// @param price
|
||
|
// @param orderNumber
|
||
|
// @param totalMoney
|
||
|
// @param serviceCost
|
||
|
// @param marketMoney
|
||
|
// @return models.BotStockBlockTrade
|
||
|
func UpdateOpenBotStockBlockTrade(ctx context.Context, price, orderNumber, totalMoney, serviceCost, marketMoney string) models.BotStockBlockTrade {
|
||
|
return models.BotStockBlockTrade{
|
||
|
OpenTime: time.Now(),
|
||
|
DealPrice: price,
|
||
|
ServiceCost: serviceCost,
|
||
|
OrderNumber: orderNumber,
|
||
|
OrderMoney: totalMoney,
|
||
|
MarketMoney: marketMoney,
|
||
|
Status: flags.PositionStatus,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateOpenBotStockHkdTrade
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param price
|
||
|
// @param orderNumber
|
||
|
// @param totalMoney
|
||
|
// @param serviceCost
|
||
|
// @param marketMoney
|
||
|
// @return models.BotStockHkdTrade
|
||
|
func UpdateOpenBotStockHkdTrade(ctx context.Context, price, orderNumber, totalMoney, serviceCost, marketMoney string) models.BotStockHkdTrade {
|
||
|
return models.BotStockHkdTrade{
|
||
|
OpenTime: time.Now(),
|
||
|
DealPrice: price,
|
||
|
ServiceCost: serviceCost,
|
||
|
OrderNumber: orderNumber,
|
||
|
OrderMoney: totalMoney,
|
||
|
MarketMoney: marketMoney,
|
||
|
Status: flags.PositionStatus,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateCloseBotStockTrade
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param price
|
||
|
// @param totalMoney
|
||
|
// @param serviceCost
|
||
|
// @return models.BotStockTrade
|
||
|
func UpdateCloseBotStockTrade(ctx context.Context, price, serviceCost string) models.BotStockTrade {
|
||
|
return models.BotStockTrade{
|
||
|
ClosingTime: time.Now(),
|
||
|
ClosingPrice: price,
|
||
|
ClosingCost: serviceCost,
|
||
|
Status: flags.CloseStatus,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateCloseBotStockBlockTrade
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param price
|
||
|
// @param serviceCost
|
||
|
// @return models.BotStockBlockTrade
|
||
|
func UpdateCloseBotStockBlockTrade(ctx context.Context, price, serviceCost string) models.BotStockBlockTrade {
|
||
|
return models.BotStockBlockTrade{
|
||
|
ClosingTime: time.Now(),
|
||
|
ClosingPrice: price,
|
||
|
ClosingCost: serviceCost,
|
||
|
Status: flags.CloseStatus,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateCloseBotStockHkdTrade
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param price
|
||
|
// @param serviceCost
|
||
|
// @return models.BotStockHkdTrade
|
||
|
func UpdateCloseBotStockHkdTrade(ctx context.Context, price, serviceCost string) models.BotStockHkdTrade {
|
||
|
return models.BotStockHkdTrade{
|
||
|
ClosingTime: time.Now(),
|
||
|
ClosingPrice: price,
|
||
|
ClosingCost: serviceCost,
|
||
|
Status: flags.CloseStatus,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreatBotUserStockLog
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param code
|
||
|
// @param symbol
|
||
|
// @param changeNum
|
||
|
// @param orderId
|
||
|
// @return models.BotUserStockLog
|
||
|
func CreatBotUserStockLog(ctx context.Context, userId, code int64, symbol, changeNum, orderId string) models.BotUserStockLog {
|
||
|
return models.BotUserStockLog{
|
||
|
OrderId: orderId,
|
||
|
UserId: int(userId),
|
||
|
ChangeNum: changeNum,
|
||
|
ChangeType: int(code),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
StockId: symbol,
|
||
|
BeforeNum: decimal.Zero.String(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreatBotUserStockBlockLog
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param code
|
||
|
// @param symbol
|
||
|
// @param changeNum
|
||
|
// @param orderId
|
||
|
// @param typeStatus
|
||
|
// @return models.BotUserStockBlockLog
|
||
|
func CreatBotUserStockBlockLog(ctx context.Context, userId, code int64, symbol, changeNum, orderId string, typeStatus int64) models.BotUserStockBlockLog {
|
||
|
return models.BotUserStockBlockLog{
|
||
|
OrderId: orderId,
|
||
|
UserId: int(userId),
|
||
|
ChangeNum: changeNum,
|
||
|
ChangeType: int(code),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
StockId: symbol,
|
||
|
BeforeNum: decimal.Zero.String(),
|
||
|
Type: int(typeStatus),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreatBotUserStockHkdLog
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param code
|
||
|
// @param symbol
|
||
|
// @param changeNum
|
||
|
// @param orderId
|
||
|
// @return models.BotUserStockHkdLog
|
||
|
func CreatBotUserStockHkdLog(ctx context.Context, userId, code int64, symbol, changeNum, orderId string) models.BotUserStockHkdLog {
|
||
|
return models.BotUserStockHkdLog{
|
||
|
OrderId: orderId,
|
||
|
UserId: int(userId),
|
||
|
ChangeNum: changeNum,
|
||
|
ChangeType: int(code),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
StockId: symbol,
|
||
|
BeforeNum: decimal.Zero.String(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockTradePre
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param orderId
|
||
|
// @param order
|
||
|
// @return models.BotStockTrade
|
||
|
func BotStockTradePre(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockTrade {
|
||
|
if order.StopWinPrice == flags.SetNull {
|
||
|
order.StopWinPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.StopLossPrice == flags.SetNull {
|
||
|
order.StopLossPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.MarketPrice == flags.SetNull {
|
||
|
order.MarketPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.LimitPrice == flags.SetNull {
|
||
|
order.LimitPrice = decimal.Zero.String()
|
||
|
}
|
||
|
|
||
|
return models.BotStockTrade{
|
||
|
UserId: int(userId),
|
||
|
TradeType: int(order.TradeType),
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StockId: order.StockId,
|
||
|
ServiceCost: order.ServiceCost,
|
||
|
MarketPrice: order.MarketPrice,
|
||
|
MarketMoney: order.MarketMoney,
|
||
|
LimitPrice: order.LimitPrice,
|
||
|
DealType: int(order.DealType),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
OrderId: orderId,
|
||
|
Status: flags.PositionStatus,
|
||
|
OpenTime: time.Now(),
|
||
|
DealPrice: order.LimitPrice,
|
||
|
OrderNumber: order.OrderNumber,
|
||
|
OrderMoney: order.MarketMoney,
|
||
|
ClosingPrice: decimal.Zero.String(),
|
||
|
ClosingCost: decimal.Zero.String(),
|
||
|
OvernightCost: decimal.Zero.String(),
|
||
|
PryNum: flags.SetPreOne,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreatBotUserStockPre
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param stockId
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStock
|
||
|
func CreatBotUserStockPre(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStock {
|
||
|
return models.BotUserStock{
|
||
|
UserId: int(userId),
|
||
|
StockId: stockId,
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreatBotUserStockIdnPre
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param stockId
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStock
|
||
|
func CreatBotUserStockIdnPre(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockIdn {
|
||
|
return models.BotUserStockIdn{
|
||
|
UserId: int(userId),
|
||
|
StockId: stockId,
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreatBotUserStockMysPre
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param stockId
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockMys
|
||
|
func CreatBotUserStockMysPre(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockMys {
|
||
|
return models.BotUserStockMys{
|
||
|
UserId: int(userId),
|
||
|
StockId: stockId,
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreatBotUserStockThaPre
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param stockId
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockTha
|
||
|
func CreatBotUserStockThaPre(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockTha {
|
||
|
return models.BotUserStockTha{
|
||
|
UserId: int(userId),
|
||
|
StockId: stockId,
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreatBotUserStockInPre
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param stockId
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockIn
|
||
|
func CreatBotUserStockInPre(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockIn {
|
||
|
return models.BotUserStockIn{
|
||
|
UserId: int(userId),
|
||
|
StockId: stockId,
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreatBotUserStockSgdPre
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param stockId
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockSgd
|
||
|
func CreatBotUserStockSgdPre(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockSgd {
|
||
|
return models.BotUserStockSgd{
|
||
|
UserId: int(userId),
|
||
|
StockId: stockId,
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreatBotUserStockGbxPre
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param stockId
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockGbx
|
||
|
func CreatBotUserStockGbxPre(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockGbx {
|
||
|
return models.BotUserStockGbx{
|
||
|
UserId: int(userId),
|
||
|
StockId: stockId,
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreatBotUserStockEurPre
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param stockId
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockEur
|
||
|
func CreatBotUserStockEurPre(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockEur {
|
||
|
return models.BotUserStockEur{
|
||
|
UserId: int(userId),
|
||
|
StockId: stockId,
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreatBotUserStockBrlPre
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param stockId
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockBrl
|
||
|
func CreatBotUserStockBrlPre(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockBrl {
|
||
|
return models.BotUserStockBrl{
|
||
|
UserId: int(userId),
|
||
|
StockId: stockId,
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreatBotUserStockFurPre
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param stockId
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockFur
|
||
|
func CreatBotUserStockFurPre(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockFur {
|
||
|
return models.BotUserStockFur{
|
||
|
UserId: int(userId),
|
||
|
StockId: stockId,
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreatBotUserStockJpyPre
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param stockId
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockJp
|
||
|
func CreatBotUserStockJpyPre(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockJp {
|
||
|
return models.BotUserStockJp{
|
||
|
UserId: int(userId),
|
||
|
StockId: stockId,
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreatBotUserStockHkdPre
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param stockId
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockHkd
|
||
|
func CreatBotUserStockHkdPre(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockHkd {
|
||
|
return models.BotUserStockHkd{
|
||
|
UserId: int(userId),
|
||
|
StockId: stockId,
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateBotUserStockPre
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStock
|
||
|
func UpdateBotUserStockPre(ctx context.Context, usableNum, frozenNum string) models.BotUserStock {
|
||
|
return models.BotUserStock{
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateBotUserStockIdnPre
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockIdn
|
||
|
func UpdateBotUserStockIdnPre(ctx context.Context, usableNum, frozenNum string) models.BotUserStockIdn {
|
||
|
return models.BotUserStockIdn{
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateBotUserStockMysPre
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockMys
|
||
|
func UpdateBotUserStockMysPre(ctx context.Context, usableNum, frozenNum string) models.BotUserStockMys {
|
||
|
return models.BotUserStockMys{
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateBotUserStockThaPre
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockTha
|
||
|
func UpdateBotUserStockThaPre(ctx context.Context, usableNum, frozenNum string) models.BotUserStockTha {
|
||
|
return models.BotUserStockTha{
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateBotUserStockInPre
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockIn
|
||
|
func UpdateBotUserStockInPre(ctx context.Context, usableNum, frozenNum string) models.BotUserStockIn {
|
||
|
return models.BotUserStockIn{
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateBotUserStockSgdPre
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockSgd
|
||
|
func UpdateBotUserStockSgdPre(ctx context.Context, usableNum, frozenNum string) models.BotUserStockSgd {
|
||
|
return models.BotUserStockSgd{
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateBotUserStockGbxPre
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockGbx
|
||
|
func UpdateBotUserStockGbxPre(ctx context.Context, usableNum, frozenNum string) models.BotUserStockGbx {
|
||
|
return models.BotUserStockGbx{
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateBotUserStockEurPre
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockEur
|
||
|
func UpdateBotUserStockEurPre(ctx context.Context, usableNum, frozenNum string) models.BotUserStockEur {
|
||
|
return models.BotUserStockEur{
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateBotUserStockBrlPre
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockBrl
|
||
|
func UpdateBotUserStockBrlPre(ctx context.Context, usableNum, frozenNum string) models.BotUserStockBrl {
|
||
|
return models.BotUserStockBrl{
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateBotUserStockFurPre
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockFur
|
||
|
func UpdateBotUserStockFurPre(ctx context.Context, usableNum, frozenNum string) models.BotUserStockFur {
|
||
|
return models.BotUserStockFur{
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateBotUserStockJpyPre
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockJp
|
||
|
func UpdateBotUserStockJpyPre(ctx context.Context, usableNum, frozenNum string) models.BotUserStockJp {
|
||
|
return models.BotUserStockJp{
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateBotUserStockHkdPre
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockHkd
|
||
|
func UpdateBotUserStockHkdPre(ctx context.Context, usableNum, frozenNum string) models.BotUserStockHkd {
|
||
|
return models.BotUserStockHkd{
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockIdnTrade
|
||
|
//
|
||
|
// @Description: (印尼股下单|印尼股设置止损止盈|印尼股撤单|印尼股平仓)
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param orderId
|
||
|
// @param order
|
||
|
// @return models.BotStockIdnTrade
|
||
|
func BotStockIdnTrade(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockIdnTrade {
|
||
|
marketPrice := decimal.RequireFromString(order.MarketMoney)
|
||
|
cost := decimal.RequireFromString(order.ServiceCost)
|
||
|
// total order Money
|
||
|
orderMoney := marketPrice.Add(cost)
|
||
|
pryNum, err := strconv.Atoi(order.PryNum)
|
||
|
if err != nil {
|
||
|
pryNum = 0
|
||
|
}
|
||
|
|
||
|
var lp, mp string
|
||
|
switch order.DealType {
|
||
|
case flags.DealTypeLimited: // 限价
|
||
|
if len(order.LimitPrice) != 0 {
|
||
|
lp = order.LimitPrice
|
||
|
mp = order.LimitPrice
|
||
|
}
|
||
|
case flags.DealTypeMarket: // 市价
|
||
|
if len(order.MarketPrice) != 0 {
|
||
|
lp = order.MarketPrice
|
||
|
mp = order.MarketPrice
|
||
|
}
|
||
|
}
|
||
|
if order.StopLossPrice == flags.SetNull {
|
||
|
order.StopLossPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.StopWinPrice == flags.SetNull {
|
||
|
order.StopWinPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.LimitPrice == flags.SetNull {
|
||
|
order.LimitPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.MarketPrice == flags.SetNull {
|
||
|
order.MarketPrice = decimal.Zero.String()
|
||
|
}
|
||
|
return models.BotStockIdnTrade{
|
||
|
UserId: int(userId),
|
||
|
TradeType: int(order.TradeType),
|
||
|
StopType: int(order.StopType),
|
||
|
StockId: order.StockId,
|
||
|
Status: flags.EntrustStatus,
|
||
|
ServiceCost: order.ServiceCost,
|
||
|
OrderNumber: order.OrderNumber,
|
||
|
OrderMoney: orderMoney.String(),
|
||
|
OrderId: orderId,
|
||
|
MarketMoney: order.MarketMoney,
|
||
|
LimitPrice: lp,
|
||
|
MarketPrice: mp,
|
||
|
DealType: int(order.DealType),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
ClosingCost: decimal.Zero.String(),
|
||
|
OvernightCost: decimal.Zero.String(),
|
||
|
DealPrice: decimal.Zero.String(),
|
||
|
ClosingPrice: decimal.Zero.String(),
|
||
|
PryNum: pryNum,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockInrTrade
|
||
|
//
|
||
|
// @Description: (印度股下单|印度股设置止损止盈|印度股撤单|印度股平仓)
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param orderId
|
||
|
// @param order
|
||
|
// @return models.BotStockInTrade
|
||
|
func BotStockInrTrade(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockInTrade {
|
||
|
marketPrice := decimal.RequireFromString(order.MarketMoney)
|
||
|
cost := decimal.RequireFromString(order.ServiceCost)
|
||
|
// total order Money
|
||
|
orderMoney := marketPrice.Add(cost)
|
||
|
pryNum, err := strconv.Atoi(order.PryNum)
|
||
|
if err != nil {
|
||
|
pryNum = 1
|
||
|
}
|
||
|
|
||
|
var lp, mp string
|
||
|
switch order.DealType {
|
||
|
case flags.DealTypeLimited: // 限价
|
||
|
if len(order.LimitPrice) != 0 {
|
||
|
lp = order.LimitPrice
|
||
|
mp = order.LimitPrice
|
||
|
}
|
||
|
case flags.DealTypeMarket: // 市价
|
||
|
if len(order.MarketPrice) != 0 {
|
||
|
lp = order.MarketPrice
|
||
|
mp = order.MarketPrice
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if order.StopLossPrice == flags.SetNull {
|
||
|
order.StopLossPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.StopWinPrice == flags.SetNull {
|
||
|
order.StopWinPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.LimitPrice == flags.SetNull {
|
||
|
order.LimitPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.MarketPrice == flags.SetNull {
|
||
|
order.MarketPrice = decimal.Zero.String()
|
||
|
}
|
||
|
return models.BotStockInTrade{
|
||
|
UserId: int(userId),
|
||
|
TradeType: int(order.TradeType),
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StockId: order.StockId,
|
||
|
Status: flags.EntrustStatus,
|
||
|
ServiceCost: order.ServiceCost,
|
||
|
OrderNumber: order.OrderNumber,
|
||
|
OrderMoney: orderMoney.String(),
|
||
|
OrderId: orderId,
|
||
|
MarketMoney: order.MarketMoney,
|
||
|
LimitPrice: lp,
|
||
|
MarketPrice: mp,
|
||
|
DealType: int(order.DealType),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
DealPrice: decimal.Zero.String(),
|
||
|
ClosingPrice: decimal.Zero.String(),
|
||
|
ClosingCost: decimal.Zero.String(),
|
||
|
OvernightCost: decimal.Zero.String(),
|
||
|
PryNum: pryNum,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockGbxTrade
|
||
|
//
|
||
|
// @Description: (英股下单|英股设置止损止盈|英股撤单|英股平仓)
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param orderId
|
||
|
// @param order
|
||
|
// @return models.BotStockGbxTrade
|
||
|
func BotStockGbxTrade(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockGbxTrade {
|
||
|
marketPrice := decimal.RequireFromString(order.MarketMoney)
|
||
|
cost := decimal.RequireFromString(order.ServiceCost)
|
||
|
// total order Money
|
||
|
orderMoney := marketPrice.Add(cost)
|
||
|
pryNum, err := strconv.Atoi(order.PryNum)
|
||
|
if err != nil {
|
||
|
pryNum = 1
|
||
|
}
|
||
|
|
||
|
var lp, mp string
|
||
|
switch order.DealType {
|
||
|
case flags.DealTypeLimited: // 限价
|
||
|
if len(order.LimitPrice) != 0 {
|
||
|
lp = order.LimitPrice
|
||
|
mp = order.LimitPrice
|
||
|
}
|
||
|
case flags.DealTypeMarket: // 市价
|
||
|
if len(order.MarketPrice) != 0 {
|
||
|
lp = order.MarketPrice
|
||
|
mp = order.MarketPrice
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if order.StopLossPrice == flags.SetNull {
|
||
|
order.StopLossPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.StopWinPrice == flags.SetNull {
|
||
|
order.StopWinPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.LimitPrice == flags.SetNull {
|
||
|
order.LimitPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.MarketPrice == flags.SetNull {
|
||
|
order.MarketPrice = decimal.Zero.String()
|
||
|
}
|
||
|
return models.BotStockGbxTrade{
|
||
|
UserId: int(userId),
|
||
|
TradeType: int(order.TradeType),
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StockId: order.StockId,
|
||
|
Status: flags.EntrustStatus,
|
||
|
ServiceCost: order.ServiceCost,
|
||
|
OrderNumber: order.OrderNumber,
|
||
|
OrderMoney: orderMoney.String(),
|
||
|
OrderId: orderId,
|
||
|
MarketMoney: order.MarketMoney,
|
||
|
LimitPrice: lp,
|
||
|
MarketPrice: mp,
|
||
|
DealType: int(order.DealType),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
DealPrice: decimal.Zero.String(),
|
||
|
ClosingPrice: decimal.Zero.String(),
|
||
|
ClosingCost: decimal.Zero.String(),
|
||
|
OvernightCost: decimal.Zero.String(),
|
||
|
PryNum: pryNum,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockOptionInrTrade
|
||
|
//
|
||
|
// @Description: (印度期权股下单|印度期权股设置止损止盈|印度期权股撤单|印度期权股平仓)
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param orderId
|
||
|
// @param order
|
||
|
// @return models.BotStockOptionInrTrade
|
||
|
func BotStockOptionInrTrade(ctx context.Context, userId int64, orderId, marginRatio string, order structure.ShareOrder) models.BotStockOptionInrTrade {
|
||
|
pryNum, err := strconv.Atoi(order.PryNum)
|
||
|
if err != nil {
|
||
|
pryNum = 1
|
||
|
}
|
||
|
orderMoney := decimal.RequireFromString(marginRatio).Add(decimal.RequireFromString(order.ServiceCost)).String()
|
||
|
|
||
|
multiplier, err := strconv.Atoi(order.Multiplier)
|
||
|
if err != nil {
|
||
|
multiplier = 1
|
||
|
}
|
||
|
|
||
|
var lp, mp string
|
||
|
|
||
|
switch order.DealType {
|
||
|
case flags.DealTypeLimited: // 限价
|
||
|
if len(order.LimitPrice) != 0 {
|
||
|
lp = order.LimitPrice
|
||
|
mp = order.LimitPrice
|
||
|
}
|
||
|
case flags.DealTypeMarket: // 市价
|
||
|
if len(order.MarketPrice) != 0 {
|
||
|
lp = order.MarketPrice
|
||
|
mp = order.MarketPrice
|
||
|
}
|
||
|
}
|
||
|
if order.StrikePrice == flags.SetNull {
|
||
|
order.StrikePrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.StopLossPrice == flags.SetNull {
|
||
|
order.StopLossPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.StopWinPrice == flags.SetNull {
|
||
|
order.StopWinPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.LimitPrice == flags.SetNull {
|
||
|
order.LimitPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.MarketPrice == flags.SetNull {
|
||
|
order.MarketPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.Bid == flags.SetNull {
|
||
|
order.Bid = decimal.Zero.String()
|
||
|
}
|
||
|
if order.Ask == flags.SetNull {
|
||
|
order.Ask = decimal.Zero.String()
|
||
|
}
|
||
|
ratio := decimal.RequireFromString(flags.DecimalOne).Sub(decimal.RequireFromString(order.Ratio)).IntPart()
|
||
|
|
||
|
return models.BotStockOptionInrTrade{
|
||
|
UserId: int(userId),
|
||
|
OrderId: orderId,
|
||
|
TradeType: int(order.TradeType),
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StockId: order.StockId,
|
||
|
Status: flags.EntrustStatus,
|
||
|
ServiceCost: order.ServiceCost,
|
||
|
OrderNumber: order.OrderNumber,
|
||
|
MarketMoney: marginRatio,
|
||
|
OrderMoney: orderMoney,
|
||
|
LimitPrice: lp,
|
||
|
MarketPrice: mp,
|
||
|
DealType: int(order.DealType),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
DealPrice: decimal.Zero.String(),
|
||
|
ClosingPrice: decimal.Zero.String(),
|
||
|
ClosingCost: decimal.Zero.String(),
|
||
|
OvernightCost: decimal.Zero.String(),
|
||
|
PryNum: pryNum,
|
||
|
StopTime: order.StopTime,
|
||
|
StrikePrice: order.StrikePrice,
|
||
|
Multiplier: multiplier,
|
||
|
CostPrice: decimal.Zero.String(),
|
||
|
TradingType: int(order.TradingType),
|
||
|
Ratio: int(ratio),
|
||
|
StockCode: order.StockCode,
|
||
|
Bid: order.Bid,
|
||
|
Ask: order.Ask,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockIdnStopByOrderId
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param order
|
||
|
// @return models.BotStockIdnTrade
|
||
|
func BotStockIdnStopByOrderId(ctx context.Context, order structure.StopOrder) models.BotStockIdnTrade {
|
||
|
return models.BotStockIdnTrade{
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockInStopByOrderId
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param order
|
||
|
// @return models.BotStockInTrade
|
||
|
func BotStockInStopByOrderId(ctx context.Context, order structure.StopOrder) models.BotStockInTrade {
|
||
|
return models.BotStockInTrade{
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockGbxStopByOrderId
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param order
|
||
|
// @return models.BotStockGbxTrade
|
||
|
func BotStockGbxStopByOrderId(ctx context.Context, order structure.StopOrder) models.BotStockGbxTrade {
|
||
|
return models.BotStockGbxTrade{
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockOptionInrStopByOrderId
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param order
|
||
|
// @return models.BotStockOptionInrTrade
|
||
|
func BotStockOptionInrStopByOrderId(ctx context.Context, order structure.StopOrder) models.BotStockOptionInrTrade {
|
||
|
return models.BotStockOptionInrTrade{
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockIdnCancelByOrderId
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @return models.BotStockIdnTrade
|
||
|
func BotStockIdnCancelByOrderId(ctx context.Context) models.BotStockIdnTrade {
|
||
|
return models.BotStockIdnTrade{
|
||
|
Status: flags.CancelStatus,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockInCancelByOrderId
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @return models.BotStockIdnTrade
|
||
|
func BotStockInCancelByOrderId(ctx context.Context) models.BotStockInTrade {
|
||
|
return models.BotStockInTrade{
|
||
|
Status: flags.CancelStatus,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockGbxCancelByOrderId
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @return models.BotStockGbxTrade
|
||
|
func BotStockGbxCancelByOrderId(ctx context.Context) models.BotStockGbxTrade {
|
||
|
return models.BotStockGbxTrade{
|
||
|
Status: flags.CancelStatus,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockOptionInrCancelByOrderId
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @return models.BotStockOptionInrTrade
|
||
|
func BotStockOptionInrCancelByOrderId(ctx context.Context) models.BotStockOptionInrTrade {
|
||
|
return models.BotStockOptionInrTrade{
|
||
|
Status: flags.CancelStatus,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateBotUserStockIdn
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockIdn
|
||
|
func UpdateBotUserStockIdn(ctx context.Context, usableNum, frozenNum string) models.BotUserStockIdn {
|
||
|
return models.BotUserStockIdn{
|
||
|
UpdateTime: time.Now(),
|
||
|
FrozenNum: frozenNum,
|
||
|
UsableNum: usableNum,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateBotUserStockIn
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockIn
|
||
|
func UpdateBotUserStockIn(ctx context.Context, usableNum, frozenNum string) models.BotUserStockIn {
|
||
|
return models.BotUserStockIn{
|
||
|
UpdateTime: time.Now(),
|
||
|
FrozenNum: frozenNum,
|
||
|
UsableNum: usableNum,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateBotUserStockGbx
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockGbx
|
||
|
func UpdateBotUserStockGbx(ctx context.Context, usableNum, frozenNum string) models.BotUserStockGbx {
|
||
|
return models.BotUserStockGbx{
|
||
|
UpdateTime: time.Now(),
|
||
|
FrozenNum: frozenNum,
|
||
|
UsableNum: usableNum,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateBotUserStockOptionInr
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockOptionInr
|
||
|
func UpdateBotUserStockOptionInr(ctx context.Context, usableNum, frozenNum string) models.BotUserStockOptionInr {
|
||
|
return models.BotUserStockOptionInr{
|
||
|
UpdateTime: time.Now(),
|
||
|
FrozenNum: frozenNum,
|
||
|
UsableNum: usableNum,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreateBotUserStockIdn
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param stockId
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockIdn
|
||
|
func CreateBotUserStockIdn(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockIdn {
|
||
|
return models.BotUserStockIdn{
|
||
|
UserId: int(userId),
|
||
|
StockId: stockId,
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreateBotUserStockIn
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param stockId
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockIn
|
||
|
func CreateBotUserStockIn(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockIn {
|
||
|
return models.BotUserStockIn{
|
||
|
UserId: int(userId),
|
||
|
StockId: stockId,
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreateBotUserStockGbx
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param stockId
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockGbx
|
||
|
func CreateBotUserStockGbx(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockGbx {
|
||
|
return models.BotUserStockGbx{
|
||
|
UserId: int(userId),
|
||
|
StockId: stockId,
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreateBotUserStockOptionInr
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param stockId
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockOptionInr
|
||
|
func CreateBotUserStockOptionInr(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockOptionInr {
|
||
|
return models.BotUserStockOptionInr{
|
||
|
UserId: int(userId),
|
||
|
StockId: stockId,
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateOpenBotStockIdnTrade
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param price
|
||
|
// @param orderNumber
|
||
|
// @param totalMoney
|
||
|
// @param serviceCost
|
||
|
// @return models.BotStockIdnTrade
|
||
|
func UpdateOpenBotStockIdnTrade(ctx context.Context, price, orderNumber, totalMoney, serviceCost, openMarketMoney string) models.BotStockIdnTrade {
|
||
|
return models.BotStockIdnTrade{
|
||
|
OpenTime: time.Now(),
|
||
|
DealPrice: price,
|
||
|
ServiceCost: serviceCost,
|
||
|
OrderNumber: orderNumber,
|
||
|
OrderMoney: totalMoney,
|
||
|
MarketMoney: openMarketMoney,
|
||
|
Status: flags.PositionStatus,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateOpenBotStockInTrade
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param price
|
||
|
// @param orderNumber
|
||
|
// @param totalMoney
|
||
|
// @param serviceCost
|
||
|
// @param openMarketMoney
|
||
|
// @return models.BotStockInTrade
|
||
|
func UpdateOpenBotStockInTrade(ctx context.Context, price, orderNumber, totalMoney, serviceCost, openMarketMoney string) models.BotStockInTrade {
|
||
|
return models.BotStockInTrade{
|
||
|
OpenTime: time.Now(),
|
||
|
DealPrice: price,
|
||
|
ServiceCost: serviceCost,
|
||
|
OrderNumber: orderNumber,
|
||
|
OrderMoney: totalMoney,
|
||
|
MarketMoney: openMarketMoney,
|
||
|
Status: flags.PositionStatus,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateOpenBotStockGbxTrade
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param price
|
||
|
// @param orderNumber
|
||
|
// @param totalMoney
|
||
|
// @param serviceCost
|
||
|
// @param openMarketMoney
|
||
|
// @return models.BotStockGbxTrade
|
||
|
func UpdateOpenBotStockGbxTrade(ctx context.Context, price, orderNumber, totalMoney, serviceCost, openMarketMoney string) models.BotStockGbxTrade {
|
||
|
return models.BotStockGbxTrade{
|
||
|
OpenTime: time.Now(),
|
||
|
DealPrice: price,
|
||
|
ServiceCost: serviceCost,
|
||
|
OrderNumber: orderNumber,
|
||
|
OrderMoney: totalMoney,
|
||
|
MarketMoney: openMarketMoney,
|
||
|
Status: flags.PositionStatus,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateOpenBotStockOptionInrTrade
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param price
|
||
|
// @param orderNumber
|
||
|
// @param totalMoney
|
||
|
// @param serviceCost
|
||
|
// @param openMarketMoney
|
||
|
// @return models.BotStockOptionInrTrade
|
||
|
func UpdateOpenBotStockOptionInrTrade(ctx context.Context, price, orderNumber, totalMoney, serviceCost, openMarketMoney string) models.BotStockOptionInrTrade {
|
||
|
return models.BotStockOptionInrTrade{
|
||
|
OpenTime: time.Now(),
|
||
|
DealPrice: price,
|
||
|
ServiceCost: serviceCost,
|
||
|
OrderNumber: orderNumber,
|
||
|
OrderMoney: totalMoney,
|
||
|
MarketMoney: openMarketMoney,
|
||
|
Status: flags.PositionStatus,
|
||
|
CostPrice: decimal.Zero.String(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateCloseBotStockIdnTrade
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param price
|
||
|
// @param totalMoney
|
||
|
// @param serviceCost
|
||
|
// @return models.BotStockIdnTrade
|
||
|
func UpdateCloseBotStockIdnTrade(ctx context.Context, price, serviceCost string) models.BotStockIdnTrade {
|
||
|
return models.BotStockIdnTrade{
|
||
|
ClosingTime: time.Now(),
|
||
|
ClosingPrice: price,
|
||
|
ClosingCost: serviceCost,
|
||
|
Status: flags.CloseStatus,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateCloseBotStockInTrade
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param price
|
||
|
// @param serviceCost
|
||
|
// @return models.BotStockInTrade
|
||
|
func UpdateCloseBotStockInTrade(ctx context.Context, price, serviceCost string) models.BotStockInTrade {
|
||
|
return models.BotStockInTrade{
|
||
|
ClosingTime: time.Now(),
|
||
|
ClosingPrice: price,
|
||
|
ClosingCost: serviceCost,
|
||
|
Status: flags.CloseStatus,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateCloseBotStockGbxTrade
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param price
|
||
|
// @param serviceCost
|
||
|
// @return models.BotStockGbxTrade
|
||
|
func UpdateCloseBotStockGbxTrade(ctx context.Context, price, serviceCost string) models.BotStockGbxTrade {
|
||
|
return models.BotStockGbxTrade{
|
||
|
ClosingTime: time.Now(),
|
||
|
ClosingPrice: price,
|
||
|
ClosingCost: serviceCost,
|
||
|
Status: flags.CloseStatus,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateCloseBotStockOptionInrTrade
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param price
|
||
|
// @param serviceCost
|
||
|
// @return models.BotStockOptionInrTrade
|
||
|
func UpdateCloseBotStockOptionInrTrade(ctx context.Context, price, serviceCost string) models.BotStockOptionInrTrade {
|
||
|
return models.BotStockOptionInrTrade{
|
||
|
ClosingTime: time.Now(),
|
||
|
ClosingPrice: price,
|
||
|
ClosingCost: serviceCost,
|
||
|
Status: flags.CloseStatus,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreatBotUserStockIdnLog
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param code
|
||
|
// @param symbol
|
||
|
// @param changeNum
|
||
|
// @param orderId
|
||
|
// @return models.BotUserStockIdnLog
|
||
|
func CreatBotUserStockIdnLog(ctx context.Context, userId, code int64, symbol, changeNum, orderId string) models.BotUserStockIdnLog {
|
||
|
return models.BotUserStockIdnLog{
|
||
|
OrderId: orderId,
|
||
|
UserId: int(userId),
|
||
|
ChangeNum: changeNum,
|
||
|
ChangeType: int(code),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
StockId: symbol,
|
||
|
BeforeNum: decimal.Zero.String(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreatBotUserStockInLog
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param code
|
||
|
// @param symbol
|
||
|
// @param changeNum
|
||
|
// @param orderId
|
||
|
// @return models.BotUserStockInLog
|
||
|
func CreatBotUserStockInLog(ctx context.Context, userId, code int64, symbol, changeNum, orderId string) models.BotUserStockInLog {
|
||
|
return models.BotUserStockInLog{
|
||
|
OrderId: orderId,
|
||
|
UserId: int(userId),
|
||
|
ChangeNum: changeNum,
|
||
|
ChangeType: int(code),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
StockId: symbol,
|
||
|
BeforeNum: decimal.Zero.String(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreatBotUserStockGbxLog
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param code
|
||
|
// @param symbol
|
||
|
// @param changeNum
|
||
|
// @param orderId
|
||
|
// @return models.BotUserStockGbxLog
|
||
|
func CreatBotUserStockGbxLog(ctx context.Context, userId, code int64, symbol, changeNum, orderId string) models.BotUserStockGbxLog {
|
||
|
return models.BotUserStockGbxLog{
|
||
|
OrderId: orderId,
|
||
|
UserId: int(userId),
|
||
|
ChangeNum: changeNum,
|
||
|
ChangeType: int(code),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
StockId: symbol,
|
||
|
BeforeNum: decimal.Zero.String(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreatBotUserStockOptionInrLog
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param code
|
||
|
// @param symbol
|
||
|
// @param changeNum
|
||
|
// @param orderId
|
||
|
// @return models.BotUserStockOptionInrLog
|
||
|
func CreatBotUserStockOptionInrLog(ctx context.Context, userId, code int64, symbol, changeNum, orderId string) models.BotUserStockOptionInrLog {
|
||
|
return models.BotUserStockOptionInrLog{
|
||
|
OrderId: orderId,
|
||
|
UserId: int(userId),
|
||
|
ChangeNum: changeNum,
|
||
|
ChangeType: int(code),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
StockId: symbol,
|
||
|
BeforeNum: decimal.Zero.String(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockIdnTradePre (印度新股申购下单|设置止损止盈|撤单|平仓)
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param orderId
|
||
|
// @param order
|
||
|
// @return models.BotStockIdnTrade
|
||
|
func BotStockIdnTradePre(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockIdnTrade {
|
||
|
if order.StopWinPrice == flags.SetNull {
|
||
|
order.StopWinPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.StopLossPrice == flags.SetNull {
|
||
|
order.StopLossPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.MarketPrice == flags.SetNull {
|
||
|
order.MarketPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.LimitPrice == flags.SetNull {
|
||
|
order.LimitPrice = decimal.Zero.String()
|
||
|
}
|
||
|
|
||
|
return models.BotStockIdnTrade{
|
||
|
UserId: int(userId),
|
||
|
TradeType: int(order.TradeType),
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StockId: order.StockId,
|
||
|
ServiceCost: order.ServiceCost,
|
||
|
MarketPrice: order.MarketPrice,
|
||
|
MarketMoney: order.MarketMoney,
|
||
|
LimitPrice: order.LimitPrice,
|
||
|
DealType: int(order.DealType),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
OrderId: orderId,
|
||
|
Status: flags.PositionStatus,
|
||
|
OpenTime: time.Now(),
|
||
|
DealPrice: order.LimitPrice,
|
||
|
OrderNumber: order.OrderNumber,
|
||
|
OrderMoney: order.MarketMoney,
|
||
|
OvernightCost: decimal.Zero.String(),
|
||
|
ClosingCost: decimal.Zero.String(),
|
||
|
ClosingPrice: decimal.Zero.String(),
|
||
|
PryNum: flags.SetPreOne,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockMysTrade (马股下单|马股设置止损止盈|马股撤单|马股平仓)
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param orderId
|
||
|
// @param order
|
||
|
// @return models.BotStockMysTrade
|
||
|
func BotStockMysTrade(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockMysTrade {
|
||
|
marketPrice := decimal.RequireFromString(order.MarketMoney)
|
||
|
cost := decimal.RequireFromString(order.ServiceCost)
|
||
|
// total order Money
|
||
|
orderMoney := marketPrice.Add(cost)
|
||
|
pryNum, err := strconv.Atoi(order.PryNum)
|
||
|
if err != nil {
|
||
|
pryNum = 1
|
||
|
}
|
||
|
|
||
|
var lp, mp string
|
||
|
switch order.DealType {
|
||
|
case flags.DealTypeLimited: // 限价
|
||
|
if len(order.LimitPrice) != 0 {
|
||
|
lp = order.LimitPrice
|
||
|
mp = order.LimitPrice
|
||
|
}
|
||
|
case flags.DealTypeMarket: // 市价
|
||
|
if len(order.MarketPrice) != 0 {
|
||
|
lp = order.MarketPrice
|
||
|
mp = order.MarketPrice
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if order.StopLossPrice == flags.SetNull {
|
||
|
order.StopLossPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.StopWinPrice == flags.SetNull {
|
||
|
order.StopWinPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.MarketPrice == flags.SetNull {
|
||
|
order.MarketPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.LimitPrice == flags.SetNull {
|
||
|
order.LimitPrice = decimal.Zero.String()
|
||
|
}
|
||
|
|
||
|
return models.BotStockMysTrade{
|
||
|
UserId: int(userId),
|
||
|
TradeType: int(order.TradeType),
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StockId: order.StockId,
|
||
|
Status: flags.EntrustStatus,
|
||
|
ServiceCost: order.ServiceCost,
|
||
|
OrderNumber: order.OrderNumber,
|
||
|
OrderMoney: orderMoney.String(),
|
||
|
OrderId: orderId,
|
||
|
MarketMoney: order.MarketMoney,
|
||
|
LimitPrice: lp,
|
||
|
MarketPrice: mp,
|
||
|
DealType: int(order.DealType),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
ClosingCost: decimal.Zero.String(),
|
||
|
OvernightCost: decimal.Zero.String(),
|
||
|
ClosingPrice: decimal.Zero.String(),
|
||
|
DealPrice: decimal.Zero.String(),
|
||
|
PryNum: pryNum,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockMysStopByOrderId
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param order
|
||
|
// @return models.BotStockMysTrade
|
||
|
func BotStockMysStopByOrderId(ctx context.Context, order structure.StopOrder) models.BotStockMysTrade {
|
||
|
return models.BotStockMysTrade{
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockMysCancelByOrderId
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @return models.BotStockMysTrade
|
||
|
func BotStockMysCancelByOrderId(ctx context.Context) models.BotStockMysTrade {
|
||
|
return models.BotStockMysTrade{
|
||
|
Status: flags.CancelStatus,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateBotUserStockMys
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockMys
|
||
|
func UpdateBotUserStockMys(ctx context.Context, usableNum, frozenNum string) models.BotUserStockMys {
|
||
|
return models.BotUserStockMys{
|
||
|
UpdateTime: time.Now(),
|
||
|
FrozenNum: frozenNum,
|
||
|
UsableNum: usableNum,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreateBotUserStockMys
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param stockId
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockMys
|
||
|
func CreateBotUserStockMys(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockMys {
|
||
|
return models.BotUserStockMys{
|
||
|
UserId: int(userId),
|
||
|
StockId: stockId,
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateOpenBotStockMysTrade
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param price
|
||
|
// @param orderNumber
|
||
|
// @param totalMoney
|
||
|
// @param serviceCost
|
||
|
// @return models.BotStockMysTrade
|
||
|
func UpdateOpenBotStockMysTrade(ctx context.Context, price, orderNumber, totalMoney, serviceCost, openMarkerMoney string) models.BotStockMysTrade {
|
||
|
return models.BotStockMysTrade{
|
||
|
OpenTime: time.Now(),
|
||
|
DealPrice: price,
|
||
|
ServiceCost: serviceCost,
|
||
|
OrderNumber: orderNumber,
|
||
|
OrderMoney: totalMoney,
|
||
|
MarketMoney: openMarkerMoney,
|
||
|
Status: flags.PositionStatus,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateCloseBotStockMysTrade
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param price
|
||
|
// @param totalMoney
|
||
|
// @param serviceCost
|
||
|
// @return models.BotStockMysTrade
|
||
|
func UpdateCloseBotStockMysTrade(ctx context.Context, price, serviceCost string) models.BotStockMysTrade {
|
||
|
return models.BotStockMysTrade{
|
||
|
ClosingTime: time.Now(),
|
||
|
ClosingPrice: price,
|
||
|
ClosingCost: serviceCost,
|
||
|
Status: flags.CloseStatus,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreatBotUserStockMysLog
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param code
|
||
|
// @param symbol
|
||
|
// @param changeNum
|
||
|
// @param orderId
|
||
|
// @return models.BotUserStockMysLog
|
||
|
func CreatBotUserStockMysLog(ctx context.Context, userId, code int64, symbol, changeNum, orderId string) models.BotUserStockMysLog {
|
||
|
return models.BotUserStockMysLog{
|
||
|
OrderId: orderId,
|
||
|
UserId: int(userId),
|
||
|
ChangeNum: changeNum,
|
||
|
ChangeType: int(code),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
StockId: symbol,
|
||
|
BeforeNum: decimal.Zero.String(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockMysTradePre
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param orderId
|
||
|
// @param order
|
||
|
// @return models.BotStockMysTrade
|
||
|
func BotStockMysTradePre(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockMysTrade {
|
||
|
if order.StopWinPrice == flags.SetNull {
|
||
|
order.StopWinPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.StopLossPrice == flags.SetNull {
|
||
|
order.StopLossPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.MarketPrice == flags.SetNull {
|
||
|
order.MarketPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.LimitPrice == flags.SetNull {
|
||
|
order.LimitPrice = decimal.Zero.String()
|
||
|
}
|
||
|
return models.BotStockMysTrade{
|
||
|
UserId: int(userId),
|
||
|
TradeType: int(order.TradeType),
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StockId: order.StockId,
|
||
|
ServiceCost: order.ServiceCost,
|
||
|
MarketPrice: order.MarketPrice,
|
||
|
MarketMoney: order.MarketMoney,
|
||
|
LimitPrice: order.LimitPrice,
|
||
|
DealType: int(order.DealType),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
OrderId: orderId,
|
||
|
Status: flags.PositionStatus,
|
||
|
OpenTime: time.Now(),
|
||
|
DealPrice: order.LimitPrice,
|
||
|
OrderNumber: order.OrderNumber,
|
||
|
OrderMoney: order.MarketMoney,
|
||
|
ClosingCost: decimal.Zero.String(),
|
||
|
OvernightCost: decimal.Zero.String(),
|
||
|
ClosingPrice: decimal.Zero.String(),
|
||
|
PryNum: flags.SetPreOne,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockThaTrade (泰股下单|泰股设置止损止盈|泰股撤单|泰股平仓)
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param orderId
|
||
|
// @param order
|
||
|
// @return models.BotStockThaTrade
|
||
|
func BotStockThaTrade(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockThaTrade {
|
||
|
marketPrice := decimal.RequireFromString(order.MarketMoney)
|
||
|
cost := decimal.RequireFromString(order.ServiceCost)
|
||
|
// total order Money
|
||
|
orderMoney := marketPrice.Add(cost)
|
||
|
pryNum, err := strconv.Atoi(order.PryNum)
|
||
|
if err != nil {
|
||
|
pryNum = 1
|
||
|
}
|
||
|
|
||
|
var lp, mp string
|
||
|
switch order.DealType {
|
||
|
case flags.DealTypeLimited: // 限价
|
||
|
if len(order.LimitPrice) != 0 {
|
||
|
lp = order.LimitPrice
|
||
|
mp = order.LimitPrice
|
||
|
}
|
||
|
case flags.DealTypeMarket: // 市价
|
||
|
if len(order.MarketPrice) != 0 {
|
||
|
lp = order.MarketPrice
|
||
|
mp = order.MarketPrice
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if order.StopLossPrice == flags.SetNull {
|
||
|
order.StopLossPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.StopWinPrice == flags.SetNull {
|
||
|
order.StopWinPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.MarketPrice == flags.SetNull {
|
||
|
order.MarketPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.LimitPrice == flags.SetNull {
|
||
|
order.LimitPrice = decimal.Zero.String()
|
||
|
}
|
||
|
|
||
|
return models.BotStockThaTrade{
|
||
|
UserId: int(userId),
|
||
|
TradeType: int(order.TradeType),
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StockId: order.StockId,
|
||
|
Status: flags.EntrustStatus,
|
||
|
ServiceCost: order.ServiceCost,
|
||
|
OrderNumber: order.OrderNumber,
|
||
|
OrderMoney: orderMoney.String(),
|
||
|
OrderId: orderId,
|
||
|
MarketMoney: order.MarketMoney,
|
||
|
MarketPrice: mp,
|
||
|
LimitPrice: lp,
|
||
|
DealType: int(order.DealType),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
ClosingCost: decimal.Zero.String(),
|
||
|
OvernightCost: decimal.Zero.String(),
|
||
|
ClosingPrice: decimal.Zero.String(),
|
||
|
DealPrice: decimal.Zero.String(),
|
||
|
PryNum: pryNum,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockSgdTrade (新加坡股下单|新加坡股设置止损止盈|新加坡股撤单|新加坡股平仓)
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param orderId
|
||
|
// @param order
|
||
|
// @return models.BotStockSgdTrade
|
||
|
func BotStockSgdTrade(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockSgdTrade {
|
||
|
marketPrice := decimal.RequireFromString(order.MarketMoney)
|
||
|
cost := decimal.RequireFromString(order.ServiceCost)
|
||
|
// total order Money
|
||
|
orderMoney := marketPrice.Add(cost)
|
||
|
pryNum, err := strconv.Atoi(order.PryNum)
|
||
|
if err != nil {
|
||
|
pryNum = 1
|
||
|
}
|
||
|
|
||
|
var lp, mp string
|
||
|
switch order.DealType {
|
||
|
case flags.DealTypeLimited: // 限价
|
||
|
if len(order.LimitPrice) != 0 {
|
||
|
lp = order.LimitPrice
|
||
|
mp = order.LimitPrice
|
||
|
}
|
||
|
case flags.DealTypeMarket: // 市价
|
||
|
if len(order.MarketPrice) != 0 {
|
||
|
lp = order.MarketPrice
|
||
|
mp = order.MarketPrice
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if order.StopLossPrice == flags.SetNull {
|
||
|
order.StopLossPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.StopWinPrice == flags.SetNull {
|
||
|
order.StopWinPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.MarketPrice == flags.SetNull {
|
||
|
order.MarketPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.LimitPrice == flags.SetNull {
|
||
|
order.LimitPrice = decimal.Zero.String()
|
||
|
}
|
||
|
|
||
|
return models.BotStockSgdTrade{
|
||
|
UserId: int(userId),
|
||
|
TradeType: int(order.TradeType),
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StockId: order.StockId,
|
||
|
Status: flags.EntrustStatus,
|
||
|
ServiceCost: order.ServiceCost,
|
||
|
OrderNumber: order.OrderNumber,
|
||
|
OrderMoney: orderMoney.String(),
|
||
|
OrderId: orderId,
|
||
|
MarketMoney: order.MarketMoney,
|
||
|
MarketPrice: mp,
|
||
|
LimitPrice: lp,
|
||
|
DealType: int(order.DealType),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
ClosingCost: decimal.Zero.String(),
|
||
|
OvernightCost: decimal.Zero.String(),
|
||
|
ClosingPrice: decimal.Zero.String(),
|
||
|
DealPrice: decimal.Zero.String(),
|
||
|
PryNum: pryNum,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockEurTrade (德股下单|德股设置止损止盈|德股撤单|德股平仓)
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param orderId
|
||
|
// @param order
|
||
|
// @return models.BotStockEurTrade
|
||
|
func BotStockEurTrade(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockEurTrade {
|
||
|
marketPrice := decimal.RequireFromString(order.MarketMoney)
|
||
|
cost := decimal.RequireFromString(order.ServiceCost)
|
||
|
// total order Money
|
||
|
orderMoney := marketPrice.Add(cost)
|
||
|
pryNum, err := strconv.Atoi(order.PryNum)
|
||
|
if err != nil {
|
||
|
pryNum = 1
|
||
|
}
|
||
|
|
||
|
var lp, mp string
|
||
|
switch order.DealType {
|
||
|
case flags.DealTypeLimited: // 限价
|
||
|
if len(order.LimitPrice) != 0 {
|
||
|
lp = order.LimitPrice
|
||
|
mp = order.LimitPrice
|
||
|
}
|
||
|
case flags.DealTypeMarket: // 市价
|
||
|
if len(order.MarketPrice) != 0 {
|
||
|
lp = order.MarketPrice
|
||
|
mp = order.MarketPrice
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if order.StopLossPrice == flags.SetNull {
|
||
|
order.StopLossPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.StopWinPrice == flags.SetNull {
|
||
|
order.StopWinPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.MarketPrice == flags.SetNull {
|
||
|
order.MarketPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.LimitPrice == flags.SetNull {
|
||
|
order.LimitPrice = decimal.Zero.String()
|
||
|
}
|
||
|
|
||
|
return models.BotStockEurTrade{
|
||
|
UserId: int(userId),
|
||
|
TradeType: int(order.TradeType),
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StockId: order.StockId,
|
||
|
Status: flags.EntrustStatus,
|
||
|
ServiceCost: order.ServiceCost,
|
||
|
OrderNumber: order.OrderNumber,
|
||
|
OrderMoney: orderMoney.String(),
|
||
|
OrderId: orderId,
|
||
|
MarketMoney: order.MarketMoney,
|
||
|
MarketPrice: mp,
|
||
|
LimitPrice: lp,
|
||
|
DealType: int(order.DealType),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
ClosingCost: decimal.Zero.String(),
|
||
|
OvernightCost: decimal.Zero.String(),
|
||
|
ClosingPrice: decimal.Zero.String(),
|
||
|
DealPrice: decimal.Zero.String(),
|
||
|
PryNum: pryNum,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockBrlTrade
|
||
|
//
|
||
|
// @Description: (巴西股下单|设置止损止盈|撤单|平仓)
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param orderId
|
||
|
// @param order
|
||
|
// @return models.BotStockBrlTrade
|
||
|
func BotStockBrlTrade(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockBrlTrade {
|
||
|
marketPrice := decimal.RequireFromString(order.MarketMoney)
|
||
|
cost := decimal.RequireFromString(order.ServiceCost)
|
||
|
// total order Money
|
||
|
orderMoney := marketPrice.Add(cost)
|
||
|
pryNum, err := strconv.Atoi(order.PryNum)
|
||
|
if err != nil {
|
||
|
pryNum = 1
|
||
|
}
|
||
|
|
||
|
var lp, mp string
|
||
|
switch order.DealType {
|
||
|
case flags.DealTypeLimited: // 限价
|
||
|
if len(order.LimitPrice) != 0 {
|
||
|
lp = order.LimitPrice
|
||
|
mp = order.LimitPrice
|
||
|
}
|
||
|
case flags.DealTypeMarket: // 市价
|
||
|
if len(order.MarketPrice) != 0 {
|
||
|
lp = order.MarketPrice
|
||
|
mp = order.MarketPrice
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if order.StopLossPrice == flags.SetNull {
|
||
|
order.StopLossPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.StopWinPrice == flags.SetNull {
|
||
|
order.StopWinPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.MarketPrice == flags.SetNull {
|
||
|
order.MarketPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.LimitPrice == flags.SetNull {
|
||
|
order.LimitPrice = decimal.Zero.String()
|
||
|
}
|
||
|
|
||
|
return models.BotStockBrlTrade{
|
||
|
UserId: int(userId),
|
||
|
TradeType: int(order.TradeType),
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StockId: order.StockId,
|
||
|
Status: flags.EntrustStatus,
|
||
|
ServiceCost: order.ServiceCost,
|
||
|
OrderNumber: order.OrderNumber,
|
||
|
OrderMoney: orderMoney.String(),
|
||
|
OrderId: orderId,
|
||
|
MarketMoney: order.MarketMoney,
|
||
|
MarketPrice: mp,
|
||
|
LimitPrice: lp,
|
||
|
DealType: int(order.DealType),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
ClosingCost: decimal.Zero.String(),
|
||
|
OvernightCost: decimal.Zero.String(),
|
||
|
ClosingPrice: decimal.Zero.String(),
|
||
|
DealPrice: decimal.Zero.String(),
|
||
|
PryNum: pryNum,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockEurTrade (法股下单|德股设置止损止盈|德股撤单|德股平仓)
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param orderId
|
||
|
// @param order
|
||
|
// @return models.BotStockFurTrade
|
||
|
func BotStockFurTrade(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockFurTrade {
|
||
|
marketPrice := decimal.RequireFromString(order.MarketMoney)
|
||
|
cost := decimal.RequireFromString(order.ServiceCost)
|
||
|
// total order Money
|
||
|
orderMoney := marketPrice.Add(cost)
|
||
|
pryNum, err := strconv.Atoi(order.PryNum)
|
||
|
if err != nil {
|
||
|
pryNum = 1
|
||
|
}
|
||
|
|
||
|
var lp, mp string
|
||
|
switch order.DealType {
|
||
|
case flags.DealTypeLimited: // 限价
|
||
|
if len(order.LimitPrice) != 0 {
|
||
|
lp = order.LimitPrice
|
||
|
mp = order.LimitPrice
|
||
|
}
|
||
|
case flags.DealTypeMarket: // 市价
|
||
|
if len(order.MarketPrice) != 0 {
|
||
|
lp = order.MarketPrice
|
||
|
mp = order.MarketPrice
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if order.StopLossPrice == flags.SetNull {
|
||
|
order.StopLossPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.StopWinPrice == flags.SetNull {
|
||
|
order.StopWinPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.MarketPrice == flags.SetNull {
|
||
|
order.MarketPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.LimitPrice == flags.SetNull {
|
||
|
order.LimitPrice = decimal.Zero.String()
|
||
|
}
|
||
|
|
||
|
return models.BotStockFurTrade{
|
||
|
UserId: int(userId),
|
||
|
TradeType: int(order.TradeType),
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StockId: order.StockId,
|
||
|
Status: flags.EntrustStatus,
|
||
|
ServiceCost: order.ServiceCost,
|
||
|
OrderNumber: order.OrderNumber,
|
||
|
OrderMoney: orderMoney.String(),
|
||
|
OrderId: orderId,
|
||
|
MarketMoney: order.MarketMoney,
|
||
|
MarketPrice: mp,
|
||
|
LimitPrice: lp,
|
||
|
DealType: int(order.DealType),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
ClosingCost: decimal.Zero.String(),
|
||
|
OvernightCost: decimal.Zero.String(),
|
||
|
ClosingPrice: decimal.Zero.String(),
|
||
|
DealPrice: decimal.Zero.String(),
|
||
|
PryNum: pryNum,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockJpyTrade (日股下单|德股设置止损止盈|德股撤单|德股平仓)
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param orderId
|
||
|
// @param order
|
||
|
// @return models.BotStockFurTrade
|
||
|
func BotStockJpyTrade(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockJpTrade {
|
||
|
marketPrice := decimal.RequireFromString(order.MarketMoney)
|
||
|
cost := decimal.RequireFromString(order.ServiceCost)
|
||
|
// total order Money
|
||
|
orderMoney := marketPrice.Add(cost)
|
||
|
pryNum, err := strconv.Atoi(order.PryNum)
|
||
|
if err != nil {
|
||
|
pryNum = 1
|
||
|
}
|
||
|
|
||
|
var lp, mp string
|
||
|
switch order.DealType {
|
||
|
case flags.DealTypeLimited: // 限价
|
||
|
if len(order.LimitPrice) != 0 {
|
||
|
lp = order.LimitPrice
|
||
|
mp = order.LimitPrice
|
||
|
}
|
||
|
case flags.DealTypeMarket: // 市价
|
||
|
if len(order.MarketPrice) != 0 {
|
||
|
lp = order.MarketPrice
|
||
|
mp = order.MarketPrice
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if order.StopLossPrice == flags.SetNull {
|
||
|
order.StopLossPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.StopWinPrice == flags.SetNull {
|
||
|
order.StopWinPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.MarketPrice == flags.SetNull {
|
||
|
order.MarketPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.LimitPrice == flags.SetNull {
|
||
|
order.LimitPrice = decimal.Zero.String()
|
||
|
}
|
||
|
|
||
|
return models.BotStockJpTrade{
|
||
|
UserId: int(userId),
|
||
|
TradeType: int(order.TradeType),
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StockId: order.StockId,
|
||
|
Status: flags.EntrustStatus,
|
||
|
ServiceCost: order.ServiceCost,
|
||
|
OrderNumber: order.OrderNumber,
|
||
|
OrderMoney: orderMoney.String(),
|
||
|
OrderId: orderId,
|
||
|
MarketMoney: order.MarketMoney,
|
||
|
MarketPrice: mp,
|
||
|
LimitPrice: lp,
|
||
|
DealType: int(order.DealType),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
ClosingCost: decimal.Zero.String(),
|
||
|
OvernightCost: decimal.Zero.String(),
|
||
|
ClosingPrice: decimal.Zero.String(),
|
||
|
DealPrice: decimal.Zero.String(),
|
||
|
PryNum: pryNum,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockThaStopByOrderId
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param order
|
||
|
// @return models.BotStockThaTrade
|
||
|
func BotStockThaStopByOrderId(ctx context.Context, order structure.StopOrder) models.BotStockThaTrade {
|
||
|
return models.BotStockThaTrade{
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockSgdStopByOrderId
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param order
|
||
|
// @return models.BotStockSgdTrade
|
||
|
func BotStockSgdStopByOrderId(ctx context.Context, order structure.StopOrder) models.BotStockSgdTrade {
|
||
|
return models.BotStockSgdTrade{
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockEurStopByOrderId
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param order
|
||
|
// @return models.BotStockEurTrade
|
||
|
func BotStockEurStopByOrderId(ctx context.Context, order structure.StopOrder) models.BotStockEurTrade {
|
||
|
return models.BotStockEurTrade{
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockBrlStopByOrderId
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param order
|
||
|
// @return models.BotStockBrlTrade
|
||
|
func BotStockBrlStopByOrderId(ctx context.Context, order structure.StopOrder) models.BotStockBrlTrade {
|
||
|
return models.BotStockBrlTrade{
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockFurStopByOrderId
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param order
|
||
|
// @return models.BotStockFurTrade
|
||
|
func BotStockFurStopByOrderId(ctx context.Context, order structure.StopOrder) models.BotStockFurTrade {
|
||
|
return models.BotStockFurTrade{
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockJpyStopByOrderId
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param order
|
||
|
// @return models.BotStockJpTrade
|
||
|
func BotStockJpyStopByOrderId(ctx context.Context, order structure.StopOrder) models.BotStockJpTrade {
|
||
|
return models.BotStockJpTrade{
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockThaCancelByOrderId
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @return models.BotStockThaTrade
|
||
|
func BotStockThaCancelByOrderId(ctx context.Context) models.BotStockThaTrade {
|
||
|
return models.BotStockThaTrade{
|
||
|
Status: flags.CancelStatus,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockSgdCancelByOrderId
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @return models.BotStockSgdTrade
|
||
|
func BotStockSgdCancelByOrderId(ctx context.Context) models.BotStockSgdTrade {
|
||
|
return models.BotStockSgdTrade{
|
||
|
Status: flags.CancelStatus,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockEurCancelByOrderId
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @return models.BotStockEurTrade
|
||
|
func BotStockEurCancelByOrderId(ctx context.Context) models.BotStockEurTrade {
|
||
|
return models.BotStockEurTrade{
|
||
|
Status: flags.CancelStatus,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockBrlCancelByOrderId
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @return models.BotStockBrlTrade
|
||
|
func BotStockBrlCancelByOrderId(ctx context.Context) models.BotStockBrlTrade {
|
||
|
return models.BotStockBrlTrade{
|
||
|
Status: flags.CancelStatus,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockFurCancelByOrderId
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @return models.BotStockFurTrade
|
||
|
func BotStockFurCancelByOrderId(ctx context.Context) models.BotStockFurTrade {
|
||
|
return models.BotStockFurTrade{
|
||
|
Status: flags.CancelStatus,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockJpyCancelByOrderId
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @return models.BotStockJpTrade
|
||
|
func BotStockJpyCancelByOrderId(ctx context.Context) models.BotStockJpTrade {
|
||
|
return models.BotStockJpTrade{
|
||
|
Status: flags.CancelStatus,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateBotUserStockTha
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockTha
|
||
|
func UpdateBotUserStockTha(ctx context.Context, usableNum, frozenNum string) models.BotUserStockTha {
|
||
|
return models.BotUserStockTha{
|
||
|
UpdateTime: time.Now(),
|
||
|
FrozenNum: frozenNum,
|
||
|
UsableNum: usableNum,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateBotUserStockSgd
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockSgd
|
||
|
func UpdateBotUserStockSgd(ctx context.Context, usableNum, frozenNum string) models.BotUserStockSgd {
|
||
|
return models.BotUserStockSgd{
|
||
|
UpdateTime: time.Now(),
|
||
|
FrozenNum: frozenNum,
|
||
|
UsableNum: usableNum,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateBotUserStockEur
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockEur
|
||
|
func UpdateBotUserStockEur(ctx context.Context, usableNum, frozenNum string) models.BotUserStockEur {
|
||
|
return models.BotUserStockEur{
|
||
|
UpdateTime: time.Now(),
|
||
|
FrozenNum: frozenNum,
|
||
|
UsableNum: usableNum,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateBotUserStockBrl
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockBrl
|
||
|
func UpdateBotUserStockBrl(ctx context.Context, usableNum, frozenNum string) models.BotUserStockBrl {
|
||
|
return models.BotUserStockBrl{
|
||
|
UpdateTime: time.Now(),
|
||
|
FrozenNum: frozenNum,
|
||
|
UsableNum: usableNum,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateBotUserStockFur
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockEur
|
||
|
func UpdateBotUserStockFur(ctx context.Context, usableNum, frozenNum string) models.BotUserStockFur {
|
||
|
return models.BotUserStockFur{
|
||
|
UpdateTime: time.Now(),
|
||
|
FrozenNum: frozenNum,
|
||
|
UsableNum: usableNum,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateBotUserStockJpy
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockJp
|
||
|
func UpdateBotUserStockJpy(ctx context.Context, usableNum, frozenNum string) models.BotUserStockJp {
|
||
|
return models.BotUserStockJp{
|
||
|
UpdateTime: time.Now(),
|
||
|
FrozenNum: frozenNum,
|
||
|
UsableNum: usableNum,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreateBotUserStockTha
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param stockId
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockTha
|
||
|
func CreateBotUserStockTha(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockTha {
|
||
|
return models.BotUserStockTha{
|
||
|
UserId: int(userId),
|
||
|
StockId: stockId,
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreateBotUserStockSgd
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param stockId
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockSgd
|
||
|
func CreateBotUserStockSgd(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockSgd {
|
||
|
return models.BotUserStockSgd{
|
||
|
UserId: int(userId),
|
||
|
StockId: stockId,
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreateBotUserStockEur
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param stockId
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockEur
|
||
|
func CreateBotUserStockEur(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockEur {
|
||
|
return models.BotUserStockEur{
|
||
|
UserId: int(userId),
|
||
|
StockId: stockId,
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreateBotUserStockBrl
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param stockId
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockBrl
|
||
|
func CreateBotUserStockBrl(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockBrl {
|
||
|
return models.BotUserStockBrl{
|
||
|
UserId: int(userId),
|
||
|
StockId: stockId,
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreateBotUserStockFur
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param stockId
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockFur
|
||
|
func CreateBotUserStockFur(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockFur {
|
||
|
return models.BotUserStockFur{
|
||
|
UserId: int(userId),
|
||
|
StockId: stockId,
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreateBotUserStockJpy
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param stockId
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserStockJp
|
||
|
func CreateBotUserStockJpy(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockJp {
|
||
|
return models.BotUserStockJp{
|
||
|
UserId: int(userId),
|
||
|
StockId: stockId,
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateOpenBotStockThaTrade
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param price
|
||
|
// @param orderNumber
|
||
|
// @param totalMoney
|
||
|
// @param serviceCost
|
||
|
// @return models.BotStockThaTrade
|
||
|
func UpdateOpenBotStockThaTrade(ctx context.Context, price, orderNumber, totalMoney, serviceCost, openMarkerMoney string) models.BotStockThaTrade {
|
||
|
return models.BotStockThaTrade{
|
||
|
OpenTime: time.Now(),
|
||
|
DealPrice: price,
|
||
|
ServiceCost: serviceCost,
|
||
|
OrderNumber: orderNumber,
|
||
|
OrderMoney: totalMoney,
|
||
|
MarketMoney: openMarkerMoney,
|
||
|
Status: flags.PositionStatus,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateOpenBotStockSgdTrade
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param price
|
||
|
// @param orderNumber
|
||
|
// @param totalMoney
|
||
|
// @param serviceCost
|
||
|
// @param openMarkerMoney
|
||
|
// @return models.BotStockSgdTrade
|
||
|
func UpdateOpenBotStockSgdTrade(ctx context.Context, price, orderNumber, totalMoney, serviceCost, openMarkerMoney string) models.BotStockSgdTrade {
|
||
|
return models.BotStockSgdTrade{
|
||
|
OpenTime: time.Now(),
|
||
|
DealPrice: price,
|
||
|
ServiceCost: serviceCost,
|
||
|
OrderNumber: orderNumber,
|
||
|
OrderMoney: totalMoney,
|
||
|
MarketMoney: openMarkerMoney,
|
||
|
Status: flags.PositionStatus,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateOpenBotStockEurTrade
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param price
|
||
|
// @param orderNumber
|
||
|
// @param totalMoney
|
||
|
// @param serviceCost
|
||
|
// @param openMarkerMoney
|
||
|
// @return models.BotStockEurTrade
|
||
|
func UpdateOpenBotStockEurTrade(ctx context.Context, price, orderNumber, totalMoney, serviceCost, openMarkerMoney string) models.BotStockEurTrade {
|
||
|
return models.BotStockEurTrade{
|
||
|
OpenTime: time.Now(),
|
||
|
DealPrice: price,
|
||
|
ServiceCost: serviceCost,
|
||
|
OrderNumber: orderNumber,
|
||
|
OrderMoney: totalMoney,
|
||
|
MarketMoney: openMarkerMoney,
|
||
|
Status: flags.PositionStatus,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateOpenBotStockBrlTrade
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param price
|
||
|
// @param orderNumber
|
||
|
// @param totalMoney
|
||
|
// @param serviceCost
|
||
|
// @param openMarkerMoney
|
||
|
// @return models.BotStockBrlTrade
|
||
|
func UpdateOpenBotStockBrlTrade(ctx context.Context, price, orderNumber, totalMoney, serviceCost, openMarkerMoney string) models.BotStockBrlTrade {
|
||
|
return models.BotStockBrlTrade{
|
||
|
OpenTime: time.Now(),
|
||
|
DealPrice: price,
|
||
|
ServiceCost: serviceCost,
|
||
|
OrderNumber: orderNumber,
|
||
|
OrderMoney: totalMoney,
|
||
|
MarketMoney: openMarkerMoney,
|
||
|
Status: flags.PositionStatus,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateOpenBotStockFurTrade
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param price
|
||
|
// @param orderNumber
|
||
|
// @param totalMoney
|
||
|
// @param serviceCost
|
||
|
// @param openMarkerMoney
|
||
|
// @return models.BotStockFurTrade
|
||
|
func UpdateOpenBotStockFurTrade(ctx context.Context, price, orderNumber, totalMoney, serviceCost, openMarkerMoney string) models.BotStockFurTrade {
|
||
|
return models.BotStockFurTrade{
|
||
|
OpenTime: time.Now(),
|
||
|
DealPrice: price,
|
||
|
ServiceCost: serviceCost,
|
||
|
OrderNumber: orderNumber,
|
||
|
OrderMoney: totalMoney,
|
||
|
MarketMoney: openMarkerMoney,
|
||
|
Status: flags.PositionStatus,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateOpenBotStockJpyTrade
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param price
|
||
|
// @param orderNumber
|
||
|
// @param totalMoney
|
||
|
// @param serviceCost
|
||
|
// @param openMarkerMoney
|
||
|
// @return models.BotStockJpTrade
|
||
|
func UpdateOpenBotStockJpyTrade(ctx context.Context, price, orderNumber, totalMoney, serviceCost, openMarkerMoney string) models.BotStockJpTrade {
|
||
|
return models.BotStockJpTrade{
|
||
|
OpenTime: time.Now(),
|
||
|
DealPrice: price,
|
||
|
ServiceCost: serviceCost,
|
||
|
OrderNumber: orderNumber,
|
||
|
OrderMoney: totalMoney,
|
||
|
MarketMoney: openMarkerMoney,
|
||
|
Status: flags.PositionStatus,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateCloseBotStockThaTrade
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param price
|
||
|
// @param totalMoney
|
||
|
// @param serviceCost
|
||
|
// @return models.BotStockThaTrade
|
||
|
func UpdateCloseBotStockThaTrade(ctx context.Context, price, serviceCost string) models.BotStockThaTrade {
|
||
|
return models.BotStockThaTrade{
|
||
|
ClosingTime: time.Now(),
|
||
|
ClosingPrice: price,
|
||
|
ClosingCost: serviceCost,
|
||
|
Status: flags.CloseStatus,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateCloseBotStockSgdTrade
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param price
|
||
|
// @param serviceCost
|
||
|
// @return models.BotStockSgdTrade
|
||
|
func UpdateCloseBotStockSgdTrade(ctx context.Context, price, serviceCost string) models.BotStockSgdTrade {
|
||
|
return models.BotStockSgdTrade{
|
||
|
ClosingTime: time.Now(),
|
||
|
ClosingPrice: price,
|
||
|
ClosingCost: serviceCost,
|
||
|
Status: flags.CloseStatus,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateCloseBotStockEurTrade
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param price
|
||
|
// @param serviceCost
|
||
|
// @return models.BotStockEurTrade
|
||
|
func UpdateCloseBotStockEurTrade(ctx context.Context, price, serviceCost string) models.BotStockEurTrade {
|
||
|
return models.BotStockEurTrade{
|
||
|
ClosingTime: time.Now(),
|
||
|
ClosingPrice: price,
|
||
|
ClosingCost: serviceCost,
|
||
|
Status: flags.CloseStatus,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateCloseBotStockBrlTrade
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param price
|
||
|
// @param serviceCost
|
||
|
// @return models.BotStockBrlTrade
|
||
|
func UpdateCloseBotStockBrlTrade(ctx context.Context, price, serviceCost string) models.BotStockBrlTrade {
|
||
|
return models.BotStockBrlTrade{
|
||
|
ClosingTime: time.Now(),
|
||
|
ClosingPrice: price,
|
||
|
ClosingCost: serviceCost,
|
||
|
Status: flags.CloseStatus,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateCloseBotStockFurTrade
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param price
|
||
|
// @param serviceCost
|
||
|
// @return models.BotStockFurTrade
|
||
|
func UpdateCloseBotStockFurTrade(ctx context.Context, price, serviceCost string) models.BotStockFurTrade {
|
||
|
return models.BotStockFurTrade{
|
||
|
ClosingTime: time.Now(),
|
||
|
ClosingPrice: price,
|
||
|
ClosingCost: serviceCost,
|
||
|
Status: flags.CloseStatus,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateCloseBotStockJpyTrade
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param price
|
||
|
// @param serviceCost
|
||
|
// @return models.BotStockJpTrade
|
||
|
func UpdateCloseBotStockJpyTrade(ctx context.Context, price, serviceCost string) models.BotStockJpTrade {
|
||
|
return models.BotStockJpTrade{
|
||
|
ClosingTime: time.Now(),
|
||
|
ClosingPrice: price,
|
||
|
ClosingCost: serviceCost,
|
||
|
Status: flags.CloseStatus,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreatBotUserStockThaLog
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param code
|
||
|
// @param symbol
|
||
|
// @param changeNum
|
||
|
// @param orderId
|
||
|
// @return models.BotUserStockThaLog
|
||
|
func CreatBotUserStockThaLog(ctx context.Context, userId, code int64, symbol, changeNum, orderId string) models.BotUserStockThaLog {
|
||
|
return models.BotUserStockThaLog{
|
||
|
OrderId: orderId,
|
||
|
UserId: int(userId),
|
||
|
ChangeNum: changeNum,
|
||
|
ChangeType: int(code),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
StockId: symbol,
|
||
|
BeforeNum: decimal.Zero.String(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreatBotUserStockEurLog
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param code
|
||
|
// @param symbol
|
||
|
// @param changeNum
|
||
|
// @param orderId
|
||
|
// @return models.BotUserStockEurLog
|
||
|
func CreatBotUserStockEurLog(ctx context.Context, userId, code int64, symbol, changeNum, orderId string) models.BotUserStockEurLog {
|
||
|
return models.BotUserStockEurLog{
|
||
|
OrderId: orderId,
|
||
|
UserId: int(userId),
|
||
|
ChangeNum: changeNum,
|
||
|
ChangeType: int(code),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
StockId: symbol,
|
||
|
BeforeNum: decimal.Zero.String(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreatBotUserStockBrlLog
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param code
|
||
|
// @param symbol
|
||
|
// @param changeNum
|
||
|
// @param orderId
|
||
|
// @return models.BotUserStockBrlLog
|
||
|
func CreatBotUserStockBrlLog(ctx context.Context, userId, code int64, symbol, changeNum, orderId string) models.BotUserStockBrlLog {
|
||
|
return models.BotUserStockBrlLog{
|
||
|
OrderId: orderId,
|
||
|
UserId: int(userId),
|
||
|
ChangeNum: changeNum,
|
||
|
ChangeType: int(code),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
StockId: symbol,
|
||
|
BeforeNum: decimal.Zero.String(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreatBotUserStockFurLog
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param code
|
||
|
// @param symbol
|
||
|
// @param changeNum
|
||
|
// @param orderId
|
||
|
// @return models.BotUserStockFurLog
|
||
|
func CreatBotUserStockFurLog(ctx context.Context, userId, code int64, symbol, changeNum, orderId string) models.BotUserStockFurLog {
|
||
|
return models.BotUserStockFurLog{
|
||
|
OrderId: orderId,
|
||
|
UserId: int(userId),
|
||
|
ChangeNum: changeNum,
|
||
|
ChangeType: int(code),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
StockId: symbol,
|
||
|
BeforeNum: decimal.Zero.String(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreatBotUserStockJpyLog
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param code
|
||
|
// @param symbol
|
||
|
// @param changeNum
|
||
|
// @param orderId
|
||
|
// @return models.BotUserStockJpLog
|
||
|
func CreatBotUserStockJpyLog(ctx context.Context, userId, code int64, symbol, changeNum, orderId string) models.BotUserStockJpLog {
|
||
|
return models.BotUserStockJpLog{
|
||
|
OrderId: orderId,
|
||
|
UserId: int(userId),
|
||
|
ChangeNum: changeNum,
|
||
|
ChangeType: int(code),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
StockId: symbol,
|
||
|
BeforeNum: decimal.Zero.String(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreatBotUserStockSgdLog
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param code
|
||
|
// @param symbol
|
||
|
// @param changeNum
|
||
|
// @param orderId
|
||
|
// @return models.BotUserStockSgdLog
|
||
|
func CreatBotUserStockSgdLog(ctx context.Context, userId, code int64, symbol, changeNum, orderId string) models.BotUserStockSgdLog {
|
||
|
return models.BotUserStockSgdLog{
|
||
|
OrderId: orderId,
|
||
|
UserId: int(userId),
|
||
|
ChangeNum: changeNum,
|
||
|
ChangeType: int(code),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
StockId: symbol,
|
||
|
BeforeNum: decimal.Zero.String(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockThaTradePre
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param orderId
|
||
|
// @param order
|
||
|
// @return models.BotStockThaTrade
|
||
|
func BotStockThaTradePre(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockThaTrade {
|
||
|
if order.StopWinPrice == "" {
|
||
|
order.StopWinPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.StopLossPrice == "" {
|
||
|
order.StopLossPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.MarketPrice == "" {
|
||
|
order.MarketPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.LimitPrice == "" {
|
||
|
order.LimitPrice = decimal.Zero.String()
|
||
|
}
|
||
|
return models.BotStockThaTrade{
|
||
|
UserId: int(userId),
|
||
|
TradeType: int(order.TradeType),
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StockId: order.StockId,
|
||
|
ServiceCost: order.ServiceCost,
|
||
|
MarketPrice: order.MarketPrice,
|
||
|
MarketMoney: order.MarketMoney,
|
||
|
LimitPrice: order.LimitPrice,
|
||
|
DealType: int(order.DealType),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
OrderId: orderId,
|
||
|
Status: flags.PositionStatus,
|
||
|
OpenTime: time.Now(),
|
||
|
DealPrice: order.LimitPrice,
|
||
|
OrderNumber: order.OrderNumber,
|
||
|
OrderMoney: order.MarketMoney,
|
||
|
ClosingCost: decimal.Zero.String(),
|
||
|
OvernightCost: decimal.Zero.String(),
|
||
|
ClosingPrice: decimal.Zero.String(),
|
||
|
PryNum: flags.SetPreOne,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockInTradePre
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param orderId
|
||
|
// @param order
|
||
|
// @return models.BotStockInTrade
|
||
|
func BotStockInTradePre(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockInTrade {
|
||
|
if order.StopLossPrice == "" {
|
||
|
order.StopLossPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.StopWinPrice == "" {
|
||
|
order.StopWinPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.MarketPrice == "" {
|
||
|
order.MarketPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.LimitPrice == "" {
|
||
|
order.LimitPrice = decimal.Zero.String()
|
||
|
}
|
||
|
return models.BotStockInTrade{
|
||
|
UserId: int(userId),
|
||
|
TradeType: int(order.TradeType),
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StockId: order.StockId,
|
||
|
ServiceCost: order.ServiceCost,
|
||
|
MarketPrice: order.MarketPrice,
|
||
|
MarketMoney: order.MarketMoney,
|
||
|
LimitPrice: order.LimitPrice,
|
||
|
DealType: int(order.DealType),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
OrderId: orderId,
|
||
|
Status: flags.PositionStatus,
|
||
|
OpenTime: time.Now(),
|
||
|
DealPrice: order.LimitPrice,
|
||
|
OrderNumber: order.OrderNumber,
|
||
|
OrderMoney: order.MarketMoney,
|
||
|
OvernightCost: decimal.Zero.String(),
|
||
|
ClosingCost: decimal.Zero.String(),
|
||
|
ClosingPrice: decimal.Zero.String(),
|
||
|
PryNum: flags.SetPreOne,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockSgdTradePre
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param orderId
|
||
|
// @param order
|
||
|
// @return models.BotStockSgdTrade
|
||
|
func BotStockSgdTradePre(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockSgdTrade {
|
||
|
if order.StopLossPrice == "" {
|
||
|
order.StopLossPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.StopWinPrice == "" {
|
||
|
order.StopWinPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.MarketPrice == "" {
|
||
|
order.MarketPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.LimitPrice == "" {
|
||
|
order.LimitPrice = decimal.Zero.String()
|
||
|
}
|
||
|
return models.BotStockSgdTrade{
|
||
|
UserId: int(userId),
|
||
|
TradeType: int(order.TradeType),
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StockId: order.StockId,
|
||
|
ServiceCost: order.ServiceCost,
|
||
|
MarketPrice: order.MarketPrice,
|
||
|
MarketMoney: order.MarketMoney,
|
||
|
LimitPrice: order.LimitPrice,
|
||
|
DealType: int(order.DealType),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
OrderId: orderId,
|
||
|
Status: flags.PositionStatus,
|
||
|
OpenTime: time.Now(),
|
||
|
DealPrice: order.LimitPrice,
|
||
|
OrderNumber: order.OrderNumber,
|
||
|
OrderMoney: order.MarketMoney,
|
||
|
OvernightCost: decimal.Zero.String(),
|
||
|
ClosingCost: decimal.Zero.String(),
|
||
|
ClosingPrice: decimal.Zero.String(),
|
||
|
PryNum: flags.SetPreOne,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockGbxTradePre
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param orderId
|
||
|
// @param order
|
||
|
// @return models.BotStockGbxTrade
|
||
|
func BotStockGbxTradePre(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockGbxTrade {
|
||
|
if order.StopLossPrice == "" {
|
||
|
order.StopLossPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.StopWinPrice == "" {
|
||
|
order.StopWinPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.MarketPrice == "" {
|
||
|
order.MarketPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.LimitPrice == "" {
|
||
|
order.LimitPrice = decimal.Zero.String()
|
||
|
}
|
||
|
return models.BotStockGbxTrade{
|
||
|
UserId: int(userId),
|
||
|
TradeType: int(order.TradeType),
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StockId: order.StockId,
|
||
|
ServiceCost: order.ServiceCost,
|
||
|
MarketPrice: order.MarketPrice,
|
||
|
MarketMoney: order.MarketMoney,
|
||
|
LimitPrice: order.LimitPrice,
|
||
|
DealType: int(order.DealType),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
OrderId: orderId,
|
||
|
Status: flags.PositionStatus,
|
||
|
OpenTime: time.Now(),
|
||
|
DealPrice: order.LimitPrice,
|
||
|
OrderNumber: order.OrderNumber,
|
||
|
OrderMoney: order.MarketMoney,
|
||
|
OvernightCost: decimal.Zero.String(),
|
||
|
ClosingCost: decimal.Zero.String(),
|
||
|
ClosingPrice: decimal.Zero.String(),
|
||
|
PryNum: flags.SetPreOne,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockEurTradePre
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param orderId
|
||
|
// @param order
|
||
|
// @return models.BotStockEurTrade
|
||
|
func BotStockEurTradePre(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockEurTrade {
|
||
|
if order.StopLossPrice == "" {
|
||
|
order.StopLossPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.StopWinPrice == "" {
|
||
|
order.StopWinPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.MarketPrice == "" {
|
||
|
order.MarketPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.LimitPrice == "" {
|
||
|
order.LimitPrice = decimal.Zero.String()
|
||
|
}
|
||
|
return models.BotStockEurTrade{
|
||
|
UserId: int(userId),
|
||
|
TradeType: int(order.TradeType),
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StockId: order.StockId,
|
||
|
ServiceCost: order.ServiceCost,
|
||
|
MarketPrice: order.MarketPrice,
|
||
|
MarketMoney: order.MarketMoney,
|
||
|
LimitPrice: order.LimitPrice,
|
||
|
DealType: int(order.DealType),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
OrderId: orderId,
|
||
|
Status: flags.PositionStatus,
|
||
|
OpenTime: time.Now(),
|
||
|
DealPrice: order.LimitPrice,
|
||
|
OrderNumber: order.OrderNumber,
|
||
|
OrderMoney: order.MarketMoney,
|
||
|
OvernightCost: decimal.Zero.String(),
|
||
|
ClosingCost: decimal.Zero.String(),
|
||
|
ClosingPrice: decimal.Zero.String(),
|
||
|
PryNum: flags.SetPreOne,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockBrlTradePre
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param orderId
|
||
|
// @param order
|
||
|
// @return models.BotStockBrlTrade
|
||
|
func BotStockBrlTradePre(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockBrlTrade {
|
||
|
if order.StopLossPrice == "" {
|
||
|
order.StopLossPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.StopWinPrice == "" {
|
||
|
order.StopWinPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.MarketPrice == "" {
|
||
|
order.MarketPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.LimitPrice == "" {
|
||
|
order.LimitPrice = decimal.Zero.String()
|
||
|
}
|
||
|
return models.BotStockBrlTrade{
|
||
|
UserId: int(userId),
|
||
|
TradeType: int(order.TradeType),
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StockId: order.StockId,
|
||
|
ServiceCost: order.ServiceCost,
|
||
|
MarketPrice: order.MarketPrice,
|
||
|
MarketMoney: order.MarketMoney,
|
||
|
LimitPrice: order.LimitPrice,
|
||
|
DealType: int(order.DealType),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
OrderId: orderId,
|
||
|
Status: flags.PositionStatus,
|
||
|
OpenTime: time.Now(),
|
||
|
DealPrice: order.LimitPrice,
|
||
|
OrderNumber: order.OrderNumber,
|
||
|
OrderMoney: order.MarketMoney,
|
||
|
OvernightCost: decimal.Zero.String(),
|
||
|
ClosingCost: decimal.Zero.String(),
|
||
|
ClosingPrice: decimal.Zero.String(),
|
||
|
PryNum: flags.SetPreOne,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockFurTradePre
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param orderId
|
||
|
// @param order
|
||
|
// @return models.BotStockFurTrade
|
||
|
func BotStockFurTradePre(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockFurTrade {
|
||
|
if order.StopLossPrice == "" {
|
||
|
order.StopLossPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.StopWinPrice == "" {
|
||
|
order.StopWinPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.MarketPrice == "" {
|
||
|
order.MarketPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.LimitPrice == "" {
|
||
|
order.LimitPrice = decimal.Zero.String()
|
||
|
}
|
||
|
return models.BotStockFurTrade{
|
||
|
UserId: int(userId),
|
||
|
TradeType: int(order.TradeType),
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StockId: order.StockId,
|
||
|
ServiceCost: order.ServiceCost,
|
||
|
MarketPrice: order.MarketPrice,
|
||
|
MarketMoney: order.MarketMoney,
|
||
|
LimitPrice: order.LimitPrice,
|
||
|
DealType: int(order.DealType),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
OrderId: orderId,
|
||
|
Status: flags.PositionStatus,
|
||
|
OpenTime: time.Now(),
|
||
|
DealPrice: order.LimitPrice,
|
||
|
OrderNumber: order.OrderNumber,
|
||
|
OrderMoney: order.MarketMoney,
|
||
|
OvernightCost: decimal.Zero.String(),
|
||
|
ClosingCost: decimal.Zero.String(),
|
||
|
ClosingPrice: decimal.Zero.String(),
|
||
|
PryNum: flags.SetPreOne,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockJpyTradePre
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param orderId
|
||
|
// @param order
|
||
|
// @return models.BotStockJpTrade
|
||
|
func BotStockJpyTradePre(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockJpTrade {
|
||
|
if order.StopLossPrice == "" {
|
||
|
order.StopLossPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.StopWinPrice == "" {
|
||
|
order.StopWinPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.MarketPrice == "" {
|
||
|
order.MarketPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.LimitPrice == "" {
|
||
|
order.LimitPrice = decimal.Zero.String()
|
||
|
}
|
||
|
return models.BotStockJpTrade{
|
||
|
UserId: int(userId),
|
||
|
TradeType: int(order.TradeType),
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StockId: order.StockId,
|
||
|
ServiceCost: order.ServiceCost,
|
||
|
MarketPrice: order.MarketPrice,
|
||
|
MarketMoney: order.MarketMoney,
|
||
|
LimitPrice: order.LimitPrice,
|
||
|
DealType: int(order.DealType),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
OrderId: orderId,
|
||
|
Status: flags.PositionStatus,
|
||
|
OpenTime: time.Now(),
|
||
|
DealPrice: order.LimitPrice,
|
||
|
OrderNumber: order.OrderNumber,
|
||
|
OrderMoney: order.MarketMoney,
|
||
|
OvernightCost: decimal.Zero.String(),
|
||
|
ClosingCost: decimal.Zero.String(),
|
||
|
ClosingPrice: decimal.Zero.String(),
|
||
|
PryNum: flags.SetPreOne,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockHkdTradePre
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param orderId
|
||
|
// @param order
|
||
|
// @return models.BotStockHkdTrade
|
||
|
func BotStockHkdTradePre(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockHkdTrade {
|
||
|
if order.StopLossPrice == "" {
|
||
|
order.StopLossPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.StopWinPrice == "" {
|
||
|
order.StopWinPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.MarketPrice == "" {
|
||
|
order.MarketPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.LimitPrice == "" {
|
||
|
order.LimitPrice = decimal.Zero.String()
|
||
|
}
|
||
|
return models.BotStockHkdTrade{
|
||
|
UserId: int(userId),
|
||
|
TradeType: int(order.TradeType),
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StockId: order.StockId,
|
||
|
ServiceCost: order.ServiceCost,
|
||
|
MarketPrice: order.MarketPrice,
|
||
|
MarketMoney: order.MarketMoney,
|
||
|
LimitPrice: order.LimitPrice,
|
||
|
DealType: int(order.DealType),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
OrderId: orderId,
|
||
|
Status: flags.PositionStatus,
|
||
|
OpenTime: time.Now(),
|
||
|
DealPrice: order.LimitPrice,
|
||
|
OrderNumber: order.OrderNumber,
|
||
|
OrderMoney: order.MarketMoney,
|
||
|
OvernightCost: decimal.Zero.String(),
|
||
|
ClosingCost: decimal.Zero.String(),
|
||
|
ClosingPrice: decimal.Zero.String(),
|
||
|
PryNum: flags.SetPreOne,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotDigitalTrade (现货(下单|平仓)操作)
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param orderId
|
||
|
// @param order
|
||
|
// @return models.BotDigitalTrade
|
||
|
func BotDigitalTrade(ctx context.Context, userId int64, orderId string, order structure.SpotsOrder) models.BotDigitalTrade {
|
||
|
marketPrice := decimal.RequireFromString(order.OrderMoney)
|
||
|
cost := decimal.RequireFromString(order.ServiceCost)
|
||
|
// total order Money
|
||
|
orderMoney := marketPrice.Add(cost)
|
||
|
|
||
|
if order.MarketPrice == "" {
|
||
|
order.MarketPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.LimitPrice == "" {
|
||
|
order.LimitPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.MarketPrice == "" {
|
||
|
order.MarketPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.LimitPrice == "" {
|
||
|
order.LimitPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.DealPrice == "" {
|
||
|
order.DealPrice = decimal.Zero.String()
|
||
|
}
|
||
|
|
||
|
return models.BotDigitalTrade{
|
||
|
UserId: int(userId),
|
||
|
UpdateTime: time.Now(),
|
||
|
TradeType: int(order.TradeType),
|
||
|
TotalMoney: orderMoney.String(),
|
||
|
Status: flags.EntrustStatus,
|
||
|
ServiceCost: order.ServiceCost,
|
||
|
OrderNumber: order.OrderNumber,
|
||
|
OrderMoney: order.OrderMoney,
|
||
|
OrderId: orderId,
|
||
|
MarketPrice: order.MarketPrice,
|
||
|
LimitPrice: order.LimitPrice,
|
||
|
DigitalId: order.DigitalId,
|
||
|
DealType: int(order.DealType),
|
||
|
DealPrice: order.DealPrice,
|
||
|
CreateTime: time.Now(),
|
||
|
ClosingCost: decimal.Zero.String(),
|
||
|
OvernightCost: decimal.Zero.String(),
|
||
|
ClosingPrice: decimal.Zero.String(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateBotDigitalCancelByOrderId
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @return models.BotDigitalTrade
|
||
|
func UpdateBotDigitalCancelByOrderId(ctx context.Context) models.BotDigitalTrade {
|
||
|
return models.BotDigitalTrade{
|
||
|
Status: flags.CancelStatus,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateBotDigitalStatusByOrderId
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param closingPrice
|
||
|
// @param closingCost
|
||
|
// @param orderMoneyPrice
|
||
|
// @param totalMoneyPrice
|
||
|
// @param OrderNumber
|
||
|
// @return models.BotDigitalTrade
|
||
|
func UpdateBotDigitalStatusByOrderId(ctx context.Context, closingPrice, closingCost, orderMoneyPrice, totalMoneyPrice, OrderNumber string) models.BotDigitalTrade {
|
||
|
return models.BotDigitalTrade{
|
||
|
Status: flags.CloseStatus,
|
||
|
ClosingPrice: closingPrice,
|
||
|
ClosingCost: closingCost,
|
||
|
OrderMoney: orderMoneyPrice,
|
||
|
TotalMoney: totalMoneyPrice,
|
||
|
OrderNumber: OrderNumber,
|
||
|
ClosingTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
func UpdateBotMoneyStatusByOrderId(ctx context.Context, closingPrice, closingCost, orderMoneyPrice, totalMoneyPrice, OrderNumber string) models.BotMoneyTrade {
|
||
|
return models.BotMoneyTrade{
|
||
|
Status: flags.CloseStatus,
|
||
|
ClosingPrice: closingPrice,
|
||
|
ClosingCost: closingCost,
|
||
|
OrderMoney: orderMoneyPrice,
|
||
|
OrderNumber: OrderNumber,
|
||
|
ClosingTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateBotUserDigital
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserDigital
|
||
|
func UpdateBotUserDigital(ctx context.Context, usableNum, frozenNum string) models.BotUserDigital {
|
||
|
return models.BotUserDigital{
|
||
|
UpdateTime: time.Now(),
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
}
|
||
|
}
|
||
|
func UpdateBotUserMoneySpots(ctx context.Context, usableNum, frozenNum string) models.BotUserMoney {
|
||
|
return models.BotUserMoney{
|
||
|
UpdateTime: time.Now(),
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateBotUserDigitalByUsableNum
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param usableNum
|
||
|
// @return models.BotUserDigital
|
||
|
func UpdateBotUserDigitalByUsableNum(ctx context.Context, usableNum string) models.BotUserDigital {
|
||
|
return models.BotUserDigital{
|
||
|
UpdateTime: time.Now(),
|
||
|
UsableNum: usableNum,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateBotUserDigitalByFrozenNum
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserDigital
|
||
|
func UpdateBotUserDigitalByFrozenNum(ctx context.Context, frozenNum string) models.BotUserDigital {
|
||
|
return models.BotUserDigital{
|
||
|
UpdateTime: time.Now(),
|
||
|
FrozenNum: frozenNum,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreatBotUserBrokerage
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param backType
|
||
|
// @param userId
|
||
|
// @param LevelType
|
||
|
// @param fee
|
||
|
// @param brokerageNum
|
||
|
// @param orderId
|
||
|
// @return models.BotUserBrokerage
|
||
|
func CreatBotUserBrokerage(ctx context.Context, backType, userId, LevelType int, fee, brokerageNum, orderId string) models.BotUserBrokerage {
|
||
|
return models.BotUserBrokerage{
|
||
|
OrderId: orderId,
|
||
|
BackType: backType,
|
||
|
UserId: userId,
|
||
|
LevelType: LevelType,
|
||
|
CreateTime: time.Now(),
|
||
|
ServiceFee: fee,
|
||
|
BrokerageNum: brokerageNum,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreatBotTradeFee
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param code
|
||
|
// @param marketCode
|
||
|
// @param fee
|
||
|
// @param orderId
|
||
|
// @return models.BotTradeFee
|
||
|
func CreatBotTradeFee(ctx context.Context, userId, code, marketCode int, fee, orderId string) models.BotTradeFee {
|
||
|
return models.BotTradeFee{
|
||
|
AccountType: code,
|
||
|
CreateTime: time.Now(),
|
||
|
ServiceFee: fee,
|
||
|
TradeNo: orderId,
|
||
|
TradeType: marketCode,
|
||
|
UserId: userId,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotUserDigital
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @param order
|
||
|
// @return models.BotUserDigital
|
||
|
func BotUserDigital(ctx context.Context, userId int64, usableNum, frozenNum string, order structure.SpotsOrder) models.BotUserDigital {
|
||
|
return models.BotUserDigital{
|
||
|
UserId: int(userId),
|
||
|
DigitalId: order.DigitalId,
|
||
|
FrozenNum: frozenNum,
|
||
|
UsableNum: usableNum,
|
||
|
UpdateTime: time.Now(),
|
||
|
CreateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
func BotUserMoneySpots(ctx context.Context, userId int64, usableNum, frozenNum string, order structure.MoneyOrder) models.BotUserMoney {
|
||
|
return models.BotUserMoney{
|
||
|
UserId: int(userId),
|
||
|
StockId: order.StockId,
|
||
|
FrozenNum: frozenNum,
|
||
|
UsableNum: usableNum,
|
||
|
UpdateTime: time.Now(),
|
||
|
CreateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreatBotUserDigitalLog
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param code
|
||
|
// @param symbol
|
||
|
// @param changeNum
|
||
|
// @param orderId
|
||
|
// @return models.BotUserDigitalLog
|
||
|
func CreatBotUserDigitalLog(ctx context.Context, userId, code int64, symbol, changeNum, orderId string) models.BotUserDigitalLog {
|
||
|
return models.BotUserDigitalLog{
|
||
|
OrderId: orderId,
|
||
|
UserId: int(userId),
|
||
|
BeforeNum: decimal.Zero.String(),
|
||
|
ChangeNum: changeNum,
|
||
|
ChangeType: int(code),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
DigitalId: symbol,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotContractTrade (合约下单|设置止损止盈|撤单|平仓)
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param orderId
|
||
|
// @param order
|
||
|
// @return models.BotContractTrade
|
||
|
func BotContractTrade(ctx context.Context, userId int64, orderId string, order structure.ContractOrder) models.BotContractTrade {
|
||
|
marketPrice := decimal.RequireFromString(order.OrderAmount)
|
||
|
cost := decimal.RequireFromString(order.ServiceCost)
|
||
|
pryNum := decimal.RequireFromString(order.PryNum).IntPart()
|
||
|
|
||
|
state := 0
|
||
|
if order.Time > 0 {
|
||
|
state = 1
|
||
|
}
|
||
|
|
||
|
// total order Money
|
||
|
orderMoney := marketPrice.Add(cost)
|
||
|
|
||
|
if order.StopWinPrice == "" {
|
||
|
order.StopWinPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.StopLossPrice == "" {
|
||
|
order.StopLossPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.MarketPrice == "" {
|
||
|
order.MarketPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.LimitPrice == "" {
|
||
|
order.LimitPrice = decimal.Zero.String()
|
||
|
}
|
||
|
|
||
|
return models.BotContractTrade{
|
||
|
UserId: int(userId),
|
||
|
UpdateTime: time.Now(),
|
||
|
TradeType: int(order.TradeType),
|
||
|
TotalMoney: orderMoney.String(),
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
Status: flags.EntrustStatus,
|
||
|
ServiceCost: order.ServiceCost,
|
||
|
OrderNumber: order.OrderNumber,
|
||
|
OrderMoney: order.EarnestMoney,
|
||
|
OrderId: orderId,
|
||
|
MarketPrice: order.MarketPrice,
|
||
|
LimitPrice: order.LimitPrice,
|
||
|
EarnestMoney: order.EarnestMoney,
|
||
|
DealType: int(order.DealType),
|
||
|
CreateTime: time.Now(),
|
||
|
ContractId: order.ContractId,
|
||
|
FaceValue: order.System.FaceValue.IntPart(),
|
||
|
PryNum: int(pryNum),
|
||
|
ClosingCost: decimal.Zero.String(),
|
||
|
OvernightCost: decimal.Zero.String(),
|
||
|
ClosingPrice: decimal.Zero.String(),
|
||
|
DealPrice: decimal.Zero.String(),
|
||
|
SecondTime: int(order.Time),
|
||
|
State: state,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotForexTrade
|
||
|
//
|
||
|
// @Description: (外汇下单|设置止损止盈|撤单|平仓)
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param orderId
|
||
|
// @param order
|
||
|
// @return models.BotForexTrade
|
||
|
func BotForexTrade(ctx context.Context, userId int64, orderId string, order structure.ForexOrder) models.BotForexTrade {
|
||
|
marketPrice := decimal.RequireFromString(order.OrderAmount)
|
||
|
cost := decimal.RequireFromString(order.ServiceCost)
|
||
|
pryNum := decimal.RequireFromString(order.PryNum).IntPart()
|
||
|
|
||
|
state := 0
|
||
|
if order.Time > 0 {
|
||
|
state = 1
|
||
|
}
|
||
|
|
||
|
// total order Money
|
||
|
orderMoney := marketPrice.Add(cost)
|
||
|
|
||
|
if order.StopWinPrice == "" {
|
||
|
order.StopWinPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.StopLossPrice == "" {
|
||
|
order.StopLossPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.MarketPrice == "" {
|
||
|
order.MarketPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.LimitPrice == "" {
|
||
|
order.LimitPrice = decimal.Zero.String()
|
||
|
}
|
||
|
|
||
|
return models.BotForexTrade{
|
||
|
UserId: int(userId),
|
||
|
UpdateTime: time.Now(),
|
||
|
TradeType: int(order.TradeType),
|
||
|
TotalMoney: orderMoney.String(),
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
Status: flags.EntrustStatus,
|
||
|
ServiceCost: order.ServiceCost,
|
||
|
OrderNumber: order.OrderNumber,
|
||
|
OrderMoney: order.EarnestMoney,
|
||
|
OrderId: orderId,
|
||
|
MarketPrice: order.MarketPrice,
|
||
|
LimitPrice: order.LimitPrice,
|
||
|
EarnestMoney: order.EarnestMoney,
|
||
|
DealType: int(order.DealType),
|
||
|
CreateTime: time.Now(),
|
||
|
ContractId: order.ForexId,
|
||
|
FaceValue: order.System.FaceValue.IntPart(),
|
||
|
PryNum: int(pryNum),
|
||
|
ClosingCost: decimal.Zero.String(),
|
||
|
OvernightCost: decimal.Zero.String(),
|
||
|
ClosingPrice: decimal.Zero.String(),
|
||
|
DealPrice: decimal.Zero.String(),
|
||
|
SecondTime: int(order.Time),
|
||
|
State: state,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotMoneyTrade
|
||
|
//
|
||
|
// @Description: (综合(现货|合约|外汇)下单|设置止损止盈|撤单|平仓)
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param orderId
|
||
|
// @param order
|
||
|
// @return models.BotMoneyTrade
|
||
|
func BotMoneyTrade(ctx context.Context, userId int64, orderId string, order structure.MoneyOrder) models.BotMoneyTrade {
|
||
|
marketPrice := decimal.RequireFromString(order.OrderAmount)
|
||
|
cost := decimal.RequireFromString(order.ServiceCost)
|
||
|
pryNum := decimal.RequireFromString(order.PryNum).IntPart()
|
||
|
|
||
|
// total order Money
|
||
|
orderMoney := marketPrice.Add(cost)
|
||
|
|
||
|
if order.StopWinPrice == "" {
|
||
|
order.StopWinPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.StopLossPrice == "" {
|
||
|
order.StopLossPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.MarketPrice == "" {
|
||
|
order.MarketPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.LimitPrice == "" {
|
||
|
order.LimitPrice = decimal.Zero.String()
|
||
|
}
|
||
|
|
||
|
return models.BotMoneyTrade{
|
||
|
UserId: int(userId),
|
||
|
UpdateTime: time.Now(),
|
||
|
TradeType: int(order.TradeType),
|
||
|
MarketMoney: order.EarnestMoney,
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
Status: flags.EntrustStatus,
|
||
|
ServiceCost: order.ServiceCost,
|
||
|
OrderNumber: order.OrderNumber,
|
||
|
OrderMoney: orderMoney.String(),
|
||
|
OrderId: orderId,
|
||
|
MarketPrice: order.MarketPrice,
|
||
|
LimitPrice: order.LimitPrice,
|
||
|
DealType: int(order.DealType),
|
||
|
CreateTime: time.Now(),
|
||
|
StockId: order.StockId,
|
||
|
FaceValue: 1,
|
||
|
PryNum: int(pryNum),
|
||
|
ClosingCost: decimal.Zero.String(),
|
||
|
OvernightCost: decimal.Zero.String(),
|
||
|
ClosingPrice: decimal.Zero.String(),
|
||
|
DealPrice: decimal.Zero.String(),
|
||
|
MarketType: int(order.Type),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotContractSecTrade (秒合约下单|设置止损止盈|撤单|平仓)
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param orderId
|
||
|
// @param order
|
||
|
// @return models.BotContractSecTrade
|
||
|
func BotContractSecTrade(ctx context.Context, userId int64, orderId string, order structure.ContractOrder) models.BotContractSecTrade {
|
||
|
marketPrice := decimal.RequireFromString(order.OrderAmount)
|
||
|
cost := decimal.RequireFromString(order.ServiceCost)
|
||
|
pryNum := decimal.RequireFromString(order.PryNum).IntPart()
|
||
|
|
||
|
state := 0
|
||
|
if order.Time > 0 {
|
||
|
state = 1
|
||
|
}
|
||
|
|
||
|
// total order Money
|
||
|
orderMoney := marketPrice.Add(cost)
|
||
|
|
||
|
if order.StopWinPrice == "" {
|
||
|
order.StopWinPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.StopLossPrice == "" {
|
||
|
order.StopLossPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.MarketPrice == "" {
|
||
|
order.MarketPrice = decimal.Zero.String()
|
||
|
}
|
||
|
if order.LimitPrice == "" {
|
||
|
order.LimitPrice = decimal.Zero.String()
|
||
|
}
|
||
|
|
||
|
return models.BotContractSecTrade{
|
||
|
UserId: int(userId),
|
||
|
UpdateTime: time.Now(),
|
||
|
TradeType: int(order.TradeType),
|
||
|
TotalMoney: orderMoney.String(),
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
Status: flags.EntrustStatus,
|
||
|
ServiceCost: order.ServiceCost,
|
||
|
OrderNumber: order.OrderNumber,
|
||
|
OrderMoney: order.EarnestMoney,
|
||
|
OrderId: orderId,
|
||
|
MarketPrice: order.MarketPrice,
|
||
|
LimitPrice: order.LimitPrice,
|
||
|
EarnestMoney: order.EarnestMoney,
|
||
|
DealType: int(order.DealType),
|
||
|
CreateTime: time.Now(),
|
||
|
ContractId: order.ContractId,
|
||
|
FaceValue: order.System.FaceValue.IntPart(),
|
||
|
PryNum: int(pryNum),
|
||
|
ClosingCost: decimal.Zero.String(),
|
||
|
OvernightCost: decimal.Zero.String(),
|
||
|
ClosingPrice: decimal.Zero.String(),
|
||
|
DealPrice: decimal.Zero.String(),
|
||
|
SecondTime: int(order.Time),
|
||
|
State: state,
|
||
|
OrderStatus: 0,
|
||
|
OrderValue: decimal.Zero.String(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateOpenBotContractTrade
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param price
|
||
|
// @param orderNumber
|
||
|
// @param totalMoney
|
||
|
// @param serviceCost
|
||
|
// @return models.BotContractTrade
|
||
|
func UpdateOpenBotContractTrade(ctx context.Context, price, orderNumber, totalMoney, serviceCost string) models.BotContractTrade {
|
||
|
return models.BotContractTrade{
|
||
|
OpenTime: time.Now(),
|
||
|
DealPrice: price,
|
||
|
ServiceCost: serviceCost,
|
||
|
OrderNumber: orderNumber,
|
||
|
TotalMoney: totalMoney,
|
||
|
Status: flags.PositionStatus,
|
||
|
}
|
||
|
}
|
||
|
func UpdateOpenBotForexTrade(ctx context.Context, price, orderNumber, totalMoney, serviceCost string) models.BotForexTrade {
|
||
|
return models.BotForexTrade{
|
||
|
OpenTime: time.Now(),
|
||
|
DealPrice: price,
|
||
|
ServiceCost: serviceCost,
|
||
|
OrderNumber: orderNumber,
|
||
|
TotalMoney: totalMoney,
|
||
|
Status: flags.PositionStatus,
|
||
|
}
|
||
|
}
|
||
|
func UpdateOpenBotMoneyTrade(ctx context.Context, price, orderNumber, totalMoney, serviceCost string) models.BotMoneyTrade {
|
||
|
return models.BotMoneyTrade{
|
||
|
OpenTime: time.Now(),
|
||
|
DealPrice: price,
|
||
|
ServiceCost: serviceCost,
|
||
|
OrderNumber: orderNumber,
|
||
|
OrderMoney: totalMoney,
|
||
|
Status: flags.PositionStatus,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateOpenBotContractSecTrade
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param price
|
||
|
// @param orderNumber
|
||
|
// @param totalMoney
|
||
|
// @param serviceCost
|
||
|
// @return models.BotContractTrade
|
||
|
func UpdateOpenBotContractSecTrade(ctx context.Context, price, orderNumber, totalMoney, serviceCost string) models.BotContractSecTrade {
|
||
|
return models.BotContractSecTrade{
|
||
|
OpenTime: time.Now(),
|
||
|
DealPrice: price,
|
||
|
ServiceCost: serviceCost,
|
||
|
OrderNumber: orderNumber,
|
||
|
TotalMoney: totalMoney,
|
||
|
Status: flags.PositionStatus,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateCloseBotContractTrade
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param price
|
||
|
// @param earnestMoney
|
||
|
// @param totalMoney
|
||
|
// @param serviceCost
|
||
|
// @return models.BotContractTrade
|
||
|
func UpdateCloseBotContractTrade(ctx context.Context, price, earnestMoney, totalMoney, serviceCost string) models.BotContractTrade {
|
||
|
return models.BotContractTrade{
|
||
|
ClosingTime: time.Now(),
|
||
|
ClosingPrice: price,
|
||
|
EarnestMoney: earnestMoney,
|
||
|
TotalMoney: totalMoney,
|
||
|
ClosingCost: serviceCost,
|
||
|
Status: flags.CloseStatus,
|
||
|
}
|
||
|
}
|
||
|
func UpdateCloseBotForexTrade(ctx context.Context, price, earnestMoney, totalMoney, serviceCost string) models.BotForexTrade {
|
||
|
return models.BotForexTrade{
|
||
|
ClosingTime: time.Now(),
|
||
|
ClosingPrice: price,
|
||
|
EarnestMoney: earnestMoney,
|
||
|
TotalMoney: totalMoney,
|
||
|
ClosingCost: serviceCost,
|
||
|
Status: flags.CloseStatus,
|
||
|
}
|
||
|
}
|
||
|
func UpdateCloseBotMoneyTrade(ctx context.Context, price, earnestMoney, totalMoney, serviceCost string, status int) models.BotMoneyTrade {
|
||
|
return models.BotMoneyTrade{
|
||
|
ClosingTime: time.Now(),
|
||
|
ClosingPrice: price,
|
||
|
MarketMoney: earnestMoney,
|
||
|
OrderMoney: totalMoney,
|
||
|
ClosingCost: serviceCost,
|
||
|
Status: status, //flags.CloseStatus,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateCloseBotContractSecTrade
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param price
|
||
|
// @param earnestMoney
|
||
|
// @param totalMoney
|
||
|
// @param serviceCost
|
||
|
// @return models.BotContractSecTrade
|
||
|
func UpdateCloseBotContractSecTrade(ctx context.Context, price, earnestMoney, totalMoney, serviceCost, orderValue string, orderStatus int, closeTime time.Time) models.BotContractSecTrade {
|
||
|
return models.BotContractSecTrade{
|
||
|
ClosingTime: closeTime,
|
||
|
ClosingPrice: price,
|
||
|
EarnestMoney: earnestMoney,
|
||
|
TotalMoney: totalMoney,
|
||
|
ClosingCost: serviceCost,
|
||
|
Status: flags.CloseStatus,
|
||
|
OrderStatus: orderStatus,
|
||
|
OrderValue: orderValue,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotContractStopByOrderId
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param order
|
||
|
// @return models.BotContractTrade
|
||
|
func BotContractStopByOrderId(ctx context.Context, order structure.StopOrder) models.BotContractTrade {
|
||
|
return models.BotContractTrade{
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func BotForexStopByOrderId(ctx context.Context, order structure.StopOrder) models.BotForexTrade {
|
||
|
return models.BotForexTrade{
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
func BotMoneyStopByOrderId(ctx context.Context, order structure.StopOrder) models.BotMoneyTrade {
|
||
|
return models.BotMoneyTrade{
|
||
|
StopType: int(order.StopType),
|
||
|
StopLossPrice: order.StopLossPrice,
|
||
|
StopWinPrice: order.StopWinPrice,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotContractCancelByOrderId
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @return models.BotContractTrade
|
||
|
func BotContractCancelByOrderId(ctx context.Context) models.BotContractTrade {
|
||
|
return models.BotContractTrade{
|
||
|
Status: flags.CancelStatus,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
func BotForexCancelByOrderId(ctx context.Context) models.BotForexTrade {
|
||
|
return models.BotForexTrade{
|
||
|
Status: flags.CancelStatus,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
func BotMoneyCancelByOrderId(ctx context.Context) models.BotMoneyTrade {
|
||
|
return models.BotMoneyTrade{
|
||
|
Status: flags.CancelStatus,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotContractClosingByOrderId
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @return models.BotContractTrade
|
||
|
func BotContractClosingByOrderId(ctx context.Context) models.BotContractTrade {
|
||
|
return models.BotContractTrade{
|
||
|
Status: flags.CloseStatus,
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateBotUserContract
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserContract
|
||
|
func UpdateBotUserContract(ctx context.Context, usableNum, frozenNum string) models.BotUserContract {
|
||
|
return models.BotUserContract{
|
||
|
UpdateTime: time.Now(),
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateBotUserForex
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserForex
|
||
|
func UpdateBotUserForex(ctx context.Context, usableNum, frozenNum string) models.BotUserForex {
|
||
|
return models.BotUserForex{
|
||
|
UpdateTime: time.Now(),
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateBotUserMoney
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserMoney
|
||
|
func UpdateBotUserMoney(ctx context.Context, usableNum, frozenNum string) models.BotUserMoney {
|
||
|
return models.BotUserMoney{
|
||
|
UpdateTime: time.Now(),
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// UpdateBotUserContractSec
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @return models.BotUserContract
|
||
|
func UpdateBotUserContractSec(ctx context.Context, usableNum, frozenNum string) models.BotUserContractSec {
|
||
|
return models.BotUserContractSec{
|
||
|
UpdateTime: time.Now(),
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreatBotUserContract
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param usableNum
|
||
|
// @param frozenNum
|
||
|
// @param order
|
||
|
// @return models.BotUserContract
|
||
|
func CreatBotUserContract(ctx context.Context, userId int64, usableNum, frozenNum string, order structure.ContractOrder) models.BotUserContract {
|
||
|
return models.BotUserContract{
|
||
|
UserId: int(userId),
|
||
|
ContractId: order.ContractId,
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
func CreatBotUserForex(ctx context.Context, userId int64, usableNum, frozenNum string, order structure.ForexOrder) models.BotUserForex {
|
||
|
return models.BotUserForex{
|
||
|
UserId: int(userId),
|
||
|
ContractId: order.ForexId,
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
func CreatBotUserMoney(ctx context.Context, userId int64, usableNum, frozenNum string, order structure.MoneyOrder) models.BotUserMoney {
|
||
|
return models.BotUserMoney{
|
||
|
UserId: int(userId),
|
||
|
StockId: order.StockId,
|
||
|
UsableNum: usableNum,
|
||
|
FrozenNum: frozenNum,
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreatBotUserContractLog
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param code
|
||
|
// @param symbol
|
||
|
// @param changeNum
|
||
|
// @param orderId
|
||
|
// @return models.BotUserContractLog
|
||
|
func CreatBotUserContractLog(ctx context.Context, userId, code int64, symbol, changeNum, orderId string) models.BotUserContractLog {
|
||
|
return models.BotUserContractLog{
|
||
|
OrderId: orderId,
|
||
|
UserId: int(userId),
|
||
|
ChangeNum: changeNum,
|
||
|
ChangeType: int(code),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
ContractId: symbol,
|
||
|
BeforeNum: decimal.Zero.String(),
|
||
|
}
|
||
|
}
|
||
|
func CreatBotUserForexLog(ctx context.Context, userId, code int64, symbol, changeNum, orderId string) models.BotUserForexLog {
|
||
|
return models.BotUserForexLog{
|
||
|
OrderId: orderId,
|
||
|
UserId: int(userId),
|
||
|
ChangeNum: changeNum,
|
||
|
ChangeType: int(code),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
ContractId: symbol,
|
||
|
BeforeNum: decimal.Zero.String(),
|
||
|
}
|
||
|
}
|
||
|
func CreatBotUserMoneyLog(ctx context.Context, userId, code int64, symbol, changeNum, orderId string) models.BotUserMoneyLog {
|
||
|
return models.BotUserMoneyLog{
|
||
|
OrderId: orderId,
|
||
|
UserId: int(userId),
|
||
|
ChangeNum: changeNum,
|
||
|
ChangeType: int(code),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
StockId: symbol,
|
||
|
BeforeNum: decimal.Zero.String(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CreatBotUserContractSecLog
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param ctx
|
||
|
// @param userId
|
||
|
// @param code
|
||
|
// @param symbol
|
||
|
// @param changeNum
|
||
|
// @param orderId
|
||
|
// @return models.BotUserContractLog
|
||
|
func CreatBotUserContractSecLog(ctx context.Context, userId, code int64, symbol, changeNum, orderId string) models.BotUserContractSecLog {
|
||
|
return models.BotUserContractSecLog{
|
||
|
OrderId: orderId,
|
||
|
UserId: int(userId),
|
||
|
ChangeNum: changeNum,
|
||
|
ChangeType: int(code),
|
||
|
CreateTime: time.Now(),
|
||
|
UpdateTime: time.Now(),
|
||
|
ContractId: symbol,
|
||
|
BeforeNum: decimal.Zero.String(),
|
||
|
}
|
||
|
}
|