Websocket: Restructure files and types (#1859)

* Websocket: Rename stream package

* Websocket: Rename Websocket to Manager

* Websocket: Replace explicit errs with common.NilGuard

* Websocket: Move websocket_types.go to types.go

* Websocket: Minor field comment and alignment in types

* Webosocket: Rename WebsocketConnection to Connection

* Alphapoint: Make gorilla ws import explicit

Just to avoid confusion with our own packages.

* Websocket: Move stream_match to match

* Websocket: Move websocket_connection to connection

* Websocket: Move websocket.go to manager.go

* Websocket: Break out all subscription methods into subscriptions.go

* Websocket: Move connection type into its file

* Websocket: Remove PositionUpdated

Type is not used anywhere

* Kraken: Use local constant for pong

Was the only use of websocket.Pong and doesn't really feel right to
represent kraken's api resp in one of our packages

* Websocket: Move connection sub-types to connection package

* Websocket: Move manager types into manager

* Websocket: Move ConnectionWrapper into manager

* Websocket: Move websocket_test to manager_test

* Websocket: Privatise connectionWrapper

* Websocket: Remaining types into types.go

These really belong somewhere else mostly, but this will do for now

* Websocket: Tidy up connection method vars

* Gofumpt: Moving package imports around

* Websocket: Rename errDuplicateConnectionSetup

* Websocket: Fix duplicate import of gws

* Websocket: Fix gofumpt -extra

* Websocket: Standardise import of gws across other pkgs

* Kraken: Remove unused sub conf consts

These were replaced by the generic Levels and Depth fields on all subs

* Websocket: Privitise ConnectioWrapper fields

* Websocket: inline single use var WebsocketNotAuthenticatedUsingRest

* Websocket: Move documentation to template

* Bithumb: Assertify TestWsHandleData
This commit is contained in:
Gareth Kirwan
2025-04-10 08:25:02 +02:00
committed by GitHub
parent 676b2e0367
commit b4e45e9a1b
119 changed files with 3169 additions and 3056 deletions

View File

@@ -26,8 +26,8 @@ import (
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
"github.com/thrasher-corp/gocryptotrader/exchanges/stream"
"github.com/thrasher-corp/gocryptotrader/exchanges/subscription"
"github.com/thrasher-corp/gocryptotrader/internal/exchange/websocket"
testexch "github.com/thrasher-corp/gocryptotrader/internal/testing/exchange"
testsubs "github.com/thrasher-corp/gocryptotrader/internal/testing/subscriptions"
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
@@ -3520,7 +3520,7 @@ func TestGenerateWebsocketMessageID(t *testing.T) {
require.NotEmpty(t, g.GenerateWebsocketMessageID(false))
}
type DummyConnection struct{ stream.Connection }
type DummyConnection struct{ websocket.Connection }
func (d *DummyConnection) GenerateMessageID(bool) int64 { return 1337 }
func (d *DummyConnection) SendMessageReturnResponse(context.Context, request.EndpointLimit, any, any) ([]byte, error) {
@@ -3532,12 +3532,12 @@ func TestHandleSubscriptions(t *testing.T) {
subs := subscription.List{{Channel: subscription.OrderbookChannel}}
err := g.handleSubscription(context.Background(), &DummyConnection{}, subscribeEvent, subs, func(context.Context, stream.Connection, string, subscription.List) ([]WsInput, error) {
err := g.handleSubscription(context.Background(), &DummyConnection{}, subscribeEvent, subs, func(context.Context, websocket.Connection, string, subscription.List) ([]WsInput, error) {
return []WsInput{{}}, nil
})
require.NoError(t, err)
err = g.handleSubscription(context.Background(), &DummyConnection{}, unsubscribeEvent, subs, func(context.Context, stream.Connection, string, subscription.List) ([]WsInput, error) {
err = g.handleSubscription(context.Background(), &DummyConnection{}, unsubscribeEvent, subs, func(context.Context, websocket.Connection, string, subscription.List) ([]WsInput, error) {
return []WsInput{{}}, nil
})
require.NoError(t, err)

View File

@@ -15,7 +15,7 @@ import (
"github.com/Masterminds/sprig/v3"
"github.com/buger/jsonparser"
"github.com/gorilla/websocket"
gws "github.com/gorilla/websocket"
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
@@ -25,10 +25,10 @@ import (
"github.com/thrasher-corp/gocryptotrader/exchanges/kline"
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-corp/gocryptotrader/exchanges/stream"
"github.com/thrasher-corp/gocryptotrader/exchanges/subscription"
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
"github.com/thrasher-corp/gocryptotrader/exchanges/trade"
"github.com/thrasher-corp/gocryptotrader/internal/exchange/websocket"
)
const (
@@ -76,12 +76,12 @@ var subscriptionNames = map[string]string{
var standardMarginAssetTypes = []asset.Item{asset.Spot, asset.Margin, asset.CrossMargin}
// WsConnectSpot initiates a websocket connection
func (g *Gateio) WsConnectSpot(ctx context.Context, conn stream.Connection) error {
func (g *Gateio) WsConnectSpot(ctx context.Context, conn websocket.Connection) error {
err := g.CurrencyPairs.IsAssetEnabled(asset.Spot)
if err != nil {
return err
}
err = conn.DialContext(ctx, &websocket.Dialer{}, http.Header{})
err = conn.DialContext(ctx, &gws.Dialer{}, http.Header{})
if err != nil {
return err
}
@@ -89,22 +89,22 @@ func (g *Gateio) WsConnectSpot(ctx context.Context, conn stream.Connection) erro
if err != nil {
return err
}
conn.SetupPingHandler(websocketRateLimitNotNeededEPL, stream.PingHandler{
conn.SetupPingHandler(websocketRateLimitNotNeededEPL, websocket.PingHandler{
Websocket: true,
Delay: time.Second * 15,
Message: pingMessage,
MessageType: websocket.TextMessage,
MessageType: gws.TextMessage,
})
return nil
}
// authenticateSpot sends an authentication message to the websocket connection
func (g *Gateio) authenticateSpot(ctx context.Context, conn stream.Connection) error {
func (g *Gateio) authenticateSpot(ctx context.Context, conn websocket.Connection) error {
return g.websocketLogin(ctx, conn, "spot.login")
}
// websocketLogin authenticates the websocket connection
func (g *Gateio) websocketLogin(ctx context.Context, conn stream.Connection, channel string) error {
func (g *Gateio) websocketLogin(ctx context.Context, conn websocket.Connection, channel string) error {
if conn == nil {
return fmt.Errorf("%w: %T", common.ErrNilPointer, conn)
}
@@ -209,10 +209,10 @@ func (g *Gateio) WsHandleSpotData(_ context.Context, respRaw []byte) error {
return g.processCrossMarginLoans(respRaw)
case spotPongChannel:
default:
g.Websocket.DataHandler <- stream.UnhandledMessageWarning{
Message: g.Name + stream.UnhandledMessage + string(respRaw),
g.Websocket.DataHandler <- websocket.UnhandledMessageWarning{
Message: g.Name + websocket.UnhandledMessage + string(respRaw),
}
return errors.New(stream.UnhandledMessage)
return errors.New(websocket.UnhandledMessage)
}
return nil
}
@@ -333,10 +333,10 @@ func (g *Gateio) processCandlestick(incoming []byte) error {
return err
}
out := make([]stream.KlineData, 0, len(standardMarginAssetTypes))
out := make([]websocket.KlineData, 0, len(standardMarginAssetTypes))
for _, a := range standardMarginAssetTypes {
if enabled, _ := g.CurrencyPairs.IsPairEnabled(currencyPair, a); enabled {
out = append(out, stream.KlineData{
out = append(out, websocket.KlineData{
Pair: currencyPair,
AssetType: a,
Exchange: g.Name,
@@ -670,7 +670,7 @@ func (g *Gateio) GetSubscriptionTemplate(_ *subscription.Subscription) (*templat
}
// manageSubs sends a websocket message to subscribe or unsubscribe from a list of channel
func (g *Gateio) manageSubs(ctx context.Context, event string, conn stream.Connection, subs subscription.List) error {
func (g *Gateio) manageSubs(ctx context.Context, event string, conn websocket.Connection, subs subscription.List) error {
var errs error
subs, errs = subs.ExpandTemplates(g)
if errs != nil {
@@ -706,7 +706,7 @@ func (g *Gateio) manageSubs(ctx context.Context, event string, conn stream.Conne
}
// manageSubReq constructs the subscription management message for a subscription
func (g *Gateio) manageSubReq(ctx context.Context, event string, conn stream.Connection, s *subscription.Subscription) (*WsInput, error) {
func (g *Gateio) manageSubReq(ctx context.Context, event string, conn websocket.Connection, s *subscription.Subscription) (*WsInput, error) {
req := &WsInput{
ID: conn.GenerateMessageID(false),
Event: event,
@@ -733,12 +733,12 @@ func (g *Gateio) manageSubReq(ctx context.Context, event string, conn stream.Con
}
// Subscribe sends a websocket message to stop receiving data from the channel
func (g *Gateio) Subscribe(ctx context.Context, conn stream.Connection, subs subscription.List) error {
func (g *Gateio) Subscribe(ctx context.Context, conn websocket.Connection, subs subscription.List) error {
return g.manageSubs(ctx, subscribeEvent, conn, subs)
}
// Unsubscribe sends a websocket message to stop receiving data from the channel
func (g *Gateio) Unsubscribe(ctx context.Context, conn stream.Connection, subs subscription.List) error {
func (g *Gateio) Unsubscribe(ctx context.Context, conn websocket.Connection, subs subscription.List) error {
return g.manageSubs(ctx, unsubscribeEvent, conn, subs)
}
@@ -784,10 +784,10 @@ const subTplText = `
`
// GeneratePayload returns the payload for a websocket message
type GeneratePayload func(ctx context.Context, conn stream.Connection, event string, channelsToSubscribe subscription.List) ([]WsInput, error)
type GeneratePayload func(ctx context.Context, conn websocket.Connection, event string, channelsToSubscribe subscription.List) ([]WsInput, error)
// handleSubscription sends a websocket message to receive data from the channel
func (g *Gateio) handleSubscription(ctx context.Context, conn stream.Connection, event string, channelsToSubscribe subscription.List, generatePayload GeneratePayload) error {
func (g *Gateio) handleSubscription(ctx context.Context, conn websocket.Connection, event string, channelsToSubscribe subscription.List, generatePayload GeneratePayload) error {
payloads, err := generatePayload(ctx, conn, event, channelsToSubscribe)
if err != nil {
return err

View File

@@ -7,14 +7,14 @@ import (
"strconv"
"time"
"github.com/gorilla/websocket"
gws "github.com/gorilla/websocket"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
"github.com/thrasher-corp/gocryptotrader/exchanges/account"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
"github.com/thrasher-corp/gocryptotrader/exchanges/kline"
"github.com/thrasher-corp/gocryptotrader/exchanges/stream"
"github.com/thrasher-corp/gocryptotrader/exchanges/subscription"
"github.com/thrasher-corp/gocryptotrader/internal/exchange/websocket"
)
const (
@@ -37,12 +37,12 @@ var defaultDeliveryFuturesSubscriptions = []string{
var fetchedFuturesCurrencyPairSnapshotOrderbook = make(map[string]bool)
// WsDeliveryFuturesConnect initiates a websocket connection for delivery futures account
func (g *Gateio) WsDeliveryFuturesConnect(ctx context.Context, conn stream.Connection) error {
func (g *Gateio) WsDeliveryFuturesConnect(ctx context.Context, conn websocket.Connection) error {
err := g.CurrencyPairs.IsAssetEnabled(asset.DeliveryFutures)
if err != nil {
return err
}
err = conn.DialContext(ctx, &websocket.Dialer{}, http.Header{})
err = conn.DialContext(ctx, &gws.Dialer{}, http.Header{})
if err != nil {
return err
}
@@ -54,10 +54,10 @@ func (g *Gateio) WsDeliveryFuturesConnect(ctx context.Context, conn stream.Conne
if err != nil {
return err
}
conn.SetupPingHandler(websocketRateLimitNotNeededEPL, stream.PingHandler{
conn.SetupPingHandler(websocketRateLimitNotNeededEPL, websocket.PingHandler{
Websocket: true,
Delay: time.Second * 5,
MessageType: websocket.PingMessage,
MessageType: gws.PingMessage,
Message: pingMessage,
})
return nil
@@ -109,16 +109,16 @@ func (g *Gateio) GenerateDeliveryFuturesDefaultSubscriptions() (subscription.Lis
}
// DeliveryFuturesSubscribe sends a websocket message to stop receiving data from the channel
func (g *Gateio) DeliveryFuturesSubscribe(ctx context.Context, conn stream.Connection, channelsToUnsubscribe subscription.List) error {
func (g *Gateio) DeliveryFuturesSubscribe(ctx context.Context, conn websocket.Connection, channelsToUnsubscribe subscription.List) error {
return g.handleSubscription(ctx, conn, subscribeEvent, channelsToUnsubscribe, g.generateDeliveryFuturesPayload)
}
// DeliveryFuturesUnsubscribe sends a websocket message to stop receiving data from the channel
func (g *Gateio) DeliveryFuturesUnsubscribe(ctx context.Context, conn stream.Connection, channelsToUnsubscribe subscription.List) error {
func (g *Gateio) DeliveryFuturesUnsubscribe(ctx context.Context, conn websocket.Connection, channelsToUnsubscribe subscription.List) error {
return g.handleSubscription(ctx, conn, unsubscribeEvent, channelsToUnsubscribe, g.generateDeliveryFuturesPayload)
}
func (g *Gateio) generateDeliveryFuturesPayload(ctx context.Context, conn stream.Connection, event string, channelsToSubscribe subscription.List) ([]WsInput, error) {
func (g *Gateio) generateDeliveryFuturesPayload(ctx context.Context, conn websocket.Connection, event string, channelsToSubscribe subscription.List) ([]WsInput, error) {
if len(channelsToSubscribe) == 0 {
return nil, errors.New("cannot generate payload, no channels supplied")
}

View File

@@ -10,7 +10,7 @@ import (
"strings"
"time"
"github.com/gorilla/websocket"
gws "github.com/gorilla/websocket"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
"github.com/thrasher-corp/gocryptotrader/exchanges/account"
@@ -19,10 +19,10 @@ import (
"github.com/thrasher-corp/gocryptotrader/exchanges/kline"
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-corp/gocryptotrader/exchanges/stream"
"github.com/thrasher-corp/gocryptotrader/exchanges/subscription"
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
"github.com/thrasher-corp/gocryptotrader/exchanges/trade"
"github.com/thrasher-corp/gocryptotrader/internal/exchange/websocket"
)
const (
@@ -58,12 +58,12 @@ var defaultFuturesSubscriptions = []string{
}
// WsFuturesConnect initiates a websocket connection for futures account
func (g *Gateio) WsFuturesConnect(ctx context.Context, conn stream.Connection) error {
func (g *Gateio) WsFuturesConnect(ctx context.Context, conn websocket.Connection) error {
err := g.CurrencyPairs.IsAssetEnabled(asset.Futures)
if err != nil {
return err
}
err = conn.DialContext(ctx, &websocket.Dialer{}, http.Header{})
err = conn.DialContext(ctx, &gws.Dialer{}, http.Header{})
if err != nil {
return err
}
@@ -75,9 +75,9 @@ func (g *Gateio) WsFuturesConnect(ctx context.Context, conn stream.Connection) e
if err != nil {
return err
}
conn.SetupPingHandler(websocketRateLimitNotNeededEPL, stream.PingHandler{
conn.SetupPingHandler(websocketRateLimitNotNeededEPL, websocket.PingHandler{
Websocket: true,
MessageType: websocket.PingMessage,
MessageType: gws.PingMessage,
Delay: time.Second * 15,
Message: pingMessage,
})
@@ -138,12 +138,12 @@ func (g *Gateio) GenerateFuturesDefaultSubscriptions(settlement currency.Code) (
}
// FuturesSubscribe sends a websocket message to stop receiving data from the channel
func (g *Gateio) FuturesSubscribe(ctx context.Context, conn stream.Connection, channelsToUnsubscribe subscription.List) error {
func (g *Gateio) FuturesSubscribe(ctx context.Context, conn websocket.Connection, channelsToUnsubscribe subscription.List) error {
return g.handleSubscription(ctx, conn, subscribeEvent, channelsToUnsubscribe, g.generateFuturesPayload)
}
// FuturesUnsubscribe sends a websocket message to stop receiving data from the channel
func (g *Gateio) FuturesUnsubscribe(ctx context.Context, conn stream.Connection, channelsToUnsubscribe subscription.List) error {
func (g *Gateio) FuturesUnsubscribe(ctx context.Context, conn websocket.Connection, channelsToUnsubscribe subscription.List) error {
return g.handleSubscription(ctx, conn, unsubscribeEvent, channelsToUnsubscribe, g.generateFuturesPayload)
}
@@ -199,14 +199,14 @@ func (g *Gateio) WsHandleFuturesData(_ context.Context, respRaw []byte, a asset.
case futuresAutoOrdersChannel:
return g.processFuturesAutoOrderPushData(respRaw)
default:
g.Websocket.DataHandler <- stream.UnhandledMessageWarning{
Message: g.Name + stream.UnhandledMessage + string(respRaw),
g.Websocket.DataHandler <- websocket.UnhandledMessageWarning{
Message: g.Name + websocket.UnhandledMessage + string(respRaw),
}
return errors.New(stream.UnhandledMessage)
return errors.New(websocket.UnhandledMessage)
}
}
func (g *Gateio) generateFuturesPayload(ctx context.Context, conn stream.Connection, event string, channelsToSubscribe subscription.List) ([]WsInput, error) {
func (g *Gateio) generateFuturesPayload(ctx context.Context, conn websocket.Connection, event string, channelsToSubscribe subscription.List) ([]WsInput, error) {
if len(channelsToSubscribe) == 0 {
return nil, errors.New("cannot generate payload, no channels supplied")
}
@@ -375,7 +375,7 @@ func (g *Gateio) processFuturesCandlesticks(data []byte, assetType asset.Item) e
if err != nil {
return err
}
klineDatas := make([]stream.KlineData, len(resp.Result))
klineDatas := make([]websocket.KlineData, len(resp.Result))
for x := range resp.Result {
icp := strings.Split(resp.Result[x].Name, currency.UnderscoreDelimiter)
if len(icp) < 3 {
@@ -385,7 +385,7 @@ func (g *Gateio) processFuturesCandlesticks(data []byte, assetType asset.Item) e
if err != nil {
return err
}
klineDatas[x] = stream.KlineData{
klineDatas[x] = websocket.KlineData{
Pair: currencyPair,
AssetType: assetType,
Exchange: g.Name,

View File

@@ -9,7 +9,7 @@ import (
"strings"
"time"
"github.com/gorilla/websocket"
gws "github.com/gorilla/websocket"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
"github.com/thrasher-corp/gocryptotrader/exchanges/account"
@@ -18,10 +18,10 @@ import (
"github.com/thrasher-corp/gocryptotrader/exchanges/kline"
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-corp/gocryptotrader/exchanges/stream"
"github.com/thrasher-corp/gocryptotrader/exchanges/subscription"
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
"github.com/thrasher-corp/gocryptotrader/exchanges/trade"
"github.com/thrasher-corp/gocryptotrader/internal/exchange/websocket"
"github.com/thrasher-corp/gocryptotrader/log"
)
@@ -67,12 +67,12 @@ var defaultOptionsSubscriptions = []string{
var fetchedOptionsCurrencyPairSnapshotOrderbook = make(map[string]bool)
// WsOptionsConnect initiates a websocket connection to options websocket endpoints.
func (g *Gateio) WsOptionsConnect(ctx context.Context, conn stream.Connection) error {
func (g *Gateio) WsOptionsConnect(ctx context.Context, conn websocket.Connection) error {
err := g.CurrencyPairs.IsAssetEnabled(asset.Options)
if err != nil {
return err
}
err = conn.DialContext(ctx, &websocket.Dialer{}, http.Header{})
err = conn.DialContext(ctx, &gws.Dialer{}, http.Header{})
if err != nil {
return err
}
@@ -84,10 +84,10 @@ func (g *Gateio) WsOptionsConnect(ctx context.Context, conn stream.Connection) e
if err != nil {
return err
}
conn.SetupPingHandler(websocketRateLimitNotNeededEPL, stream.PingHandler{
conn.SetupPingHandler(websocketRateLimitNotNeededEPL, websocket.PingHandler{
Websocket: true,
Delay: time.Second * 5,
MessageType: websocket.PingMessage,
MessageType: gws.PingMessage,
Message: pingMessage,
})
return nil
@@ -169,7 +169,7 @@ getEnabledPairs:
return subscriptions, nil
}
func (g *Gateio) generateOptionsPayload(ctx context.Context, conn stream.Connection, event string, channelsToSubscribe subscription.List) ([]WsInput, error) {
func (g *Gateio) generateOptionsPayload(ctx context.Context, conn websocket.Connection, event string, channelsToSubscribe subscription.List) ([]WsInput, error) {
if len(channelsToSubscribe) == 0 {
return nil, errors.New("cannot generate payload, no channels supplied")
}
@@ -283,12 +283,12 @@ func (g *Gateio) generateOptionsPayload(ctx context.Context, conn stream.Connect
}
// OptionsSubscribe sends a websocket message to stop receiving data for asset type options
func (g *Gateio) OptionsSubscribe(ctx context.Context, conn stream.Connection, channelsToUnsubscribe subscription.List) error {
func (g *Gateio) OptionsSubscribe(ctx context.Context, conn websocket.Connection, channelsToUnsubscribe subscription.List) error {
return g.handleSubscription(ctx, conn, subscribeEvent, channelsToUnsubscribe, g.generateOptionsPayload)
}
// OptionsUnsubscribe sends a websocket message to stop receiving data for asset type options
func (g *Gateio) OptionsUnsubscribe(ctx context.Context, conn stream.Connection, channelsToUnsubscribe subscription.List) error {
func (g *Gateio) OptionsUnsubscribe(ctx context.Context, conn websocket.Connection, channelsToUnsubscribe subscription.List) error {
return g.handleSubscription(ctx, conn, unsubscribeEvent, channelsToUnsubscribe, g.generateOptionsPayload)
}
@@ -346,10 +346,10 @@ func (g *Gateio) WsHandleOptionsData(_ context.Context, respRaw []byte) error {
case optionsPositionsChannel:
return g.processOptionsPositionPushData(respRaw)
default:
g.Websocket.DataHandler <- stream.UnhandledMessageWarning{
Message: g.Name + stream.UnhandledMessage + string(respRaw),
g.Websocket.DataHandler <- websocket.UnhandledMessageWarning{
Message: g.Name + websocket.UnhandledMessage + string(respRaw),
}
return errors.New(stream.UnhandledMessage)
return errors.New(websocket.UnhandledMessage)
}
}
@@ -464,7 +464,7 @@ func (g *Gateio) processOptionsCandlestickPushData(data []byte) error {
if err != nil {
return err
}
klineDatas := make([]stream.KlineData, len(resp.Result))
klineDatas := make([]websocket.KlineData, len(resp.Result))
for x := range resp.Result {
icp := strings.Split(resp.Result[x].NameOfSubscription, currency.UnderscoreDelimiter)
if len(icp) < 3 {
@@ -474,7 +474,7 @@ func (g *Gateio) processOptionsCandlestickPushData(data []byte) error {
if err != nil {
return err
}
klineDatas[x] = stream.KlineData{
klineDatas[x] = websocket.KlineData{
Pair: currencyPair,
AssetType: asset.Options,
Exchange: g.Name,

View File

@@ -12,7 +12,6 @@ import (
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
"github.com/thrasher-corp/gocryptotrader/exchanges/stream"
testexch "github.com/thrasher-corp/gocryptotrader/internal/testing/exchange"
)
@@ -21,18 +20,18 @@ func TestWebsocketLogin(t *testing.T) {
err := g.websocketLogin(context.Background(), nil, "")
require.ErrorIs(t, err, common.ErrNilPointer)
err = g.websocketLogin(context.Background(), &stream.WebsocketConnection{}, "")
require.ErrorIs(t, err, errChannelEmpty)
sharedtestvalues.SkipTestIfCredentialsUnset(t, g, canManipulateRealOrders)
testexch.UpdatePairsOnce(t, g)
g := getWebsocketInstance(t, g) //nolint:govet // Intentional shadow to avoid future copy/paste mistakes
demonstrationConn, err := g.Websocket.GetConnection(asset.Spot)
c, err := g.Websocket.GetConnection(asset.Spot)
require.NoError(t, err)
err = g.websocketLogin(context.Background(), demonstrationConn, "spot.login")
err = g.websocketLogin(context.Background(), c, "")
require.ErrorIs(t, err, errChannelEmpty)
err = g.websocketLogin(context.Background(), c, "spot.login")
require.NoError(t, err)
}

View File

@@ -26,10 +26,10 @@ import (
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-corp/gocryptotrader/exchanges/protocol"
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
"github.com/thrasher-corp/gocryptotrader/exchanges/stream"
"github.com/thrasher-corp/gocryptotrader/exchanges/subscription"
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
"github.com/thrasher-corp/gocryptotrader/exchanges/trade"
"github.com/thrasher-corp/gocryptotrader/internal/exchange/websocket"
"github.com/thrasher-corp/gocryptotrader/log"
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
"github.com/thrasher-corp/gocryptotrader/types"
@@ -176,7 +176,7 @@ func (g *Gateio) SetDefaults() {
if err != nil {
log.Errorln(log.ExchangeSys, err)
}
g.Websocket = stream.NewWebsocket()
g.Websocket = websocket.NewManager()
g.WebsocketResponseMaxLimit = exchange.DefaultWebsocketResponseMaxLimit
g.WebsocketResponseCheckTimeout = exchange.DefaultWebsocketResponseCheckTimeout
g.WebsocketOrderbookBufferLimit = exchange.DefaultWebsocketOrderbookBufferLimit
@@ -197,7 +197,7 @@ func (g *Gateio) Setup(exch *config.Exchange) error {
return err
}
err = g.Websocket.Setup(&stream.WebsocketSetup{
err = g.Websocket.Setup(&websocket.ManagerSetup{
ExchangeConfig: exch,
Features: &g.Features.Supports.WebsocketCapabilities,
FillsFeed: g.Features.Enabled.FillsFeed,
@@ -209,7 +209,7 @@ func (g *Gateio) Setup(exch *config.Exchange) error {
return err
}
// Spot connection
err = g.Websocket.SetupNewConnection(&stream.ConnectionSetup{
err = g.Websocket.SetupNewConnection(&websocket.ConnectionSetup{
URL: gateioWebsocketEndpoint,
ResponseCheckTimeout: exch.WebsocketResponseCheckTimeout,
ResponseMaxLimit: exch.WebsocketResponseMaxLimit,
@@ -226,7 +226,7 @@ func (g *Gateio) Setup(exch *config.Exchange) error {
return err
}
// Futures connection - USDT margined
err = g.Websocket.SetupNewConnection(&stream.ConnectionSetup{
err = g.Websocket.SetupNewConnection(&websocket.ConnectionSetup{
URL: futuresWebsocketUsdtURL,
ResponseCheckTimeout: exch.WebsocketResponseCheckTimeout,
ResponseMaxLimit: exch.WebsocketResponseMaxLimit,
@@ -245,7 +245,7 @@ func (g *Gateio) Setup(exch *config.Exchange) error {
}
// Futures connection - BTC margined
err = g.Websocket.SetupNewConnection(&stream.ConnectionSetup{
err = g.Websocket.SetupNewConnection(&websocket.ConnectionSetup{
URL: futuresWebsocketBtcURL,
ResponseCheckTimeout: exch.WebsocketResponseCheckTimeout,
ResponseMaxLimit: exch.WebsocketResponseMaxLimit,
@@ -265,7 +265,7 @@ func (g *Gateio) Setup(exch *config.Exchange) error {
// TODO: Add BTC margined delivery futures.
// Futures connection - Delivery - USDT margined
err = g.Websocket.SetupNewConnection(&stream.ConnectionSetup{
err = g.Websocket.SetupNewConnection(&websocket.ConnectionSetup{
URL: deliveryRealUSDTTradingURL,
ResponseCheckTimeout: exch.WebsocketResponseCheckTimeout,
ResponseMaxLimit: exch.WebsocketResponseMaxLimit,
@@ -284,7 +284,7 @@ func (g *Gateio) Setup(exch *config.Exchange) error {
}
// Futures connection - Options
return g.Websocket.SetupNewConnection(&stream.ConnectionSetup{
return g.Websocket.SetupNewConnection(&websocket.ConnectionSetup{
URL: optionsWebsocketURL,
ResponseCheckTimeout: exch.WebsocketResponseCheckTimeout,
ResponseMaxLimit: exch.WebsocketResponseMaxLimit,