stellar-deprecated / kelp

Kelp is a free and open-source trading bot for the Stellar DEX and 100+ centralized exchanges
https://kelpbot.io
Other
1.1k stars 260 forks source link

Volume and price precision code not active for centralized exchanges #141

Closed Reidmcc closed 5 years ago

Reidmcc commented 5 years ago

Describe the bug

Kelp's ccxt exchange implementation has a struct and related function, model.MakeOrderConstraints to specify order constraints, but only minimum volume is available in the configuration files. The other two parameters, price and volume precision, aren't implemented. Without these Kelp can only trade centralized exchange pairs that accept seven digits of precision unless volumes and prices are manually set to round amounts, which you can do for the buy/sell strategy, but cannot do for balanced. So if you're trying to use the balanced strategy for a pair that requires lower precision, Kelp fails to submit valid API requests. It works in the ccxt test files because it's hard-coded there.

Expected behavior

Kelp should be able to handle specified precision for price and volume.

Frequency

Always when relevant conditions exist.

Steps To Reproduce

  1. Set Kelp to use the balanced strategy on a centralized exchange pair that requires lower than 7-digit precision, such as XLM/USD on Coinbase Pro.
  2. Try to submit orders.

Possible Solution

We can fix this by implementing the precision functions already present in the Kelp codebase.

I tried it, but its not straightforward. The big problem is that sellSideStrategy.go handles buying and selling precision in the same way, which leads to incorrect behavior if you try to give it lower volume precision values, i.e. on XLM/USD it will apply the 0 precision to the USD amounts before converting them back to XLM amounts, which can lead to rounding to 0 if you're trading small XLM amounts (which is common with balanced). If it doesn't round to 0 it tries to submit a amount based on a precision 0 USD volume, which fails because it is not a round XLM volume when divided by price in sdex.CreateBuyOffer. Precision values are also not checked in orderConstraintsFilter.go, and sdex.go is hard-coded to precision 7. This is looks like a non-trivial overhaul, and I'm not sure where the constraints should be passed in.

Your Environment

version: master:v1.6.0 git branch: master git hash: 761e114ee60ead6fb08482227b21fa8e8d39b696 build date: 20190331T174723Z GOOS: linux GOARCH: amd64

Context

I am unable to trade with the balanced strategy on the Coinbase Pro XLM/USD pair, or with other pairs that require lower precision.

Reidmcc commented 5 years ago

log_XLM_USD_20190401T074343CDT.log

Reidmcc commented 5 years ago

Here's one for balanced. It has the actual cb pro error text too -log_XLM_USD_20190330T124604CDT.log

nikhilsaraf commented 5 years ago

fyi @Reidmcc, feel free to reopen this issue if it doesn't work with the balanced strategy, I've not tested on coinbasepro with the balanced strategy