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

balanced trading template does not handle case when no trades on new market #737

Open
nikhilsaraf opened this issue Sep 23, 2021 · 0 comments
Labels
bug Something isn't working
Milestone

Comments

@nikhilsaraf
Copy link
Contributor

Describe the bug

Horizon has a weird response for /trades when the market is new. We handle this somewhere in kelp, I think in the mirror trading template, but not in the main sideStrategy logic. For that reason the balanced, and probably all other trading templates, fail when fetching trades.

Expected behavior

The current workaround is to manually trigger a trade on this new market so we don't encounter this issue. It is rarely an issue on mainnet because there are few occasions where a new asset is created relative to on testnet (owing to testnet resets).

Frequency

The frequency is: always under the above described conditions

Steps To Reproduce

see above

Possible Solution

This bug can be fixed by fixing the code at the point where we fetch trades for the market. Look at the mirror trading template to see how it is handled there (IIRC that's where it's done correctly but I could be wrong).

Your Environment

master:v1.11.0-28-gba17509a [ba17509]
circle-ci

cli version: master:v1.11.0-28-gba17509a
gui version: v1.0.0-rc2
git branch: master
git hash: ba17509
build date: 20210923T145554Z
build type: cli
env: dev
GOOS: linux
GOARCH: amd64

Context

I am unable to run strategies on new markets because of this bug.

Attachments

