package bitgetservice

import (
	"go-admin/common/helper"
	"go-admin/config"
	"testing"
	"time"

	"github.com/go-admin-team/go-admin-core/sdk"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

func initSetting() {
	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")
	config.ExtConfig.ProxyUrl = "http://127.0.0.1:7890"
}

func TestBitgetMarketFutureClient_Subscribe(t *testing.T) {
	initSetting()
	// 初始化Bitget合约行情客户端
	bitgetFut := BitgetMarketFutureClient{}

	// 测试用的合约符号列表
	testSymbols := []string{"ETHUSDT"}

	// 调用订阅方法
	err := bitgetFut.Subscribe(testSymbols)
	if err != nil {
		t.Errorf("订阅Bitget合约行情失败: %v", err)
	}
	time.Sleep(60 * time.Second)
}

func TestBitgetMarketSpotClient_Subscribe(t *testing.T) {
	initSetting()
	// 初始化Bitget现货行情客户端
	bitgetSpot := BitgetMarketSpotClient{}

	// 测试用的现货符号列表
	testSymbols := []string{"ETHUSDT"}

	// 调用订阅方法
	err := bitgetSpot.Subscribe(testSymbols)
	if err != nil {
		t.Errorf("订阅Bitget现货行情失败: %v", err)
	}

	time.Sleep(60 * time.Second)
}
