mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
gateio: Implement UpdateOrderExecutionLimits for spot instruments (#1281)
* gateio: limits (cherry-pick) * clean * linter: fix --------- Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
This commit is contained in:
@@ -3319,3 +3319,57 @@ func TestGateioNumericalValue(t *testing.T) {
|
||||
t.Fatalf("found %f, but expected %d", in.Number, 0)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateOrderExecutionLimits(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
err := g.UpdateTradablePairs(context.Background(), true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = g.UpdateOrderExecutionLimits(context.Background(), 1336)
|
||||
if !errors.Is(err, asset.ErrNotSupported) {
|
||||
t.Fatalf("received %v, expected %v", err, asset.ErrNotSupported)
|
||||
}
|
||||
|
||||
err = g.UpdateOrderExecutionLimits(context.Background(), asset.Options)
|
||||
if !errors.Is(err, common.ErrNotYetImplemented) {
|
||||
t.Fatalf("received %v, expected %v", err, common.ErrNotYetImplemented)
|
||||
}
|
||||
|
||||
err = g.UpdateOrderExecutionLimits(context.Background(), asset.Spot)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
avail, err := g.GetAvailablePairs(asset.Spot)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for i := range avail {
|
||||
mm, err := g.GetOrderExecutionLimits(asset.Spot, avail[i])
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if mm == (order.MinMaxLevel{}) {
|
||||
t.Fatal("expected a value")
|
||||
}
|
||||
|
||||
if mm.MinimumBaseAmount <= 0 {
|
||||
t.Fatalf("MinimumBaseAmount expected 0 but received %v for %v", mm.MinimumBaseAmount, avail[i])
|
||||
}
|
||||
|
||||
// 1INCH_TRY no minimum quote or base values are returned.
|
||||
|
||||
if mm.QuoteStepIncrementSize <= 0 {
|
||||
t.Fatalf("QuoteStepIncrementSize expected 0 but received %v for %v", mm.QuoteStepIncrementSize, avail[i])
|
||||
}
|
||||
|
||||
if mm.AmountStepIncrementSize <= 0 {
|
||||
t.Fatalf("AmountStepIncrementSize expected 0 but received %v for %v", mm.AmountStepIncrementSize, avail[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1995,3 +1995,58 @@ func (g *Gateio) checkInstrumentAvailabilityInSpot(instrument currency.Pair) (bo
|
||||
}
|
||||
return availables.Contains(instrument, true), nil
|
||||
}
|
||||
|
||||
// UpdateOrderExecutionLimits sets exchange executions for a required asset type
|
||||
func (g *Gateio) UpdateOrderExecutionLimits(ctx context.Context, a asset.Item) error {
|
||||
if !g.SupportsAsset(a) {
|
||||
return fmt.Errorf("%s %w", a, asset.ErrNotSupported)
|
||||
}
|
||||
|
||||
avail, err := g.GetAvailablePairs(a)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var limits []order.MinMaxLevel
|
||||
switch a {
|
||||
case asset.Spot:
|
||||
var pairsData []CurrencyPairDetail
|
||||
pairsData, err := g.ListSpotCurrencyPairs(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
limits = make([]order.MinMaxLevel, 0, len(pairsData))
|
||||
for x := range pairsData {
|
||||
if pairsData[x].TradeStatus == "untradable" {
|
||||
continue
|
||||
}
|
||||
var pair currency.Pair
|
||||
pair, err = avail.DeriveFrom(strings.ReplaceAll(pairsData[x].ID, "_", ""))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Minimum base amounts are not always provided this will default to
|
||||
// precision for base deployment. This can't be done for quote.
|
||||
minBaseAmount := pairsData[x].MinBaseAmount.Float64()
|
||||
if minBaseAmount == 0 {
|
||||
minBaseAmount = math.Pow10(-int(pairsData[x].AmountPrecision))
|
||||
}
|
||||
|
||||
limits = append(limits, order.MinMaxLevel{
|
||||
Asset: a,
|
||||
Pair: pair,
|
||||
QuoteStepIncrementSize: math.Pow10(-int(pairsData[x].Precision)),
|
||||
AmountStepIncrementSize: math.Pow10(-int(pairsData[x].AmountPrecision)),
|
||||
MinimumBaseAmount: minBaseAmount,
|
||||
MinimumQuoteAmount: pairsData[x].MinQuoteAmount.Float64(),
|
||||
})
|
||||
}
|
||||
default:
|
||||
// TODO: Add in other assets
|
||||
return fmt.Errorf("%s %w", a, common.ErrNotYetImplemented)
|
||||
}
|
||||
|
||||
return g.LoadLimits(limits)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user