2021/09/23 15:12:12 Starting Kelp Trader: master:v1.11.0-28-gba17509a [ba17509ade15afbc8c4363ab6ae0a0dd8db08567]
2021/09/23 15:12:12 will run only 1 update iterations
2021/09/23 15:12:12 configs:
2021/09/23 15:12:12      SOURCE_SECRET_SEED: [secret key to account GBCVBQDCFPOTNQX4A4ZTIJNCARSRK24C7TGG5QZBKOVQL3FDA4HVJ3MJ]
2021/09/23 15:12:12      TRADING_SECRET_SEED: [secret key to account GBCVBQDCFPOTNQX4A4ZTIJNCARSRK24C7TGG5QZBKOVQL3FDA4HVJ3MJ]
2021/09/23 15:12:12      ASSET_CODE_A: XLM
2021/09/23 15:12:12      ISSUER_A: 
2021/09/23 15:12:12      ASSET_CODE_B: CITEST
2021/09/23 15:12:12      ISSUER_B: GBMMZMK2DC4FFP4CAI6KCVNCQ7WLO5A7DQU7EC7WGHRDQBZB763X4OQI
2021/09/23 15:12:12      TICK_INTERVAL_MILLIS: 300000
2021/09/23 15:12:12      MAX_TICK_DELAY_MILLIS: 0
2021/09/23 15:12:12      SLEEP_MODE: 
2021/09/23 15:12:12      DELETE_CYCLES_THRESHOLD: 0
2021/09/23 15:12:12      SUBMIT_MODE: both
2021/09/23 15:12:12      FILL_TRACKER_SLEEP_MILLIS: 150000
2021/09/23 15:12:12      FILL_TRACKER_DELETE_CYCLES_THRESHOLD: 0
2021/09/23 15:12:12      SYNCHRONIZE_STATE_LOAD_ENABLE: false
2021/09/23 15:12:12      SYNCHRONIZE_STATE_LOAD_MAX_RETRIES: 0
2021/09/23 15:12:12      FILL_TRACKER_LAST_TRADE_CURSOR_OVERRIDE: 
2021/09/23 15:12:12      HORIZON_URL: https://horizon-testnet.stellar.org
2021/09/23 15:12:12      CCXT_REST_URL: <nil>
2021/09/23 15:12:12      DOLLAR_VALUE_FEED_BASE_ASSET: 
2021/09/23 15:12:12      DOLLAR_VALUE_FEED_QUOTE_ASSET: 
2021/09/23 15:12:12      FEE: 
2021/09/23 15:12:12          CAPACITY_TRIGGER: 0.8
2021/09/23 15:12:12          PERCENTILE: 90
2021/09/23 15:12:12          MAX_OP_FEE_STROOPS: 5000
2021/09/23 15:12:12      CENTRALIZED_PRICE_PRECISION_OVERRIDE: <nil>
2021/09/23 15:12:12      CENTRALIZED_VOLUME_PRECISION_OVERRIDE: <nil>
2021/09/23 15:12:12      CENTRALIZED_MIN_BASE_VOLUME_OVERRIDE: <nil>
2021/09/23 15:12:12      CENTRALIZED_MIN_QUOTE_VOLUME_OVERRIDE: <nil>
2021/09/23 15:12:12      POSTGRES_DB: <nil>
2021/09/23 15:12:12      DB_OVERRIDE__ACCOUNT_ID: 
2021/09/23 15:12:12      FILTERS: []
2021/09/23 15:12:12      ALERT_TYPE: 
2021/09/23 15:12:12      ALERT_API_KEY: 
2021/09/23 15:12:12      MONITORING_PORT: 0
2021/09/23 15:12:12      MONITORING_TLS_CERT: 
2021/09/23 15:12:12      MONITORING_TLS_KEY: 
2021/09/23 15:12:12      GOOGLE_CLIENT_ID: 
2021/09/23 15:12:12      GOOGLE_CLIENT_SECRET: 
2021/09/23 15:12:12      ACCEPTABLE_GOOGLE_EMAILS: 
2021/09/23 15:12:12      TRADING_EXCHANGE: 
2021/09/23 15:12:12      EXCHANGE_API_KEYS: 
2021/09/23 15:12:12      EXCHANGE_PARAMS: 
2021/09/23 15:12:12      EXCHANGE_HEADERS: 
2021/09/23 15:12:12 Trading XLM: for CITEST:GBMMZMK2DC4FFP4CAI6KCVNCQ7WLO5A7DQU7EC7WGHRDQBZB763X4OQI
2021/09/23 15:12:12 metric - not sending event metric of type 'bot_startup' because metrics are disabled
2021/09/23 15:12:12 using client.AppName = kelp--cli--bot
2021/09/23 15:12:12 using CCXT-rest URL: http://localhost:3000
2021/09/23 15:12:12 Using network passphrase: Test SDF Network ; September 2015
2021/09/23 15:12:12 Making strategy: balanced
2021/09/23 15:12:12 configs:
2021/09/23 15:12:12      PRICE_TOLERANCE: 0.1
2021/09/23 15:12:12      AMOUNT_TOLERANCE: 0.1
2021/09/23 15:12:12      SPREAD: 0.001
2021/09/23 15:12:12      MIN_AMOUNT_SPREAD: 0.0005
2021/09/23 15:12:12      MAX_AMOUNT_SPREAD: 0.0005
2021/09/23 15:12:12      MAX_LEVELS: 2
2021/09/23 15:12:12      LEVEL_DENSITY: 1
2021/09/23 15:12:12      ENSURE_FIRST_N_LEVELS: 10
2021/09/23 15:12:12      MIN_AMOUNT_CARRYOVER_SPREAD: 0.01
2021/09/23 15:12:12      MAX_AMOUNT_CARRYOVER_SPREAD: 0.01
2021/09/23 15:12:12      CARRYOVER_INCLUSION_PROBABILITY: 1
2021/09/23 15:12:12      VIRTUAL_BALANCE_BASE: 0
2021/09/23 15:12:12      VIRTUAL_BALANCE_QUOTE: 0
2021/09/23 15:12:12 received a Resource Missing error while fetching trades, treating as if no trades exist for this trading pair and continuing: horizon error: "Resource Missing" - check horizon.Error.Problem for more information
2021/09/23 15:12:12 set latest trade cursor from where to start tracking fills (no override specified): <nil>
2021/09/23 15:12:12 validating trustlines...
2021/09/23 15:12:12 trustlines valid
2021/09/23 15:12:12 Starting fill tracker with 3 handlers
2021/09/23 15:12:12 Starting the trader bot...
2021/09/23 15:12:12 ----------------------------------------------------------------------------------------------------
2021/09/23 15:12:12 returned from fetch trades API call for SDEX using cursor '' (len(records) = 0, error = <nil>)
2021/09/23 15:12:12 there were no trades, leaving lastCursor value as <nil>
2021/09/23 15:12:13 synchronized state loading is disabled
2021/09/23 15:12:13  (base) assetA=native, maxA=9999.99996000, trustA=math.MaxFloat64
2021/09/23 15:12:13 (quote) assetB=CITEST:GBMMZMK2DC4FFP4CAI6KCVNCQ7WLO5A7DQU7EC7WGHRDQBZB763X4OQI, maxB=0.00000000, trustB=922337203685.47753906
2021/09/23 15:12:13 orderConstraints for trading pair XLM/CITEST: OrderConstraints[PricePrecision: 7, VolumePrecision: 7, MinBaseVolume: 0.0000001, MinQuoteVolume: <nil>]
2021/09/23 15:12:13 liabilities after resetting
2021/09/23 15:12:13 asset=base  , balance=9999.99996000, trust=math.MaxFloat64, minAccountBal=22.50000000, buyingLiabilities=0.00000000, sellingLiabilities=0.00000000
2021/09/23 15:12:13 asset=quote , balance=0.00000000, trust=922337203685.47753906, minAccountBal=0.00000000, buyingLiabilities=0.00000000, sellingLiabilities=0.00000000
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x5f01a1]

