Skip to content

Commit

Permalink
WIP: Rebase out 2
Browse files Browse the repository at this point in the history
  • Loading branch information
gbjk committed Feb 6, 2024
1 parent 25c15b4 commit 0839825
Show file tree
Hide file tree
Showing 25 changed files with 173 additions and 150 deletions.
13 changes: 10 additions & 3 deletions exchanges/bitfinex/bitfinex_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -1771,6 +1771,13 @@ func (b *Bitfinex) subscribeToChan(chans []subscription.Subscription) error {

// subscribeReq returns a map of request params for subscriptions
func subscribeReq(c *subscription.Subscription) (map[string]interface{}, error) {
if c == nil {
return common.ErrNilPointer
}
if len(c.Pairs) != 1 {
return subscription.ErrNotSinglePair
}
pair := c.Pairs[0]
req := map[string]interface{}{
"event": "subscribe",
"channel": c.Channel,
Expand All @@ -1793,13 +1800,13 @@ func subscribeReq(c *subscription.Subscription) (map[string]interface{}, error)
prefix = "f"
}

needsDelimiter := c.Pair.Len() > 6
needsDelimiter := pair.Len() > 6

var formattedPair string
if needsDelimiter {
formattedPair = c.Pair.Format(currency.PairFormat{Uppercase: true, Delimiter: ":"}).String()
formattedPair = pair.Format(currency.PairFormat{Uppercase: true, Delimiter: ":"}).String()
} else {
formattedPair = currency.PairFormat{Uppercase: true}.Format(c.Pair)
formattedPair = currency.PairFormat{Uppercase: true}.Format(pair)
}

if c.Channel == wsCandles {
Expand Down
4 changes: 2 additions & 2 deletions exchanges/bithumb/bithumb_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (b *Bithumb) GenerateSubscriptions() ([]subscription.Subscription, error) {
for y := range channels {
subscriptions = append(subscriptions, subscription.Subscription{
Channel: channels[y],
Pair: pairs[x].Format(pFmt),
Pairs: pairs[x].Format(pFmt),
Asset: asset.Spot,
})
}
Expand All @@ -204,7 +204,7 @@ func (b *Bithumb) Subscribe(channelsToSubscribe []subscription.Subscription) err
}
subs[channelsToSubscribe[i].Channel] = s
}
s.Symbols = append(s.Symbols, channelsToSubscribe[i].Pair)
s.Symbols = append(s.Symbols, channelsToSubscribe[i].Pairs)
}

tSub, ok := subs["ticker"]
Expand Down
4 changes: 2 additions & 2 deletions exchanges/bitmex/bitmex_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ func (b *Bitmex) GenerateDefaultSubscriptions() ([]subscription.Subscription, er
}
subscriptions = append(subscriptions, subscription.Subscription{
Channel: channels[z] + ":" + pFmt.Format(contracts[y]),
Pair: contracts[y],
Pairs: contracts[y],
Asset: assets[x],
})
}
Expand Down Expand Up @@ -621,7 +621,7 @@ func (b *Bitmex) GenerateAuthenticatedSubscriptions() ([]subscription.Subscripti
for j := range contracts {
subscriptions = append(subscriptions, subscription.Subscription{
Channel: channels[i] + ":" + pFmt.Format(contracts[j]),
Pair: contracts[j],
Pairs: contracts[j],
Asset: asset.PerpetualContract,
})
}
Expand Down
4 changes: 2 additions & 2 deletions exchanges/bitstamp/bitstamp_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,15 @@ func (b *Bitstamp) generateDefaultSubscriptions() ([]subscription.Subscription,
subscriptions = append(subscriptions, subscription.Subscription{
Channel: defaultAuthSubChannels[j] + "_" + p.String(),
Asset: asset.Spot,
Pair: p,
Pairsr: p,
Params: map[string]interface{}{
"auth": struct{}{},
},
})
}
}
}
return subscriptions, nil
retuPairsubscriptions, nil
}

