Skip to content

Commit

Permalink
Kucoin: Subscription configuration
Browse files Browse the repository at this point in the history
* Simplify GenerateDefaultSubs
* Improve TestGenSubs coverage
* Test Candle Sub generation
* Support Candle intervals
* Full responsibility for formatting Channel name on GenerateDefaultSubs
  OR consumer of Subscribe
* Simplify generatePayloads as a result
  • Loading branch information
gbjk committed Nov 22, 2023
1 parent 84d960d commit d3be869
Show file tree
Hide file tree
Showing 8 changed files with 420 additions and 439 deletions.
8 changes: 8 additions & 0 deletions currency/currencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ func NewCurrenciesFromStringArray(currencies []string) Currencies {
// Currencies define a range of supported currency codes
type Currencies []Code

// Add adds a currency to the list if it doesn't exist
func (c Currencies) Add(a Code) Currencies {
if !c.Contains(a) {
c = append(c, a)
}
return c
}

// Strings returns an array of currency strings
func (c Currencies) Strings() []string {
list := make([]string, len(c))
Expand Down
12 changes: 12 additions & 0 deletions currency/currencies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package currency
import (
"encoding/json"
"testing"

"github.com/stretchr/testify/assert"
)

func TestCurrenciesUnmarshalJSON(t *testing.T) {
Expand Down Expand Up @@ -62,3 +64,13 @@ func TestMatch(t *testing.T) {
t.Fatal("should not match")
}
}

func TestCurrenciesAdd(t *testing.T) {
c := Currencies{}
c = c.Add(BTC)
assert.Len(t, c, 1, "Should have one currency")
c = c.Add(ETH)
assert.Len(t, c, 2, "Should have one currency")
c = c.Add(BTC)
assert.Len(t, c, 2, "Adding a duplicate should not change anything")
}
209 changes: 160 additions & 49 deletions exchanges/kucoin/kucoin_test.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions exchanges/kucoin/kucoin_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ var (
errSizeOrFundIsRequired = errors.New("at least one required among size and funds")
errInvalidLeverage = errors.New("invalid leverage value")
errInvalidClientOrderID = errors.New("no client order ID supplied, this endpoint requires a UUID or similar string")
errInvalidMsgType = errors.New("message type field not valid")
errSubscriptionPairRequired = errors.New("pair required for manual subscriptions")

subAccountRegExp = regexp.MustCompile("^[a-zA-Z0-9]{7-32}$")
subAccountPassphraseRegExp = regexp.MustCompile("^[a-zA-Z0-9]{7-24}$")
Expand Down
Loading

0 comments on commit d3be869

Please sign in to comment.