goroutine 1 [running]:
math/big.(*Rat).Mul(0x0, 0x0, 0xc0005a5148, 0xc0005a5148)
	/usr/local/go/src/math/big/rat.go:526 +0x1c1
github.com/stellar/kelp/model.toFixed(0x7ff0000000000000, 0x3f40624dd2f1a907, 0x0, 0x3f40624dd2f1a9fc)
	/home/circleci/project/model/number.go:211 +0x152
github.com/stellar/kelp/model.NumberFromFloat(...)
	/home/circleci/project/model/number.go:126
github.com/stellar/kelp/plugins.(*balancedLevelProvider).getLevel(0xc000334510, 0x0, 0x40c387fffeb074a7, 0x95, 0xc00038c600, 0xc000110030, 0x5c723c0, 0xc0005a52c8, 0x4f38e0)
	/home/circleci/project/plugins/balancedLevelProvider.go:197 +0xee
github.com/stellar/kelp/plugins.(*balancedLevelProvider).recomputeLevels(0xc000334510, 0x0, 0x40c387fffeb074a7, 0xc0004597c0, 0xd64c75, 0xc000590120, 0x30, 0x5c90840)
	/home/circleci/project/plugins/balancedLevelProvider.go:222 +0xd9
github.com/stellar/kelp/plugins.(*balancedLevelProvider).GetLevels(0xc000334510, 0x0, 0x40c387fffeb074a7, 0x100, 0x30, 0x0, 0xc15660, 0xc00055e040)
	/home/circleci/project/plugins/balancedLevelProvider.go:114 +0x51
github.com/stellar/kelp/plugins.(*sellSideStrategy).PreUpdate(0xc0003345a0, 0x0, 0x40c387fffeb074a7, 0x426ad7f29abcaf48, 0x7fefffffffffffff, 0xd64c75, 0x6)
	/home/circleci/project/plugins/sellSideStrategy.go:141 +0x74
github.com/stellar/kelp/plugins.(*composeStrategy).PreUpdate(0xc0002d9500, 0x40c387fffeb074a7, 0x0, 0x7fefffffffffffff, 0x426ad7f29abcaf48, 0x0, 0x0)
	/home/circleci/project/plugins/composeStrategy.go:52 +0x74
github.com/stellar/kelp/trader.(*Trader).update(0xc00000c1e0, 0x0, 0x0, 0x0, 0x0, 0x0)
	/home/circleci/project/trader/trader.go:429 +0x683
github.com/stellar/kelp/trader.(*Trader).Start(0xc00000c1e0)
	/home/circleci/project/trader/trader.go:144 +0x304
github.com/stellar/kelp/cmd.runTradeCmd(0xc0000b42d0, 0xc0000b42e0, 0xc0000b4300, 0xc00003c1c8, 0xc00003c1d8, 0xc00003c1e5, 0xc0000b4310, 0xc00003c1e8, 0xc00003c1f0, 0xc0000b4320, ...)
	/home/circleci/project/cmd/trade.go:824 +0x1fea
github.com/stellar/kelp/cmd.init.5.func1(0x5c60920, 0xc0002ee280, 0x0, 0x8)
	/home/circleci/project/cmd/trade.go:208 +0xaa
github.com/spf13/cobra.(*Command).execute(0x5c60920, 0xc0002ee200, 0x8, 0x8, 0x5c60920, 0xc0002ee200)
	/go/pkg/mod/github.com/spf13/[email protected]/command.go:702 +0x285
github.com/spf13/cobra.(*Command).ExecuteC(0x5c602c0, 0x0, 0x0, 0x0)
	/go/pkg/mod/github.com/spf13/[email protected]/command.go:783 +0x2c9
github.com/spf13/cobra.(*Command).Execute(...)
	/go/pkg/mod/github.com/spf13/[email protected]/command.go:736
main.main()
	/home/circleci/project/main.go:10 +0x2d
@nikhilsaraf nikhilsaraf added the bug Something isn't working label Sep 23, 2021
@nikhilsaraf nikhilsaraf added this to the v1.12.0 milestone Sep 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant