mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
btcm: add order execution limit wrapper support (#941)
* btcm: add in order execution limit fetching * btcm/test: add t.Parrrrrralllleeellllllllll * btcm/wrapper: add update on startup * glorious: nits * thrasher: nit add status field
This commit is contained in:
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user