mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-05 07:26:47 +00:00
ftx: add basic exchange order execution limits for lower bound (#725)
* ftx: add basic exchange order execution limits for lower bound * ftx/binance: conform to standard logger output * ftx: fix field from SizeIncrement -> MinProvideSize * limits: fix whoopsie * limit: add tests * ftx: fix comment
This commit is contained in:
@@ -98,6 +98,11 @@ func (e *ExecutionLimits) LoadLimits(levels []MinMaxLevel) error {
|
||||
}
|
||||
|
||||
for x := range levels {
|
||||
if !levels[x].Asset.IsValid() {
|
||||
return fmt.Errorf("cannot load levels for '%s': %w",
|
||||
levels[x].Asset,
|
||||
asset.ErrNotSupported)
|
||||
}
|
||||
m1, ok := e.m[levels[x].Asset]
|
||||
if !ok {
|
||||
m1 = make(map[*currency.Item]map[*currency.Item]*Limits)
|
||||
@@ -116,7 +121,9 @@ func (e *ExecutionLimits) LoadLimits(levels []MinMaxLevel) error {
|
||||
m2[levels[x].Pair.Quote.Item] = limit
|
||||
}
|
||||
|
||||
if levels[x].MinPrice > levels[x].MaxPrice {
|
||||
if levels[x].MinPrice > 0 &&
|
||||
levels[x].MaxPrice > 0 &&
|
||||
levels[x].MinPrice > levels[x].MaxPrice {
|
||||
return fmt.Errorf("%w for %s %s supplied min: %f max: %f",
|
||||
errInvalidPriceLevels,
|
||||
levels[x].Asset,
|
||||
@@ -125,7 +132,9 @@ func (e *ExecutionLimits) LoadLimits(levels []MinMaxLevel) error {
|
||||
levels[x].MaxPrice)
|
||||
}
|
||||
|
||||
if levels[x].MinAmount > levels[x].MaxAmount {
|
||||
if levels[x].MinAmount > 0 &&
|
||||
levels[x].MaxAmount > 0 &&
|
||||
levels[x].MinAmount > levels[x].MaxAmount {
|
||||
return fmt.Errorf("%w for %s %s supplied min: %f max: %f",
|
||||
errInvalidAmountLevels,
|
||||
levels[x].Asset,
|
||||
|
||||
@@ -20,6 +20,22 @@ func TestLoadLimits(t *testing.T) {
|
||||
t.Fatalf("expected error %v but received %v", errCannotLoadLimit, err)
|
||||
}
|
||||
|
||||
invalidAsset := []MinMaxLevel{
|
||||
{
|
||||
Pair: btcusd,
|
||||
MinPrice: 100000,
|
||||
MaxPrice: 1000000,
|
||||
MinAmount: 1,
|
||||
MaxAmount: 10,
|
||||
},
|
||||
}
|
||||
err = e.LoadLimits(invalidAsset)
|
||||
if !errors.Is(err, asset.ErrNotSupported) {
|
||||
t.Fatalf("expected error %v but received %v",
|
||||
asset.ErrNotSupported,
|
||||
err)
|
||||
}
|
||||
|
||||
newLimits := []MinMaxLevel{
|
||||
{
|
||||
Pair: btcusd,
|
||||
@@ -79,6 +95,32 @@ func TestLoadLimits(t *testing.T) {
|
||||
if !errors.Is(err, nil) {
|
||||
t.Fatalf("expected error %v but received %v", nil, err)
|
||||
}
|
||||
|
||||
noCompare := []MinMaxLevel{
|
||||
{
|
||||
Pair: btcusd,
|
||||
Asset: asset.Spot,
|
||||
MinAmount: 10,
|
||||
},
|
||||
}
|
||||
|
||||
err = e.LoadLimits(noCompare)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Fatalf("expected error %v but received %v", nil, err)
|
||||
}
|
||||
|
||||
noCompare = []MinMaxLevel{
|
||||
{
|
||||
Pair: btcusd,
|
||||
Asset: asset.Spot,
|
||||
MinPrice: 10,
|
||||
},
|
||||
}
|
||||
|
||||
err = e.LoadLimits(noCompare)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Fatalf("expected error %v but received %v", nil, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetOrderExecutionLimits(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user