ctubio / Krypto-trading-bot

Self-hosted crypto trading bot (automated high frequency market making) written in C++
https://127.0.0.1:3000
Other
3.37k stars 823 forks source link

Bitfinex Wrong account value multiple instances, single account #880

Closed CooleRnax closed 5 years ago

CooleRnax commented 5 years ago

When you run multiple instances with different pairs on single bitfinex account total account value is calculated wrongly.

Please fix this.

ctubio commented 5 years ago

i can try to fix this even if the description is the smallest ever seen (no logs, no example values)

Please understand this: what is wrong for you may be excelent for me, or for my sister (that is always against my opinion); examples never hurt

ctubio commented 5 years ago

consider to share what multiple currency paris are you using, so i can reproduce your very same issue

ctubio commented 5 years ago

:koala: and the exchange name please

ctubio commented 5 years ago

he said bitfinex!

ctubio commented 5 years ago

:koala: ok thanks for the info

ctubio commented 5 years ago

please note the calucaltion of wallet values is a very simple formula: https://github.com/ctubio/Krypto-trading-bot/blob/79f0971ea5682e45d84a838b5210362c3e9ea824/src/lib/Krypto.ninja-data.h#L1812-L1815

(it can't be wrong)

the amounts that you are missing are held in other markets.

in other words: DAI/USD wallet misses the held amounts in open orders of both sides on TRX/USD, XLM/USD and ZRX/USD TRX/USD wallet misses the held amounts in open orders of both sides on DAI/USD, XLM/USD and ZRX/USD XLM/USD wallet misses the held amounts in open orders of both sides on TRX/USD, DAI/USD and ZRX/USD ZRX/USD wallet misses the held amounts in open orders of both sides on TRX/USD, XLM/USD and DAI/USD

in other words: bitfinex website knows all your funds held and available in all your wallets each K bot only knows about the funds held and available in its own wallet/market

hope this helps''' (many thanks for the screenshots'¡)

CooleRnax commented 5 years ago

i think this approach only works if you use single bot on one account if you want to scale and use % values everything will start working not as it should

in my example you start with 1000$, 0 coins, max order value is 3% and 10 bots. bots begin sending orders 30$ each 3% as expected lets assume that all bots bought successfully. new account values for bots is 1000-(309)=730$ second wave of orders starts. bots begin sending orders 21.9$ each 3% lets assume that all bots bought successfully again. new account values for bots is 730-(229)=532$ third wave of orders starts. bots begin sending order 15.9$ each 3%

same problems will have every setting where you use % (positions, orders), except ping pong width size if everything is connected to account value, it fix these problems

ctubio commented 5 years ago

you are right but that is expected; K intentionaly doesnt read all wallets from an exchange; just the currency begin traded, because happens the same when manually trading, you cannot place 1000$ in 4 markets, you can only place 250$ on each (if our world had always an equitable distribution of resources)

ctubio commented 5 years ago

(really the reason why this is not implemented is performance)

CooleRnax commented 5 years ago

maybe you can include option to override this by my own value?

CooleRnax commented 5 years ago

something like max account value usage in usd

CooleRnax commented 5 years ago

bot will think that 100$ from 1000$ is max for account and will not buy more

CooleRnax commented 5 years ago

ideally it would be great to add max account usage in % this variable will be the value of the account and all other settings will not requre updates

ctubio commented 5 years ago

mm.. i think you mean argument --wallet-limit, see the --help: https://github.com/ctubio/Krypto-trading-bot/blob/048f945eafeef9420c86573674634211103c9efa/src/bin/trading-bot/trading-bot.h#L32-L33

you can set then a maximum limit value for each bot, that K will use as a maximum wallet (ignoring the rest of funds)

CooleRnax commented 5 years ago

this requires restart of the bot which is not very practical

CooleRnax commented 5 years ago

wallet-limit is not ideal but will make my life much easier for running multiple instances. where i can find all possible -- commands? maybe i can find a solution for some other issues there...

CooleRnax commented 5 years ago

if symbol is btcusd, wallet-limit will limit usage in usd or in btc?

CooleRnax commented 5 years ago

i have tried --wallet-limit 250 in the result account value is still bigger than 250 usd, same as was before it seeems that actual behavior haven't changed all orders and positions are still linked to account value

CooleRnax commented 5 years ago

--wallet-limit works for btc in btcusd pair I need something to set max account value in usd currency.

CooleRnax commented 5 years ago

started dedicated issue https://github.com/ctubio/Krypto-trading-bot/issues/883

ctubio commented 5 years ago

--wallet-limit uses base currency, see --help