Skip to content

Commit

Permalink
WIP - rebase me
Browse files Browse the repository at this point in the history
  • Loading branch information
gbjk committed Sep 13, 2023
1 parent 6caf581 commit 12cc5f0
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
36 changes: 35 additions & 1 deletion exchanges/bitfinex/bitfinex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,16 @@ func TestMain(m *testing.M) {
if err != nil {
log.Fatal("Bitfinex setup error", err)
}
b.Websocket.Enable()
err = b.WsConnect()
if err != nil {
log.Fatal("Bitfinex setup error", err)
}
b.SetCredentials(apiKey, apiSecret, "", "", "", "")
if !b.Enabled || b.API.AuthenticatedSupport ||
b.Verbose || b.Websocket.IsEnabled() || len(b.BaseCurrencies) < 1 {
b.Verbose ||
//b.Websocket.IsEnabled() ||
len(b.BaseCurrencies) < 1 {
log.Fatal("Bitfinex Setup values not set correctly")
}

Expand Down Expand Up @@ -87,6 +94,33 @@ func TestStart(t *testing.T) {
testWg.Wait()
}

// TestWebsocketSubscribe tests returning a message with an id
func TestWebsocketSubscribe(t *testing.T) {
err := b.Subscribe([]stream.ChannelSubscription{
{
Channel: wsTicker,
Currency: currency.NewPairWithDelimiter("BTC", "USDT", "-"),
Params: map[string]interface{
"symbol":"tWIBBLE",

Check failure on line 104 in exchanges/bitfinex/bitfinex_test.go

View workflow job for this annotation

GitHub Actions / GoCryptoTrader back-end with PSQL

expected '}', found "symbol"

Check failure on line 104 in exchanges/bitfinex/bitfinex_test.go

View workflow job for this annotation

GitHub Actions / GoCryptoTrader back-end 32-bit with PSQL

expected '}', found "symbol"
},
},
})
if err != nil {
t.Error(err)
}
time.Sleep(time.Second * 5)
/*
err = b.ReSubscribe([]stream.ChannelSubscription{
{
Channel: wsT,
Currency: currency.NewPairWithDelimiter("BTC", "USDT", "-"),
},
})
if err != nil {
t.Error(err)
}
*/
}
func TestGetV2MarginFunding(t *testing.T) {
t.Parallel()
sharedtestvalues.SkipTestIfCredentialsUnset(t, b)
Expand Down
14 changes: 9 additions & 5 deletions exchanges/bitfinex/bitfinex_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -1526,7 +1526,7 @@ func (b *Bitfinex) WsUpdateOrderbook(p currency.Pair, assetType asset.Item, book
// GenerateDefaultSubscriptions Adds default subscriptions to websocket to be handled by ManageSubscriptions()
func (b *Bitfinex) GenerateDefaultSubscriptions() ([]stream.ChannelSubscription, error) {
var wsPairFormat = currency.PairFormat{Uppercase: true}
var channels = []string{wsBook, wsTrades, wsTicker, wsCandles}
var channels = []string{} //wsBook, wsTrades, wsTicker, wsCandles}

var subscriptions []stream.ChannelSubscription
assets := b.GetAssetTypes(true)
Expand Down Expand Up @@ -1561,6 +1561,7 @@ func (b *Bitfinex) GenerateDefaultSubscriptions() ([]stream.ChannelSubscription,
formattedPair = wsPairFormat.Format(enabledPairs[k])
}

// TODO - This should not be here in DefSubs
if channels[j] == wsCandles {
// TODO: Add ability to select timescale && funding period
fundingPeriod := ""
Expand All @@ -1587,6 +1588,7 @@ func (b *Bitfinex) GenerateDefaultSubscriptions() ([]stream.ChannelSubscription,

// Subscribe sends a websocket message to receive data from the channel
func (b *Bitfinex) Subscribe(channelsToSubscribe []stream.ChannelSubscription) error {
// TODO: This should be done once only
checksum := make(map[string]interface{})
checksum["event"] = "conf"
checksum["flags"] = bitfinexChecksumFlag + bitfinexWsSequenceFlag
Expand All @@ -1607,9 +1609,11 @@ func (b *Bitfinex) Subscribe(channelsToSubscribe []stream.ChannelSubscription) e
req[k] = v
}
}
if channelsToSubscribe[i].Channel == wsBook {
req["subId"] = strconv.Itoa(int(b.Websocket.Conn.GenerateMessageID(false)))
}
req["subId"] = strconv.Itoa(int(b.Websocket.Conn.GenerateMessageID(false)))
/*
if channelsToSubscribe[i].Channel == wsBook {
}
*/

key, err := keyForSub("subscribe:"+channelsToSubscribe[i].Channel, req)
if err != nil {
Expand Down Expand Up @@ -2060,7 +2064,7 @@ func keyForSub(prefix string, r map[string]interface{}) (key string, err error)
}

if s, ok := r[subKey].(string); !ok {
err = fmt.Errorf("error converting %s to string in keyForSub: %w", subKey, r[subKey])
err = fmt.Errorf("error converting %s to string in keyForSub: %v", subKey, r[subKey])
} else {
key = key + ":" + s
}
Expand Down
2 changes: 1 addition & 1 deletion exchanges/stream/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func (w *Websocket) SetupNewConnection(c ConnectionSetup) error {
ExchangeName: w.exchangeName,
URL: connectionURL,
ProxyURL: w.GetProxyAddress(),
Verbose: w.verbose,
Verbose: true, // w.verbose,
ResponseMaxLimit: c.ResponseMaxLimit,
Traffic: w.TrafficAlert,
readMessageErrors: w.ReadMessageErrors,
Expand Down

0 comments on commit 12cc5f0

Please sign in to comment.