diff --git a/exchanges/btcmarkets/btcmarkets_test.go b/exchanges/btcmarkets/btcmarkets_test.go index beb04243..fc5e3571 100644 --- a/exchanges/btcmarkets/btcmarkets_test.go +++ b/exchanges/btcmarkets/btcmarkets_test.go @@ -1040,3 +1040,25 @@ func TestGetTimeInForce(t *testing.T) { t.Fatalf("received: '%v' but expected: '%v'", f, fillOrKill) } } + +func TestUpdateOrderExecutionLimits(t *testing.T) { + t.Parallel() + err := b.UpdateOrderExecutionLimits(context.Background(), asset.Empty) + if !errors.Is(err, asset.ErrNotSupported) { + t.Fatalf("received: '%v' but expected: '%v'", err, asset.ErrNotSupported) + } + + err = b.UpdateOrderExecutionLimits(context.Background(), asset.Spot) + if !errors.Is(err, nil) { + t.Fatalf("received: '%v' but expected: '%v'", err, nil) + } + + lim, err := b.ExecutionLimits.GetOrderExecutionLimits(asset.Spot, currency.NewPair(currency.BTC, currency.AUD)) + if !errors.Is(err, nil) { + t.Fatalf("received: '%v' but expected: '%v'", err, nil) + } + + if lim == nil { + t.Fatal("expected value return") + } +} diff --git a/exchanges/btcmarkets/btcmarkets_types.go b/exchanges/btcmarkets/btcmarkets_types.go index dccdf29b..04632255 100644 --- a/exchanges/btcmarkets/btcmarkets_types.go +++ b/exchanges/btcmarkets/btcmarkets_types.go @@ -10,12 +10,13 @@ import ( // Market holds a tradable market instrument type Market struct { MarketID string `json:"marketId"` - BaseAsset string `json:"baseAsset"` - QuoteAsset string `json:"quoteAsset"` + BaseAsset string `json:"baseAssetName"` + QuoteAsset string `json:"quoteAssetName"` MinOrderAmount float64 `json:"minOrderAmount,string"` MaxOrderAmount float64 `json:"maxOrderAmount,string"` - AmountDecimals int64 `json:"amountDecimals,string"` - PriceDecimals int64 `json:"priceDecimals,string"` + AmountDecimals float64 `json:"amountDecimals,string"` + PriceDecimals float64 `json:"priceDecimals,string"` + Status string `json:"status"` } // Ticker holds ticker information diff --git a/exchanges/btcmarkets/btcmarkets_wrapper.go b/exchanges/btcmarkets/btcmarkets_wrapper.go index 6c63708c..b6ebcf96 100644 --- a/exchanges/btcmarkets/btcmarkets_wrapper.go +++ b/exchanges/btcmarkets/btcmarkets_wrapper.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "math" "sort" "strconv" "strings" @@ -255,6 +256,13 @@ func (b *BTCMarkets) Run() { } } + err = b.UpdateOrderExecutionLimits(context.TODO(), asset.Spot) + if err != nil { + log.Errorf(log.ExchangeSys, + "%s Failed to update order execution limits. Error: %v\n", + b.Name, err) + } + if !b.GetEnabledFeatures().AutoPairUpdates && !forceUpdate { return } @@ -1094,3 +1102,34 @@ func (b *BTCMarkets) GetHistoricCandlesExtended(ctx context.Context, p currency. func (b *BTCMarkets) GetServerTime(ctx context.Context, _ asset.Item) (time.Time, error) { return b.GetCurrentServerTime(ctx) } + +// UpdateOrderExecutionLimits sets exchange executions for a required asset type +func (b *BTCMarkets) UpdateOrderExecutionLimits(ctx context.Context, a asset.Item) error { + if a != asset.Spot { + return fmt.Errorf("%s %w", a, asset.ErrNotSupported) + } + + markets, err := b.GetMarkets(ctx) + if err != nil { + return err + } + + limits := make([]order.MinMaxLevel, len(markets)) + for x := range markets { + var pair currency.Pair + pair, err = currency.NewPairFromStrings(markets[x].BaseAsset, markets[x].QuoteAsset) + if err != nil { + return err + } + + limits[x] = order.MinMaxLevel{ + Pair: pair, + Asset: asset.Spot, + MinAmount: markets[x].MinOrderAmount, + MaxAmount: markets[x].MaxOrderAmount, + StepAmount: math.Pow(10, -markets[x].AmountDecimals), + StepPrice: math.Pow(10, -markets[x].PriceDecimals), + } + } + return b.LoadLimits(limits) +}