// Subscribe sends a websocket message to receive data from the channel
Expand Down
12 changes: 6 additions & 6 deletions exchanges/btcmarkets/btcmarkets_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func (b *BTCMarkets) generateDefaultSubscriptions() ([]subscription.Subscription
for j := range enabledCurrencies {
subscriptions = append(subscriptions, subscription.Subscription{
Channel: channels[i],
Pair: enabledCurrencies[j],
Pairs: enabledCurrencies[j],
Asset: asset.Spot,
})
}
Expand Down Expand Up @@ -370,10 +370,10 @@ func (b *BTCMarkets) Subscribe(subs []subscription.Subscription) error {
authenticate = true
}
payload.Channels = append(payload.Channels, subs[i].Channel)
if subs[i].Pair.IsEmpty() {
if subs[i].Pairs.IsEmpty() {
continue
}
pair := subs[i].Pair.String()
pair := subs[i].Pairs.String()
if common.StringDataCompare(payload.MarketIDs, pair) {
continue
}
Expand Down Expand Up @@ -415,11 +415,11 @@ func (b *BTCMarkets) Unsubscribe(subs []subscription.Subscription) error {
}
for i := range subs {
payload.Channels = append(payload.Channels, subs[i].Channel)
if subs[i].Pair.IsEmpty() {
if subs[i].Pairs.IsEmpty() {
continue
}

pair := subs[i].Pair.String()
pair := subs[i].Pairs.String()
if common.StringDataCompare(payload.MarketIDs, pair) {
continue
}
Expand All @@ -439,7 +439,7 @@ func (b *BTCMarkets) Unsubscribe(subs []subscription.Subscription) error {
func (b *BTCMarkets) ReSubscribeSpecificOrderbook(pair currency.Pair) error {
sub := []subscription.Subscription{{
Channel: wsOB,
Pair: pair,
Pairs: pair,
Asset: asset.Spot,
}}
if err := b.Unsubscribe(sub); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion exchanges/btse/btse_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ func (b *BTSE) GenerateDefaultSubscriptions() ([]subscription.Subscription, erro
for j := range pairs {
subscriptions = append(subscriptions, subscription.Subscription{
Channel: fmt.Sprintf(channels[i], pairs[j]),
Pair: pairs[j],
Pairs: pairs[j],
Asset: asset.Spot,
})
}
Expand Down
2 changes: 1 addition & 1 deletion exchanges/coinbasepro/coinbasepro_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ func TestWsAuth(t *testing.T) {
err = c.Subscribe([]subscription.Subscription{
{
Channel: "user",
Pair: testPair,
Pairs: testPair,
},
})
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions exchanges/coinbasepro/coinbasepro_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ func (c *CoinbasePro) GenerateDefaultSubscriptions() ([]subscription.Subscriptio
}
subscriptions = append(subscriptions, subscription.Subscription{
Channel: channels[i],
Pair: fPair,
Pairs: fPair,
Asset: asset.Spot,
})
}
Expand All @@ -414,7 +414,7 @@ func (c *CoinbasePro) Subscribe(channelsToSubscribe []subscription.Subscription)
}
productIDs := make([]string, 0, len(channelsToSubscribe))
for i := range channelsToSubscribe {
p := channelsToSubscribe[i].Pair.String()
p := channelsToSubscribe[i].Pairs.String()
if p != "" && !common.StringDataCompare(productIDs, p) {
// get all unique productIDs in advance as we generate by channels
productIDs = append(productIDs, p)
Expand Down Expand Up @@ -466,7 +466,7 @@ func (c *CoinbasePro) Unsubscribe(channelsToUnsubscribe []subscription.Subscript
}
productIDs := make([]string, 0, len(channelsToUnsubscribe))
for i := range channelsToUnsubscribe {
p := channelsToUnsubscribe[i].Pair.String()
p := channelsToUnsubscribe[i].Pairs.String()
if p != "" && !common.StringDataCompare(productIDs, p) {
// get all unique productIDs in advance as we generate by channels
productIDs = append(productIDs, p)
Expand Down
6 changes: 3 additions & 3 deletions exchanges/coinut/coinut_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ func (c *COINUT) GenerateDefaultSubscriptions() ([]subscription.Subscription, er
for j := range enabledPairs {
subscriptions = append(subscriptions, subscription.Subscription{
Channel: channels[i],
Pair: enabledPairs[j],
Pairs: enabledPairs[j],
Asset: asset.Spot,
})
}
Expand All @@ -621,7 +621,7 @@ func (c *COINUT) GenerateDefaultSubscriptions() ([]subscription.Subscription, er
func (c *COINUT) Subscribe(channelsToSubscribe []subscription.Subscription) error {
var errs error
for i := range channelsToSubscribe {
fPair, err := c.FormatExchangeCurrency(channelsToSubscribe[i].Pair, asset.Spot)
fPair, err := c.FormatExchangeCurrency(channelsToSubscribe[i].Pairs, asset.Spot)
if err != nil {
errs = common.AppendError(errs, err)
continue
Expand Down Expand Up @@ -650,7 +650,7 @@ func (c *COINUT) Subscribe(channelsToSubscribe []subscription.Subscription) erro
func (c *COINUT) Unsubscribe(channelToUnsubscribe []subscription.Subscription) error {
var errs error
for i := range channelToUnsubscribe {
fPair, err := c.FormatExchangeCurrency(channelToUnsubscribe[i].Pair, asset.Spot)
fPair, err := c.FormatExchangeCurrency(channelToUnsubscribe[i].Pairs, asset.Spot)
if err != nil {
errs = common.AppendError(errs, err)
continue
Expand Down
6 changes: 3 additions & 3 deletions exchanges/gateio/gateio_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ func (g *Gateio) GenerateDefaultSubscriptions() ([]subscription.Subscription, er

subscriptions = append(subscriptions, subscription.Subscription{
Channel: channelsToSubscribe[i],
Pair: fpair.Upper(),
Pairs: fpair.Upper(),
Asset: assetType,
Params: params,
})
Expand Down Expand Up @@ -738,8 +738,8 @@ func (g *Gateio) generatePayload(event string, channelsToSubscribe []subscriptio
for i := range channelsToSubscribe {
var auth *WsAuthInput
timestamp := time.Now()
channelsToSubscribe[i].Pair.Delimiter = currency.UnderscoreDelimiter
params := []string{channelsToSubscribe[i].Pair.String()}
channelsToSubscribe[i].Pairs.Delimiter = currency.UnderscoreDelimiter
params := []string{channelsToSubscribe[i].Pairs.String()}
switch channelsToSubscribe[i].Channel {
case spotOrderbookChannel:
interval, okay := channelsToSubscribe[i].Params["interval"].(kline.Interval)
Expand Down
6 changes: 3 additions & 3 deletions exchanges/gateio/gateio_ws_delivery_futures.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (g *Gateio) GenerateDeliveryFuturesDefaultSubscriptions() ([]subscription.S
}
subscriptions = append(subscriptions, subscription.Subscription{
Channel: channelsToSubscribe[i],
Pair: fpair.Upper(),
Pairs: fpair.Upper(),
Params: params,
})
}
Expand Down Expand Up @@ -246,7 +246,7 @@ func (g *Gateio) generateDeliveryFuturesPayload(event string, channelsToSubscrib
var auth *WsAuthInput
timestamp := time.Now()
var params []string
params = []string{channelsToSubscribe[i].Pair.String()}
params = []string{channelsToSubscribe[i].Pairs.String()}
if g.Websocket.CanUseAuthenticatedEndpoints() {
switch channelsToSubscribe[i].Channel {
case futuresOrdersChannel, futuresUserTradesChannel,
Expand Down Expand Up @@ -310,7 +310,7 @@ func (g *Gateio) generateDeliveryFuturesPayload(event string, channelsToSubscrib
params = append(params, intervalString)
}
}
if strings.HasPrefix(channelsToSubscribe[i].Pair.Quote.Upper().String(), "USDT") {
if strings.HasPrefix(channelsToSubscribe[i].Pairs.Quote.Upper().String(), "USDT") {
payloads[0] = append(payloads[0], WsInput{
ID: g.Websocket.Conn.GenerateMessageID(false),
Event: event,
Expand Down
6 changes: 3 additions & 3 deletions exchanges/gateio/gateio_ws_futures.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (g *Gateio) GenerateFuturesDefaultSubscriptions() ([]subscription.Subscript
}
subscriptions[count] = subscription.Subscription{
Channel: channelsToSubscribe[i],
Pair: fpair.Upper(),
Pairs: fpair.Upper(),
Params: params,
}
count++
Expand Down Expand Up @@ -324,7 +324,7 @@ func (g *Gateio) generateFuturesPayload(event string, channelsToSubscribe []subs
var auth *WsAuthInput
timestamp := time.Now()
var params []string
params = []string{channelsToSubscribe[i].Pair.String()}
params = []string{channelsToSubscribe[i].Pairs.String()}
if g.Websocket.CanUseAuthenticatedEndpoints() {
switch channelsToSubscribe[i].Channel {
case futuresOrdersChannel, futuresUserTradesChannel,
Expand Down Expand Up @@ -388,7 +388,7 @@ func (g *Gateio) generateFuturesPayload(event string, channelsToSubscribe []subs
params = append(params, intervalString)
}
}
if strings.HasPrefix(channelsToSubscribe[i].Pair.Quote.Upper().String(), "USDT") {
if strings.HasPrefix(channelsToSubscribe[i].Pairs.Quote.Upper().String(), "USDT") {
payloads[0] = append(payloads[0], WsInput{
ID: g.Websocket.Conn.GenerateMessageID(false),
Event: event,
Expand Down
8 changes: 4 additions & 4 deletions exchanges/gateio/gateio_ws_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ getEnabledPairs:
}
subscriptions = append(subscriptions, subscription.Subscription{
Channel: channelsToSubscribe[i],
Pair: fpair.Upper(),
Pairs: fpair.Upper(),
Params: params,
})
}
Expand All @@ -190,16 +190,16 @@ func (g *Gateio) generateOptionsPayload(event string, channelsToSubscribe []subs
optionsUnderlyingPriceChannel,
optionsUnderlyingCandlesticksChannel:
var uly currency.Pair
uly, err = g.GetUnderlyingFromCurrencyPair(channelsToSubscribe[i].Pair)
uly, err = g.GetUnderlyingFromCurrencyPair(channelsToSubscribe[i].Pairs)
if err != nil {
return nil, err
}
params = append(params, uly.String())
case optionsBalancesChannel:
// options.balance channel does not require underlying or contract
default:
channelsToSubscribe[i].Pair.Delimiter = currency.UnderscoreDelimiter
params = append(params, channelsToSubscribe[i].Pair.String())
channelsToSubscribe[i].Pairs.Delimiter = currency.UnderscoreDelimiter
params = append(params, channelsToSubscribe[i].Pairs.String())
}
switch channelsToSubscribe[i].Channel {
case optionsOrderbookChannel:
Expand Down
10 changes: 5 additions & 5 deletions exchanges/gemini/gemini_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (g *Gemini) GenerateDefaultSubscriptions() ([]subscription.Subscription, er
for y := range pairs {
subscriptions = append(subscriptions, subscription.Subscription{
Channel: channels[x],
Pair: pairs[y],
Pairs: pairs[y],
Asset: asset.Spot,
})
}
Expand All @@ -100,10 +100,10 @@ func (g *Gemini) Subscribe(channelsToSubscribe []subscription.Subscription) erro

var pairs currency.Pairs
for x := range channelsToSubscribe {
if pairs.Contains(channelsToSubscribe[x].Pair, true) {
if pairs.Contains(channelsToSubscribe[x].Pairs, true) {
continue
}
pairs = append(pairs, channelsToSubscribe[x].Pair)
pairs = append(pairs, channelsToSubscribe[x].Pairs)
}

fmtPairs, err := g.FormatExchangeCurrencies(pairs, asset.Spot)
Expand Down Expand Up @@ -144,10 +144,10 @@ func (g *Gemini) Unsubscribe(channelsToUnsubscribe []subscription.Subscription)

var pairs currency.Pairs
for x := range channelsToUnsubscribe {
if pairs.Contains(channelsToUnsubscribe[x].Pair, true) {
if pairs.Contains(channelsToUnsubscribe[x].Pairs, true) {
continue
}
pairs = append(pairs, channelsToUnsubscribe[x].Pair)
pairs = append(pairs, channelsToUnsubscribe[x].Pairs)
}

fmtPairs, err := g.FormatExchangeCurrencies(pairs, asset.Spot)
Expand Down
8 changes: 4 additions & 4 deletions exchanges/hitbtc/hitbtc_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ func (h *HitBTC) GenerateDefaultSubscriptions() ([]subscription.Subscription, er
enabledCurrencies[j].Delimiter = ""
subscriptions = append(subscriptions, subscription.Subscription{
Channel: channels[i],
Pair: fPair,
Pairs: fPair,
Asset: asset.Spot,
})
}
Expand All @@ -509,8 +509,8 @@ func (h *HitBTC) Subscribe(channelsToSubscribe []subscription.Subscription) erro
ID: h.Websocket.Conn.GenerateMessageID(false),
}

if channelsToSubscribe[i].Pair.String() != "" {
subscribe.Params.Symbol = channelsToSubscribe[i].Pair.String()
if channelsToSubscribe[i].Pairs.String() != "" {
subscribe.Params.Symbol = channelsToSubscribe[i].Pairs.String()
}
if strings.EqualFold(channelsToSubscribe[i].Channel, "subscribeTrades") {
subscribe.Params.Limit = 100
Expand Down Expand Up @@ -546,7 +546,7 @@ func (h *HitBTC) Unsubscribe(channelsToUnsubscribe []subscription.Subscription)
Method: unsubscribeChannel,
}

unsubscribe.Params.Symbol = channelsToUnsubscribe[i].Pair.String()
unsubscribe.Params.Symbol = channelsToUnsubscribe[i].Pairs.String()
if strings.EqualFold(unsubscribeChannel, "unsubscribeTrades") {
unsubscribe.Params.Limit = 100
} else if strings.EqualFold(unsubscribeChannel, "unsubscribeCandles") {
Expand Down
2 changes: 1 addition & 1 deletion exchanges/huobi/huobi_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ func (h *HUOBI) GenerateDefaultSubscriptions() ([]subscription.Subscription, err
enabledCurrencies[j].Lower().String())
subscriptions = append(subscriptions, subscription.Subscription{
Channel: channel,
Pair: enabledCurrencies[j],
Pairs: enabledCurrencies[j],
})
}
}
Expand Down
Loading

0 comments on commit 0839825

Please sign in to comment.