bmino / binance-triangle-arbitrage

Detect in-market cryptocurrency arbitrage
MIT License
1.07k stars 337 forks source link

Ideas, questions and performance analysis #141

Closed vassil-vassilev closed 3 years ago

vassil-vassilev commented 3 years ago

Hi @bmino,

First I would like to thank you for your work! It's great that you share your knowledge and experience with us.

I tested the bot for more than a week and it managed to execute more than 30 triangular trades. Unfortunately all of them were losing money and even taking into consideration the deltas doesn't change that.

The instance I am using is based in the Tokyo region with an average latency of 40-50 ms and around 900+ cycles per second. The profit threshold is set to 0.50%. Often the expected profit is reported to be > 1%, but still the trade is executed at loss.

Here is just one example. I can send you the full log if you would like to take a look.

[3/3/2021, 7:09:49 AM] INFO : Attempting to execute BTC-WAN-BNB with an age of 33 ms and expected profit of 1.5082% [3/3/2021, 7:09:49 AM] INFO : Buying 35 WANBTC @ market price [3/3/2021, 7:09:49 AM] INFO : Successfully bought 35.00000000 WANBTC @ a quote of 0.00059500 in 24 ms [3/3/2021, 7:09:49 AM] INFO : Selling 35 WANBNB @ market price [3/3/2021, 7:09:49 AM] INFO : Successfully sold 35.00000000 WANBNB @ a quote of 0.11760000 in 16 ms [3/3/2021, 7:09:49 AM] INFO : Selling 0.11 BNBBTC @ market price [3/3/2021, 7:09:49 AM] INFO : Successfully sold 0.11000000 BNBBTC @ a quote of 0.00055356 in 12 ms [3/3/2021, 7:09:49 AM] INFO : Executed BTC-WAN-BNB position in 59 ms [3/3/2021, 7:09:49 AM] DEBUG : WANBTC Stats: [3/3/2021, 7:09:49 AM] DEBUG : Expected Conversion: 0.00059360 BTC into 35.00000000 WAN @ 0.00001696 [3/3/2021, 7:09:49 AM] DEBUG : Observed Conversion: 0.00059500 BTC into 35.00000000 WAN @ 0.00001700 [3/3/2021, 7:09:49 AM] DEBUG : Price Change: 0.23584906% [3/3/2021, 7:09:49 AM] DEBUG : [3/3/2021, 7:09:49 AM] DEBUG : WANBNB Stats: [3/3/2021, 7:09:49 AM] DEBUG : Expected Conversion: 35.00000000 WAN into 0.12005000 BNB @ 0.00343000 [3/3/2021, 7:09:49 AM] DEBUG : Observed Conversion: 35.00000000 WAN into 0.11760000 BNB @ 0.00336000 [3/3/2021, 7:09:49 AM] DEBUG : Price Change: -2.04081633% [3/3/2021, 7:09:49 AM] DEBUG : [3/3/2021, 7:09:49 AM] DEBUG : BNBBTC Stats: [3/3/2021, 7:09:49 AM] DEBUG : Expected Conversion: 0.12000000 BNB into 0.00060389 BTC @ 0.00503240 [3/3/2021, 7:09:49 AM] DEBUG : Observed Conversion: 0.11000000 BNB into 0.00055356 BTC @ 0.00503236 [3/3/2021, 7:09:49 AM] DEBUG : Price Change: -0.00072259% [3/3/2021, 7:09:49 AM] INFO : [3/3/2021, 7:09:49 AM] INFO : BTC delta: -0.00004144 (-6.9647%) [3/3/2021, 7:09:49 AM] INFO : WAN delta: 0.00000000 ( 0.0000%) [3/3/2021, 7:09:49 AM] INFO : BNB delta: 0.00760000 ( 6.9091%) [3/3/2021, 7:09:49 AM] INFO : BNB fees: -0.00025838

Do you have any suggestions or ideas for me to try? Should I try to reduce the latency even more?

On another topic - in order to monitor the performance of the bot on the go I have added an integration with Telegram. Currently most of the logging messages are replayed there. Let me know if that is something interesting for you and I can add a PR.

Thank you! Vassil

WebLeash commented 3 years ago

I'm new to this, but what about a flash loan(s)?

bmino commented 3 years ago

I don't use telegram personally but I have been contemplating adding a configurable email notifier. If you wanna put in a framework for notifications I'm all for it!

As for the latency, this has plagued me for a year+ now. Even getting depth data and completing calculations within 1ms (haha literally 1ms) the execution times of 20+ms seem to kill the opportunity. And try as I have, idk how to get closer to the exchange than being on (theoretically) the same aws cluster as Binance

bmino commented 3 years ago

@WebLeash flash loans would apply if this execution was done via a smart contract and if Binance was operating on chain. This app is interacting with the binance.com market

talmannn commented 3 years ago

Hello @bmino, appreciate your work and that's being shared.

I've got ... depth (0) too shallow to convert ... message even on 01-north-east AWS region ec2 instance and the app does not open any orders. Can't figure out what's wrong yet.

Is there any additional configuration to make it work except EXECUTION.ENABLED: true?

May you please share one of your working configs?, obviously without API keys. :)

vassil-vassilev commented 3 years ago

@bmino, have you tried different availability zones in the ap-northeast region? Any performance differences?

I will think how to make the Telegram integration more abstract and potentially build a notification framework when I have some free time.

Last question for you as the author of the bot - are you still running it? If yes, on an average (daily, weekly basis) do you manage to do any profit?

Thank you!

bmino commented 3 years ago

I switched over to decentralized finance late last year and haven't looked back. I've got a few big ideas still for this bot, one of which might drastically cut cpu usage but I need to do some graphing first to prove it

NerijusD commented 3 years ago

Hello @bmino, thank you for inspiring work.

I switched over to decentralized finance late last year and haven't looked back.

Do you perform and look for triangle-arbitrage in decentralized finance apps? Do you make profit over there?

I've got a few big ideas still for this bot, one of which might drastically cut cpu usage but I need to do some graphing first to prove it

I am wondering if compiled language would make big difference in improving cpu usage and in general latency reduction?

bmino commented 3 years ago

Do you perform and look for triangle-arbitrage in decentralized finance apps? Do you make profit over there?

You bet

I am wondering if compiled language would make big difference in improving cpu usage and in general latency reduction?

Probably! I used nodejs because well I like nodejs and there are thousands of events being processed asynchronously which node handles well

bmino commented 3 years ago

thanks!