bmino / binance-triangle-arbitrage

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

error after a day of running the script #123

Closed daryl552007 closed 3 years ago

daryl552007 commented 3 years ago

Hi Bmino,

all was good for the first day I ran the script then on the second day I get the error below: on the binance.log and when I run it now, I am not getting new entries on the execution.log except "initializing"

[11/27/2020, 12:45:22 AM] ERROR : _readableState: { "objectMode": false, "highWaterMark": 16384, "buffer": { "head": null, "tail": null, "length": 0 }, "length": 0, "pipes": null, "pipesCount": 0, "flowing": true, "ended": true, "endEmitted": true, "reading": false, "sync": true, "needReadable": false, "emittedReadable": false, "readableListening": false, "resumeScheduled": false, "paused": false, "emitClose": true, "autoDestroy": false, "destroyed": false, "defaultEncoding": "utf8", "awaitDrain": 0, "readingMore": true, "decoder": null, "encoding": null } readable: false _events: { "end": [ null, null, null ], "close": [ null, null ] } _eventsCount: 4 socket: { "_tlsOptions": { "pipe": false, "secureContext": { "context": {}, "singleUse": true },

bmino commented 3 years ago

Not having entries in the execution log is totally normal. There shouldn't be much in there unless a trade was executed (or would have been executed if running with test mode on).

There isn't enough information to debug what happened from that error. Is there more in the log? Is this still happening? Sorry I missed this issue

daryl552007 commented 3 years ago

Hi Bmino,

no problem. I am not getting the error anymore. I am not getting any trades though. Been running this for weeks now.

checked performance.log and I see below. are these figures ok?

[12/30/2020, 12:32:12 PM] DEBUG : Cycles done per second: 2.00 [12/30/2020, 12:32:12 PM] DEBUG : Clock usage for cycles: 43.36% [12/30/2020, 12:32:12 PM] DEBUG : CPU Load: 153% [100%] [12/30/2020, 12:32:12 PM] DEBUG : API Latency: 81 ms

[12/30/2020, 2:16:16 PM] DEBUG : Cycles done per second: 2.05 [12/30/2020, 2:16:16 PM] DEBUG : Clock usage for cycles: 42.59% [12/30/2020, 2:16:16 PM] DEBUG : CPU Load: 155% [100%] [12/30/2020, 2:16:16 PM] DEBUG : API Latency: 120 ms

I am also seeing a lot of these: [12/30/2020, 12:32:12 PM] WARN : Ask depth (0) too shallow to convert 0.0015 BTC to PIVX using PIVXBTC [12/30/2020, 12:32:12 PM] WARN : Bid depth (0) too shallow to convert 129 WAN to ETH using WANETH [12/30/2020, 12:32:12 PM] WARN : Ask depth (0) too shallow to convert 0.0015 BTC to LUNA using LUNABTC

personally, are the default settings what you are using so that you get trades? if not, what do you recommend like the starting currency, min, max and profit values?

Also, if we use the parallel approach for the script, what if we want to limit our currencies on BTC, ETH, and LTC? That would mean that trades wont come often right as it has to be those exact 3 currencies that are involved in that triangle?

thank you so much!

bmino commented 3 years ago

You are correct on how parallel works!

I see your cpu is completely exhausted running this bot :( Latency is okay but I want to see that near the trade execution latency which is about 20ms in my experience.

Those error messages will happen when a sweet disconnects which is likely happening because of the lack of cpu resources to handle ping/pong frames

I tweak those settings to really jack performance up haha but have typically gotten burnt by long trade times such as 15ms+

daryl552007 commented 3 years ago

what can you suggest so that so that the cpu doesnt get exhausted?

by getting burnt by long trade times, so you mean you havent got trades lately as well?

what size ec2 instance are you using?

thanks

bmino commented 3 years ago

Haha if getting a better cpu or a vps isn't an option the SCANNING.TIMEOUT config option is there for ya xD Take a gander at the config readme, but the short story is to set this to where the logged "Clock usage for cycles" is low

I run with a spot instance of a c5n.large

daryl552007 commented 3 years ago

thanks Bmino!

Another question, I was working with trades starting with BTC. the assumption here is that my trades start from BTC and will also end with BTC, or isnt that the case?

The problem I am having is that I am running out of BTC from my wallet as the balance is spread out on other coins. what should be done to prevent this and just have my balance stay with BTC or whatever I set as the initial currency?

thanks

bmino commented 3 years ago

You are correct, the base currency is where the trades start and end. You must have enough of this asset to cover the investment max quantity.

You can lower the investment max quantity to match whatever you are currently holding of your base asset, change your base asset to something else you hold, or consolidate your holdings some

daryl552007 commented 3 years ago

Hi Bmino, I was actually starting with just BTC having balance. after some time running though, the BTC asset was lower, but it is just scattered among other currencies. But if you check the overall balance, accumulating all currencies as BTC value, it is actually higher.

any idea on why this could be happening and how we can prevent this?

thanks

bmino commented 3 years ago

If BTC was converted into something with a trade and was not converted back to BTC at the end, there would have been an error message in the logs since a trade would have failed. Are you seeing errors?

Unless you are performing trades yourself perhaps?

daryl552007 commented 3 years ago

No, I wasnt performing any trades manually. I actually turned the logs to silent lol to counterpart the cpu usage I mentioned last time. Will turn it back on just to test.

below are the latest trades performed:

image

bmino commented 3 years ago

I'm having trouble tracking the triangular pairs in this timeframe. Was there a BTC/SOL/BNB or BTC/BNB/SOL at 21:06? The sequential order doesn't look right

daryl552007 commented 3 years ago

Hi Bmino,

that is what confuses me. What I am showing you are what I am seeing as well. So, could it be that the trade process back to BTC didnt complete? If so what could be the reason?

thanks

daryl552007 commented 3 years ago

Hi Bmino,

Here is another trade that could further give us hints on what could be causing it. It still ends with ETH so I end up having funds on ETH instead of my base asset BTC

image

bmino commented 3 years ago

The order of trades still doesn't make sense. In this example you acquire 81 BQX and then only convert 64 (25 + 16 + 23)

Do you have BNB enabled to pay trading fees? What is showing in the logs?

daryl552007 commented 3 years ago

How about that 17 under where we convert 23? that would make it 64 + 17 =81 right?

for BNB yes, it is enabled. right now in the logs i have set it to errors. what should be the setting so that we can track this? I am not seeing anything in them except from the error I got when my BNB was not enough to cover the fees, so I acquired some

here is the latest, I seem to lose when there are multiple trades involved like this:

image

but all is ok when there are just 3 trades involved

image

daryl552007 commented 3 years ago

Hi Bmino,

here is what I am getting from the logs:

execution log

[1/19/2021, 10:44:58 AM] INFO : Attempting to execute BTC-ENJ-BNB with an age of 159 ms and expected profit of 0.1566% [1/19/2021, 10:44:58 AM] INFO : Buying 210 ENJBTC @ market price [1/19/2021, 10:44:58 AM] INFO : Successfully bought 210.00000000 ENJBTC @ a quote of 0.00200340 in 16 ms [1/19/2021, 10:44:58 AM] INFO : Selling 210 ENJBNB @ market price [1/19/2021, 10:44:58 AM] INFO : Successfully sold 210.00000000 ENJBNB @ a quote of 1.62015000 in 13 ms [1/19/2021, 10:44:58 AM] INFO : Selling 1.62 BNBBTC @ market price [1/19/2021, 10:44:58 AM] INFO : Successfully sold 1.62000000 BNBBTC @ a quote of 0.00199989 in 13 ms [1/19/2021, 10:44:58 AM] INFO : Executed BTC-ENJ-BNB position in 46 ms [1/19/2021, 10:44:58 AM] DEBUG : ENJBTC Stats: [1/19/2021, 10:44:58 AM] DEBUG : Expected Conversion: 0.00199080 BTC into 210.00000000 ENJ @ 0.00000948 [1/19/2021, 10:44:58 AM] DEBUG : Observed Conversion: 0.00200340 BTC into 210.00000000 ENJ @ 0.00000954 [1/19/2021, 10:44:58 AM] DEBUG : Price Change: 0.63291139% [1/19/2021, 10:44:58 AM] DEBUG : [1/19/2021, 10:44:58 AM] DEBUG : ENJBNB Stats: [1/19/2021, 10:44:58 AM] DEBUG : Expected Conversion: 210.00000000 ENJ into 1.62015000 BNB @ 0.00771500 [1/19/2021, 10:44:58 AM] DEBUG : Observed Conversion: 210.00000000 ENJ into 1.62015000 BNB @ 0.00771500 [1/19/2021, 10:44:58 AM] DEBUG : Price Change: 0.00000000% [1/19/2021, 10:44:58 AM] DEBUG : [1/19/2021, 10:44:58 AM] DEBUG : BNBBTC Stats: [1/19/2021, 10:44:58 AM] DEBUG : Expected Conversion: 1.62000000 BNB into 0.00199989 BTC @ 0.00123450 [1/19/2021, 10:44:58 AM] DEBUG : Observed Conversion: 1.62000000 BNB into 0.00199989 BTC @ 0.00123450 [1/19/2021, 10:44:58 AM] DEBUG : Price Change: 0.00000000% [1/19/2021, 10:44:58 AM] INFO : [1/19/2021, 10:44:58 AM] INFO : BTC delta: -0.00000351 (-0.1752%) [1/19/2021, 10:44:58 AM] INFO : ENJ delta: 0.00000000 ( 0.0000%) [1/19/2021, 10:44:58 AM] INFO : BNB delta: 0.00015000 ( 0.0093%) [1/19/2021, 10:44:58 AM] INFO : BNB fees: -0.00366643

performance log

[1/19/2021, 10:44:48 AM] DEBUG : Cycles done per second: 3.80 [1/19/2021, 10:44:48 AM] DEBUG : Clock usage for cycles: 4.95% [1/19/2021, 10:44:48 AM] DEBUG : CPU Load: 15% [13%] [1/19/2021, 10:44:48 AM] DEBUG : API Latency: 13 ms

and here is from another trade,

[1/19/2021, 11:26:22 AM] INFO : Attempting to execute BTC-ENJ-ETH with an age of 54 ms and expected profit of 0.4453% [1/19/2021, 11:26:22 AM] INFO : Buying 141 ENJBTC @ market price [1/19/2021, 11:26:22 AM] INFO : Successfully bought 141.00000000 ENJBTC @ a quote of 0.00149601 in 14 ms [1/19/2021, 11:26:22 AM] INFO : Selling 141 ENJETH @ market price [1/19/2021, 11:26:22 AM] INFO : Successfully sold 141.00000000 ENJETH @ a quote of 0.03965766 in 11 ms [1/19/2021, 11:26:22 AM] INFO : Selling 0.039 ETHBTC @ market price [1/19/2021, 11:26:22 AM] INFO : Successfully sold 0.03900000 ETHBTC @ a quote of 0.00146948 in 15 ms [1/19/2021, 11:26:22 AM] INFO : Executed BTC-ENJ-ETH position in 42 ms [1/19/2021, 11:26:22 AM] DEBUG : ENJBTC Stats: [1/19/2021, 11:26:22 AM] DEBUG : Expected Conversion: 0.00149601 BTC into 141.00000000 ENJ @ 0.00001061 [1/19/2021, 11:26:22 AM] DEBUG : Observed Conversion: 0.00149601 BTC into 141.00000000 ENJ @ 0.00001061 [1/19/2021, 11:26:22 AM] DEBUG : Price Change: 0.00000000% [1/19/2021, 11:26:22 AM] DEBUG : [1/19/2021, 11:26:22 AM] DEBUG : ENJETH Stats: [1/19/2021, 11:26:22 AM] DEBUG : Expected Conversion: 141.00000000 ENJ into 0.04000875 ETH @ 0.00028375 [1/19/2021, 11:26:22 AM] DEBUG : Observed Conversion: 141.00000000 ENJ into 0.03965766 ETH @ 0.00028126 [1/19/2021, 11:26:22 AM] DEBUG : Price Change: -0.87753304% [1/19/2021, 11:26:22 AM] DEBUG : [1/19/2021, 11:26:22 AM] DEBUG : ETHBTC Stats: [1/19/2021, 11:26:22 AM] DEBUG : Expected Conversion: 0.04000000 ETH into 0.00150716 BTC @ 0.03767900 [1/19/2021, 11:26:22 AM] DEBUG : Observed Conversion: 0.03900000 ETH into 0.00146948 BTC @ 0.03767897 [1/19/2021, 11:26:22 AM] DEBUG : Price Change: -0.00006805% [1/19/2021, 11:26:22 AM] INFO : [1/19/2021, 11:26:22 AM] INFO : BTC delta: -0.00002653 (-1.7734%) [1/19/2021, 11:26:22 AM] INFO : ENJ delta: 0.00000000 ( 0.0000%) [1/19/2021, 11:26:22 AM] INFO : ETH delta: 0.00065766 ( 1.6863%) [1/19/2021, 11:26:22 AM] INFO : BNB fees: -0.00272181 [1/19/2021, 11:26:22 AM] INFO : [1/19/2021, 11:26:22 AM] INFO : Cannot exceed user defined execution cap of 1 executions

on this last trade starting BTC was 0.02012568 and then after the trade I had 0.02009915, so I had some loss instead of profit

bmino commented 3 years ago

plz plz please copy the error from a terminal window like nano, vi, vim, etc. to avoid those color formatting characters appearing. It's so much easier to read through :)

Your cpu load is fine, and the latency looks comparable to the best values I have gotten.

In the logs above you are right, I overlooked that 17 which makes sense. What you are seeing is an order being fulfilled with a quantity that spans multiple depths. So you have one trade for for depth 1, then another trade at a slightly higher price at depth 2, etc. This is calculated in the bot so no worries here.

Things I notice:

daryl552007 commented 3 years ago

Hi Bmino,

i dropped the age threshold to 100ms, but still when I got a trade I am still losing image

here is the log

image

bmino commented 3 years ago

Still gotta go lower haha. The age threshold shouldn't be higher than your trade times. I put my threshold at 15ms or sometimes 10ms

daryl552007 commented 3 years ago

Thanks Bmino,

but when I lowered it to 15, even 10ms, I havent been getting any trades at all. What else should I be looking at?

bmino commented 3 years ago

You gotta wait for the market to be inefficient, which (in theory) shouldn't happen in the first place. This is why the config is there with those options. You can narrow the execution window with tighter thresholds or timings, or expand the execution window with the opposite. Currently, I'm not so sure it matters soo much since the trade execution times themselves seem to be too slow for acting on a position even identified within 1 ms.

bmino commented 3 years ago

I'm gonna close this issue since it has drifted to become a discussion board of sorts. Feel free to open a new issue with any specific questions etc. you've got