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:
Scott
2025-08-26 12:30:21 +10:00
committed by GitHub
parent fc0f262c42
commit 85403fe801
103 changed files with 1751 additions and 2168 deletions

View File

@@ -15,11 +15,12 @@ import (
"time"
"github.com/thrasher-corp/gocryptotrader/common/crypto"
"github.com/thrasher-corp/gocryptotrader/common/key"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
"github.com/thrasher-corp/gocryptotrader/exchange/order/limits"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
)
@@ -699,21 +700,20 @@ func (e *Exchange) GetCandleStick(ctx context.Context, symbol, interval string)
}
// FetchExchangeLimits fetches spot order execution limits
func (e *Exchange) FetchExchangeLimits(ctx context.Context) ([]order.MinMaxLevel, error) {
func (e *Exchange) FetchExchangeLimits(ctx context.Context) ([]limits.MinMaxLevel, error) {
ticks, err := e.GetAllTickers(ctx)
if err != nil {
return nil, err
}
limits := make([]order.MinMaxLevel, 0, len(ticks))
l := make([]limits.MinMaxLevel, 0, len(ticks))
for code, data := range ticks {
limits = append(limits, order.MinMaxLevel{
Pair: currency.NewPair(currency.NewCode(code), currency.KRW),
Asset: asset.Spot,
l = append(l, limits.MinMaxLevel{
Key: key.NewExchangeAssetPair(e.Name, asset.Spot, currency.NewPair(currency.NewCode(code), currency.KRW)),
MinimumBaseAmount: getAmountMinimum(data.ClosingPrice),
})
}
return limits, nil
return l, nil
}
// getAmountMinimum derives the minimum amount based on current price. This

View File

@@ -547,17 +547,17 @@ func TestGetHistoricTrades(t *testing.T) {
func TestUpdateOrderExecutionLimits(t *testing.T) {
t.Parallel()
err := e.UpdateOrderExecutionLimits(t.Context(), asset.Empty)
require.NoError(t, err, "UpdateOrderExecutionLimits must not error")
limit, err := e.GetOrderExecutionLimits(asset.Spot, testPair)
require.NoError(t, err, "GetOrderExecutionLimits must not error")
err = limit.Conforms(46241000, 0.00001, order.Limit)
assert.ErrorIs(t, err, order.ErrAmountBelowMin)
err = limit.Conforms(46241000, 0.0001, order.Limit)
assert.NoError(t, err, "Conforms should not error")
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.MinimumBaseAmount, "MinimumBaseAmount should be positive")
})
}
}
func TestGetAmountMinimum(t *testing.T) {

View File

@@ -13,6 +13,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/common/convert"
"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"
@@ -782,12 +783,15 @@ func (e *Exchange) GetHistoricCandlesExtended(_ context.Context, _ currency.Pair
}
// UpdateOrderExecutionLimits sets exchange executions for a required asset type
func (e *Exchange) UpdateOrderExecutionLimits(ctx context.Context, _ asset.Item) error {
limits, err := e.FetchExchangeLimits(ctx)
func (e *Exchange) UpdateOrderExecutionLimits(ctx context.Context, a asset.Item) error {
if !e.CurrencyPairs.IsAssetSupported(a) {
return fmt.Errorf("%w %q", asset.ErrNotSupported, a)
}
l, err := e.FetchExchangeLimits(ctx)
if err != nil {
return fmt.Errorf("cannot update exchange execution limits: %w", err)
}
return e.LoadLimits(limits)
return limits.Load(l)
}
// UpdateCurrencyStates updates currency states for exchange