mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-04 23:16:54 +00:00
exchange/order/limits: Migrate to new package and integrate with exchanges (#1860)
* move limits, transition to key gen * rollout NewExchangePairAssetKey everywhere * test improvements * self-review fixes * ok, lets go * fix merge issue * slower value func,assertify,drop IsValidPairString * remove binance reference for backtesting test * Redundant nil checks removed due to redundancy * Update order_test.go * Move limits back into /exchanges/ * puts limits in a different box again * SHAZBERT SPECIAL SUGGESTIONS * Update gateio_wrapper.go * fixes all build issues * Many niteroos! * something has gone awry * bugfix * gk's everywhere nits * lint * extra lint * re-remove IsValidPairString * lint fix * standardise test * revert some bads * dupe rm * another revert 360 mcgee * un-in-revertify * Update exchange/order/limits/levels_test.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> * fix * Update exchanges/binance/binance_test.go HERE'S HOPING GITHUB FORMATS THIS CORRECTLY! Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * update text * rn func, same line err gk4202000 --------- Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>
This commit is contained in:
@@ -241,42 +241,24 @@ func TestUpdateTradablePairs(t *testing.T) {
|
||||
|
||||
func TestUpdateOrderExecutionLimits(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
type limitTest struct {
|
||||
pair currency.Pair
|
||||
step float64
|
||||
min float64
|
||||
}
|
||||
|
||||
tests := map[asset.Item][]limitTest{
|
||||
asset.Spot: {
|
||||
{currency.NewPair(currency.ETH, currency.USDT), 0.01, 20},
|
||||
{currency.NewBTCUSDT(), 0.01, 20},
|
||||
},
|
||||
}
|
||||
for assetItem, limitTests := range tests {
|
||||
if err := e.UpdateOrderExecutionLimits(t.Context(), assetItem); err != nil {
|
||||
t.Errorf("Error fetching %s pairs for test: %v", assetItem, err)
|
||||
}
|
||||
for _, limitTest := range limitTests {
|
||||
limits, err := e.GetOrderExecutionLimits(assetItem, limitTest.pair)
|
||||
if err != nil {
|
||||
t.Errorf("Bitstamp GetOrderExecutionLimits() error during TestExecutionLimits; Asset: %s Pair: %s Err: %v", assetItem, limitTest.pair, err)
|
||||
continue
|
||||
}
|
||||
assert.NotEmpty(t, limits.Pair, "Pair should not be empty")
|
||||
assert.Positive(t, limits.PriceStepIncrementSize, "PriceStepIncrementSize should be positive")
|
||||
assert.Positive(t, limits.AmountStepIncrementSize, "AmountStepIncrementSize should be positive")
|
||||
assert.Positive(t, limits.MinimumQuoteAmount, "MinimumQuoteAmount should be positive")
|
||||
for _, a := range e.GetAssetTypes(false) {
|
||||
t.Run(a.String(), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
require.NoError(t, e.UpdateOrderExecutionLimits(t.Context(), a), "UpdateOrderExecutionLimits must not error")
|
||||
pairs, err := e.CurrencyPairs.GetPairs(a, false)
|
||||
require.NoError(t, err, "GetPairs must not error")
|
||||
l, err := e.GetOrderExecutionLimits(a, pairs[0])
|
||||
require.NoError(t, err, "GetOrderExecutionLimits must not error")
|
||||
assert.Positive(t, l.PriceStepIncrementSize, "PriceStepIncrementSize should not be zero")
|
||||
assert.NotEmpty(t, l.Key.Pair(), "Pair should not be empty")
|
||||
assert.Positive(t, l.PriceStepIncrementSize, "PriceStepIncrementSize should be positive")
|
||||
assert.Positive(t, l.AmountStepIncrementSize, "AmountStepIncrementSize should be positive")
|
||||
assert.Positive(t, l.MinimumQuoteAmount, "MinimumQuoteAmount should be positive")
|
||||
if mockTests {
|
||||
if got := limits.PriceStepIncrementSize; got != limitTest.step {
|
||||
t.Errorf("Bitstamp UpdateOrderExecutionLimits wrong PriceStepIncrementSize; Asset: %s Pair: %s Expected: %v Got: %v", assetItem, limitTest.pair, limitTest.step, got)
|
||||
}
|
||||
if got := limits.MinimumQuoteAmount; got != limitTest.min {
|
||||
t.Errorf("Bitstamp UpdateOrderExecutionLimits wrong MinAmount; Pair: %s Expected: %v Got: %v", limitTest.pair, limitTest.min, got)
|
||||
}
|
||||
assert.Equal(t, 0.01, l.PriceStepIncrementSize, "PriceStepIncrementSize should be 0.01")
|
||||
assert.Equal(t, 20., l.MinimumQuoteAmount, "MinimumQuoteAmount should be 20")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,8 +10,10 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/common/key"
|
||||
"github.com/thrasher-corp/gocryptotrader/config"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchange/order/limits"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchange/websocket"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/account"
|
||||
@@ -215,7 +217,7 @@ func (e *Exchange) UpdateOrderExecutionLimits(ctx context.Context, a asset.Item)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
limits := make([]order.MinMaxLevel, 0, len(symbols))
|
||||
l := make([]limits.MinMaxLevel, 0, len(symbols))
|
||||
for x, info := range symbols {
|
||||
if symbols[x].Trading != "Enabled" {
|
||||
continue
|
||||
@@ -224,15 +226,14 @@ func (e *Exchange) UpdateOrderExecutionLimits(ctx context.Context, a asset.Item)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
limits = append(limits, order.MinMaxLevel{
|
||||
Asset: a,
|
||||
Pair: pair,
|
||||
l = append(l, limits.MinMaxLevel{
|
||||
Key: key.NewExchangeAssetPair(e.Name, a, pair),
|
||||
PriceStepIncrementSize: math.Pow10(-info.CounterDecimals),
|
||||
AmountStepIncrementSize: math.Pow10(-info.BaseDecimals),
|
||||
MinimumQuoteAmount: info.MinimumOrder,
|
||||
})
|
||||
}
|
||||
if err := e.LoadLimits(limits); err != nil {
|
||||
if err := limits.Load(l); err != nil {
|
||||
return fmt.Errorf("%s Error loading exchange limits: %v", e.Name, err)
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user