wardbradt / peregrine

Detects arbitrage opportunities across 131 cryptocurrency exchanges in 50 countries
MIT License
1.19k stars 338 forks source link

Not the best path from bellman_ford #21

Closed wukan1986 closed 6 years ago

wukan1986 commented 6 years ago

Hi, Thank you for your work. I test the multiple_coins_one_exchange.py, modify the 'binance' to 'bitstamp'

the output is:

Starting with 100 in BTC

  1. BTC to USD at 7351.240000 = 735124.000000
  2. USD to ETH at 0.002480 = 1823.359873
  3. ETH to USD at 403.130000 = 735051.065605
  4. USD to EUR at 0.813246 = 597777.451616
  5. EUR to XRP at 2.325581 = 1390180.120037
  6. XRP to USD at 0.530590 = 737615.669891
  7. USD to EUR at 0.813246 = 599863.106186
  8. EUR to XRP at 2.325581 = 1395030.479502
  9. XRP to USD at 0.530590 = 740189.222119
  10. USD to LTC at 0.008029 = 5942.908247
  11. LTC to EUR at 101.140000 = 601065.740065
  12. EUR to USD at 1.229080 = 738757.879799
  13. USD to LTC at 0.008029 = 5931.416136
  14. LTC to EUR at 101.140000 = 599903.428044
  15. EUR to USD at 1.229080 = 737329.305341
  16. USD to ETH at 0.002480 = 1828.829787
  17. ETH to EUR at 327.240000 = 598466.259592
  18. EUR to BTC at 0.000167 = 99.979495

line 2 to 3 is bad path. line 4 to 6 is good path,but it repeat twice. line 7 to 9 same like 4 to 6 line 10 to 12, line 13 to 15 are bad duplicate paths.

Sotacan commented 6 years ago

I have encountered this as well.

wardbradt commented 6 years ago

This is noted in the docstring of line 35 of bellman_ford.py:

Note: the loop_from_source parameter, when set to True, currently outputs a less than ideal path from source to the beginning of the arbitrage opportunity.

To my knowledge, there exists no graph theory algorithm which would allow return to the source currency after exiting an arbitrage cycle with the entire trading path no more than one iteration over each complete circuit. I have been testing some algorithms to combat this problem; I am currently working on one on my remote branch which requires a complete refactoring of the code.

For the time being, to prevent this issue, do the following: When calling the bellman_ford function, as shown in multiple_coins_one_exchange.py, set the parameter loop_from_source to False. Like so:

paths = bellman_ford(graph, 'BTC', unique_paths=True, loop_from_source=False)
wardbradt commented 6 years ago

Also, @wukan1986 and @Sotacan, I apologize for the late response; I had my GitHub notification settings incorrectly configured so I did not see this issue until yesterday.

kkkttts commented 6 years ago

any update? @wukan1986 @Sotacan any ideal ?

wardbradt commented 6 years ago

@kkkttts I believe what I was trying to do may be mathematically impossible due to several edge cases. loop_from_source now defaults to False. It is recommended that you do not use it.