64 lines
2.0 KiB
Go
64 lines
2.0 KiB
Go
package binanceservice
|
|
|
|
import (
|
|
"fmt"
|
|
"go-admin/common/const/rediskey"
|
|
"go-admin/common/global"
|
|
"go-admin/common/helper"
|
|
"go-admin/models"
|
|
"go-admin/services/cacheservice"
|
|
"testing"
|
|
|
|
"github.com/bytedance/sonic"
|
|
"github.com/go-admin-team/go-admin-core/logger"
|
|
"github.com/go-admin-team/go-admin-core/sdk"
|
|
"gorm.io/driver/mysql"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
func TestFutureJudge(t *testing.T) {
|
|
dsn := "root:123456@tcp(127.0.0.1:3306)/go_exchange_single?charset=utf8mb4&parseTime=True&loc=Local&timeout=1000ms"
|
|
db, _ := gorm.Open(mysql.Open(dsn), &gorm.Config{})
|
|
helper.InitDefaultRedis("127.0.0.1:6379", "", 2)
|
|
helper.InitLockRedisConn("127.0.0.1:6379", "", "2")
|
|
// tradeSet := models.TradeSet{
|
|
// Coin: "ADA",
|
|
// Currency: "USDT",
|
|
// LastPrice: "0.516",
|
|
// }
|
|
|
|
key := fmt.Sprintf(rediskey.FuturesReduceList, global.EXCHANGE_BINANCE)
|
|
item := `{"id":4,"apiId":49,"mainId":1,"pid":1,"symbol":"ADAUSDT","price":"0.5417","side":"SELL","num":"13","orderSn":"397659701065547776"}`
|
|
reduceOrder := ReduceListItem{}
|
|
futApi := FutRestApi{}
|
|
setting, err := cacheservice.GetSystemSetting(db)
|
|
|
|
if err != nil {
|
|
logger.Error("获取系统设置失败")
|
|
return
|
|
}
|
|
if err := sonic.Unmarshal([]byte(item), &reduceOrder); err != nil {
|
|
logger.Error("反序列化失败")
|
|
return
|
|
}
|
|
// JudgeFuturesReduce(tradeSet)
|
|
FuturesReduceTrigger(db, reduceOrder, futApi, setting, key, item, false)
|
|
}
|
|
|
|
// 测试减仓后减仓触发
|
|
func TestFutureReduceReduce(t *testing.T) {
|
|
dsn := "root:123456@tcp(127.0.0.1:3306)/go_exchange_single?charset=utf8mb4&parseTime=True&loc=Local&timeout=1000ms"
|
|
db, _ := gorm.Open(mysql.Open(dsn), &gorm.Config{})
|
|
sdk.Runtime.SetDb("default", db)
|
|
helper.InitDefaultRedis("127.0.0.1:6379", "", 2)
|
|
helper.InitLockRedisConn("127.0.0.1:6379", "", "2")
|
|
tradeSet := models.TradeSet{
|
|
Coin: "ADA",
|
|
Currency: "USDT",
|
|
LastPrice: "0.5307",
|
|
}
|
|
|
|
// JudgeFuturesReduce(tradeSet)
|
|
JudgeFuturesReduce(tradeSet)
|
|
}
|