Skip to content
This repository was archived by the owner on Feb 1, 2024. It is now read-only.
This repository was archived by the owner on Feb 1, 2024. It is now read-only.

op_underfunded issue when no price or amount triggers for existing oversold offer #256

@nikhilsaraf

Description

@nikhilsaraf

Describe the bug

The bot does not check whether the capacity limit is hit for offers that could be modified and are not triggered by price or amount changes. It adds the liabilities correctly, which would exceed the balance but has no mechanism to reduce the offer.

Expected behavior

I think the correct behavior in this situation is for the bot to also constrain offers that do not need modification because of price or amount triggers. maybe introduce a new trigger called oversell

Frequency

The frequency is: Always

Steps To Reproduce

Here are the steps to reproduce the issue (see attachments in section below):

  1. Create bot with balance of XLM equaling 5,000
  2. Produce 2 levels at fixed price X and Y for amounts 2,500 XLM each
  3. Take the first offer at price X for 1000 XLM
  4. assume price of XLM does not change because we are using a fixed feed (or a feed that didn't change)
  5. the bot tries to re-place the offer at level 1 for price X in the amount of 2,500 XLM, which it can do because the XLM balance is 4,000 XLM
  6. the bot does not try and modify the level 2 offer even though it cannot support a 2,500 XLM offer at level 2 because there is no price or amount trigger for this level, which results in an op_underfunded error
    ...

Possible Solution

This bug can be fixed by introducing a new trigger called oversell which also triggers an update in offers. this is triggered when the offer's amount cannot be supported anymore.

Your Environment

version: master:v1.7.0-57-g8ea336c3
git branch: master
git hash: 8ea336c
build date: 20190820T124035Z
env: dev
GOOS: linux
GOARCH: amd64

Context

I am unable to reliably place offers and use kelp because of this bug.

Attachments

2019/08/20 17:28:21  (base) assetA=native, maxA=3086.86086210, trustA=math.MaxFloat64
2019/08/20 17:28:21 (quote) assetB=COUPON:GBMMZMK2DC4FFP4CAI6KCVNCQ7WLO5A7DQU7EC7WGHRDQBZB763X4OQI, maxB=464.30084720, trustB=922337203685.47753906
2019/08/20 17:28:21 orderConstraints for trading pair XLM/COUPON: OrderConstraints[PricePrecision: 7, VolumePrecision: 7, MinBaseVolume: 0.0000001, MinQuoteVolume: <nil>]
2019/08/20 17:28:22 liabilities after resetting
2019/08/20 17:28:23 asset=base  , balance=3086.86086210, trust=math.MaxFloat64, minAccountBal=24.00000000, buyingLiabilities=0.00000000, sellingLiabilities=0.00000000
2019/08/20 17:28:23 asset=quote , balance=464.30084720, trust=922337203685.47753906, minAccountBal=0.46430085, buyingLiabilities=0.00000000, sellingLiabilities=0.00000000
2019/08/20 17:28:23 returning kraken API key at index 0
2019/08/20 17:28:23 price from exchange feed (kraken/XXLM/ZUSD): bidPrice=0.0692140, askPrice=0.0694120, centerPrice=0.0693130
2019/08/20 17:28:23 feedPair prices: feedA=1.0000000, feedB=0.0693130; centerPrice=14.4273080
2019/08/20 17:28:23 center price (adjusted): 16.8597104
2019/08/20 17:28:23 returning kraken API key at index 0
2019/08/20 17:28:24 price from exchange feed (kraken/XXLM/ZUSD): bidPrice=0.0692140, askPrice=0.0694110, centerPrice=0.0693125
2019/08/20 17:28:24 feedPair prices: feedA=0.0693125, feedB=1.0000000; centerPrice=0.0693125
2019/08/20 17:28:24 center price (adjusted): 0.0593125
2019/08/20 17:28:24 offer | buy  | level=1 | curPriceQuote=0.05925774 | curAmtBase=2500.00000080 | pruning=false
2019/08/20 17:28:24 offer | buy  | level=2 | curPriceQuote=0.05919860 | curAmtBase=2500.00000065 | pruning=false
2019/08/20 17:28:24 offer | buy  | level=3 | curPriceQuote=0.05913958 | curAmtBase=2500.00000070 | pruning=false
2019/08/20 17:28:24 offer | sell | level=1 | curPriceQuote=0.05937630 | curAmtBase=2500.00000000 | pruning=false
2019/08/20 17:28:24 offer | sell | level=2 | curPriceQuote=0.05943560 | curAmtBase=562.86086120 | pruning=false
2019/08/20 17:28:24 created 0 operations to prune excess offers
2019/08/20 17:28:25 liabilities after resetting
2019/08/20 17:28:25 asset=base  , balance=3086.86086210, trust=math.MaxFloat64, minAccountBal=24.00000000, buyingLiabilities=0.00000000, sellingLiabilities=0.00000000
2019/08/20 17:28:25 asset=quote , balance=464.30084720, trust=922337203685.47753906, minAccountBal=0.46430085, buyingLiabilities=0.00000000, sellingLiabilities=0.00000000
2019/08/20 17:28:25 buy , done creating preceding offers (numLevelsConsumed=0, hitCapacityLimit=false, numOps=0, newTopOfferPrice=<nil>)
2019/08/20 17:28:25 buy  | modify | unmodified original level = 1 | newLevel number = 1
2019/08/20 17:28:25 buy  | modify | unmodified original level = 2 | newLevel number = 2
2019/08/20 17:28:25 buy  | modify | unmodified original level = 3 | newLevel number = 3
2019/08/20 17:28:25 sell | create | new level=1 | priceQuote=0.05937180 | amtBase=2500.00000000
2019/08/20 17:28:25 sell, done creating preceding offers (numLevelsConsumed=1, hitCapacityLimit=false, numOps=1, newTopOfferPrice=0.0593718)
2019/08/20 17:28:25 sell | modify | unmodified original level = 1 | newLevel number = 2
2019/08/20 17:28:25 sell | modify | old level=2 | new level = 3 | triggers=[amount] | targetPriceQuote=0.05949040 | targetAmtBase=2500.00000000 | curPriceQuote=0.05943560 | lowPriceQuote=0.05651588 | highPriceQuote=0.06246492 | curAmtBase=562.86086120 | minAmtBase=2497.50000000 | maxAmtBase=2502.50000000
2019/08/20 17:28:25 we will oversell the asset 'native', amountSelling = 2500.00000000, bal = 3086.86086210, minAccountBal = 24.00000000, liabilities.Selling = 5000.50000000
2019/08/20 17:28:25 computed remainder amount, no capacity available: availableSellingCapacity=-1937.63913790, availableBuyingCapacity=922337203388.60729980
2019/08/20 17:28:25 liabilities at the end of a call to UpdateWithOps
2019/08/20 17:28:25 asset=base  , balance=3086.86086210, trust=math.MaxFloat64, minAccountBal=24.00000000, buyingLiabilities=7500.00000215, sellingLiabilities=5000.50000000
2019/08/20 17:28:25 asset=quote , balance=464.30084720, trust=922337203685.47753906, minAccountBal=0.46430085, buyingLiabilities=296.87025000, sellingLiabilities=443.98981610
2019/08/20 17:28:25 orderConstraintsFilter: selling, baseAmount=2500.00000000, quoteAmount=148.42950000, keep = true
2019/08/20 17:28:25 orderConstraintsFilter: dropped 0, kept 1 ops from original 1 ops, len(filteredOps) = 1
2019/08/20 17:28:25 created 1 operations to update existing offers
2019/08/20 17:28:25 reloading sequence number
2019/08/20 17:28:25 lastFee <= maxOpFeeStroops; using last_ledger_base_fee of 100 stroops (maxOpFeeStroops = 5000)
2019/08/20 17:28:25 tx XDR: AAAAAE9zGoPa0Ask5Xf/v4uTK0Yxrz/gvVCR5en7u7YiqilsAAAAZAAAIQsAAAB8AAAAAAAAAAAAAAABAAAAAQAAAACD+yIbmhaVvdPhP4Y7BfA7NWI2VvJ09pH1FD+P7U1s2wAAAAMAAAAAAAAAAkNPVVBPTgAAAAAAAAAAAABYzLFaGLhSv4ICPKFVoofst3QfHCnyC/Yx4jgHIf+3fgAAAAXSHboAAASHmwBMS0AAAAAAAAAAAAAAAAAAAAACIqopbAAAAECNh0dlnWlw57MXN6DE+n/ctZGmU9EyzH2UY1AwYa7q+DgzMBUHm/J7Q9m7f4ZIaIxEO1VkH1J1gyQ/Guzt3osJ7U1s2wAAAEDwXspkQfyksx3BuYm0mDlgZ3THTCBwfAiiSsj1egHUUmKCyzGTA5eMLBGyBr2gf/YM6nmepvDflrMFsmB/pocE
2019/08/20 17:28:25 submitting tx XDR to network (async)
2019/08/20 17:28:29 (async) error: result code details: tx code = tx_failed , opcodes = [op_underfunded]

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions