Git Product home page Git Product logo

peregrine's Introduction

Peregrine

A Python library which provides several algorithms to detect arbitrage opportunities across over 120 cryptocurrency exchanges in 48 countries on over 38,000 trading pairs

I created this in 2017 as a proof-of-concept to familiarize myself with cryptocurrency arbitrage. I had fun building it, but do not presently have the bandwidth to maintain the repository. There are some known issues. See the Future Development section to see current issues and ideas for improvement.

Install

  1. Ensure you have installed pip.

  2. Run the following in your command line:

    pip install git+https://github.com/wardbradt/peregrine
    

Usage

This section provides a brief overview of Peregrine's functionality. Examples demonstrating many more features are available in peregrine/examples.

Multiples Exchange/ One Currency

from peregrinearb import get_opportunity_for_market
import asyncio
collections_dir = '/Users/wardbradt/cs/peregrine/'
opportunity = asyncio.get_event_loop().run_until_complete(get_opportunity_for_market("BTC/USD", collections_dir))
print(opportunity)

At the time of writing, this prints the following in less than one second.

{'highest_bid': {'exchange': <ccxt.async.lakebtc.lakebtc object at 0x10ea50518>, 'price': 11750.59},
'lowest_ask': {'exchange': <ccxt.async.gdax.gdax object at 0x10ea50400>, 'price': 8450.01}}

If you want to specify which exchanges to find opportunities on:

from peregrinearb import get_opportunity_for_market
import asyncio

collections_dir = '/Users/wardbradt/cs/peregrine/'
opportunity = asyncio.get_event_loop().run_until_complete(get_opportunity_for_market("BTC/USD", collections_dir, exchanges=["anxpro", "bitbay", "coinfloor", "gemini", "livecoin"]))
print(opportunity)

If you want to find opportunities on the exchanges of only a certain country1, you can do it like so:

from peregrinearb import build_specific_collections, get_opportunity_for_market

us_eth_btc_exchanges = build_specific_collections(countries=['US'])
collections_dir = '/Users/wardbradt/cs/peregrine/'
opportunity = get_opportunity_for_market("ETH/BTC", collections_dir, us_eth_btc_exchanges["ETH/BTC"])
print(opportunity)

1Accepted arguments in place of 'US' in this example are 'PA', 'AU', 'CA', 'JP', 'SG', 'HK', 'NZ', 'IE', 'CN', 'KR', 'IL', 'MT', 'EU', 'VG', 'GB', 'RU', 'PL', 'SC', 'MX', 'NL', 'BR', 'PH', 'UA', 'TR', 'IS', 'TH', 'DE', 'CY', 'CL', 'TW', 'ID', 'UK', 'IN', 'VN', 'BG', 'CZ', 'ES', 'SE', 'VC', 'ZA', 'CH', 'TZ', 'FR', 'AR', 'VE', 'PK', and 'AT'.

One Exchange/ Multiple Currencies

import asyncio
from peregrinearb import load_exchange_graph, print_profit_opportunity_for_path, bellman_ford
graph = asyncio.get_event_loop().run_until_complete(load_exchange_graph('hitbtc'))

paths = bellman_ford(graph)
for path in paths:
    print_profit_opportunity_for_path(graph, path)

This prints all of the arbitrage opportunities on the given exchange (in this case, HitBTC). At the time of writing, the first opportunity printed out is:

Starting with 100 in BTC
BTC to USDT at 7955.100000 = 795510.000000
USDT to NEO at 0.016173 = 12866.084425
NEO to ETH at 0.110995 = 1428.071041
ETH to XLM at 2709.292875 = 3869062.695088
XLM to BTC at 0.000026 = 100.208724

If you would like to account for transaction fees, set fees=True when calling load_exchange_graph.

import asyncio
from peregrinearb import load_exchange_graph, print_profit_opportunity_for_path, bellman_ford

graph = asyncio.get_event_loop().run_until_complete(load_exchange_graph('gdax', fees=True))

paths = bellman_ford(graph)
for path in paths:
    print_profit_opportunity_for_path(graph, path)

To find the maximum volume that can be used to execute the opportunity, set depth=True when calling bellman_ford. To my knowledge, the only exchange which offers the functionality of simultaneously fetching the volumes of the top price levels for all markets is Binance.

import asyncio
from peregrinearb import load_exchange_graph, print_profit_opportunity_for_path, bellman_ford

graph = asyncio.get_event_loop().run_until_complete(load_exchange_graph('binance'))

paths = bellman_ford(graph, depth=True)
for path, starting_amount in paths:
    # Note that depth=True and starting_amount are set in this example
    print_profit_opportunity_for_path(graph, path, depth=True, starting_amount=starting_amount)

This would output:

Starting with 0.25 in BTC
BTC to USDT at 7955.100000 = 1988.775
USDT to NEO at 0.016173 = 32.1652110625
NEO to ETH at 0.110995 = 3.5701776025
ETH to XLM at 2709.292875 = 9,672.65673772
XLM to BTC at 0.000026 = 0.25052181

Multiple Exchanges/ Multiple Currencies

from peregrinearb import create_weighted_multi_exchange_digraph, bellman_ford_multi, print_profit_opportunity_for_path_multi


graph = create_weighted_multi_exchange_digraph(['kraken', 'bittrex', 'gemini'], log=True)
graph, paths = bellman_ford_multi(graph, 'ETH')
for path in paths:
    print_profit_opportunity_for_path_multi(graph, path)

This prints all of the arbitrage opportunities on the given exchanges. At the time of writing, the first opportunity printed out is:

Starting with 100 in ETH
ETH to ANT at 204.26088199848851 = 20426.08819984885 on bittrex for ANT/ETH
ANT to BTC at 0.00034417000000000003 = 7.03004677574198 on bittrex for ANT/BTC
BTC to MLN at 136.57526594618665 = 960.1305080110928 on bittrex for MLN/BTC
MLN to BTC at 0.0073799999999999985 = 7.085763149121863 on kraken for MLN/BTC
BTC to GNO at 98.03921568627446 = 694.6826616786137 on bittrex for GNO/BTC
GNO to BTC at 0.010300000000000002 = 7.155231415289722 on kraken for GNO/BTC
BTC to GNO at 98.03921568627446 = 701.493276008796 on bittrex for GNO/BTC
GNO to BTC at 0.010300000000000002 = 7.2253807428906 on kraken for GNO/BTC
BTC to MLN at 136.57526594618665 = 986.8082965227394 on bittrex for MLN/BTC
MLN to BTC at 0.0073799999999999985 = 7.282645228337815 on kraken for MLN/BTC
BTC to USD at 7964.809999999999 = 58004.8855411173 on gemini for BTC/USD
USD to ETH at 0.0017965900720432618 = 104.21100149317708 on kraken for ETH/USD

Should you like to account for transaction fees. In the example above, simply set fees to True when calling create_weighted_multi_exchange_digraph. For example, the following code prints out all of the opportunities found on the given exchanges while accounting for fees:

from peregrinearb import create_weighted_multi_exchange_digraph, bellman_ford_multi, print_profit_opportunity_for_path_multi


graph = create_weighted_multi_exchange_digraph(['exmo', 'binance', 'bitmex', 'bittrex', 'gemini', 'kraken'], log=True)


graph, paths = bellman_ford_multi(graph, 'ETH', unique_paths=True)
for path in paths:
    print_profit_opportunity_for_path_multi(graph, path)

The most profitable of the two printed out is:

Starting with 100 in ETH
ETH to LTC at 3.2955444239388347 = 329.55444239388345 on binance for LTC/ETH
LTC to USD at 173.00829999999996 = 57015.65383601369 on exmo for LTC/USD
USD to XRP at 1.4110342881332016 = 80451.04252294863 on kraken for XRP/USD
XRP to USD at 0.739201 = 59469.49108400615 on exmo for XRP/USD
USD to BTC at 0.00011205737337516807 = 6.663994966831705 on bitmex for BTC/USD
BTC to XRP at 12599.218848431392 = 83961.13099195795 on bittrex for XRP/BTC
XRP to USD at 0.739201 = 62064.15199038631 on exmo for XRP/USD
USD to BTC at 0.00011205737337516807 = 6.954745852799899 on bitmex for BTC/USD
BTC to XRP at 12599.218848431392 = 87624.36503464654 on bittrex for XRP/BTC
XRP to RUB at 39.120000000000005 = 3427865.160155373 on exmo for XRP/RUB
RUB to USD at 0.018667164457718873 = 63988.522683505194 on exmo for USD/RUB
USD to XRP at 1.4110342881332016 = 90289.99955341498 on kraken for XRP/USD
XRP to RUB at 39.120000000000005 = 3532144.7825295944 on exmo for XRP/RUB
RUB to USD at 0.018667164457718873 = 65935.1275439536 on exmo for USD/RUB
USD to BCH at 0.000949667616334283 = 62.61645540736334 on kraken for BCH/USD
BCH to ETH at 1.8874401 = 118.18480885571941 on bittrex for BCH/ETH

Future Development

I do not presently actively maintain this project but will respond to issues and pull requests.

Issues

See the repository's Issues tab for user-submitted issues. At the time of writing, issues I am aware of are:

  • async functionality may be broken
  • some issues with relative paths to generated json files

Enhancements

Improvements that would be appreciated:

  • Prune graph into connected components to improve runtimne
  • Split graph into cycles to find most profitable, instead of any, arbitrage opportunity
  • Update requirements and Python version

peregrine's People

Contributors

ameobea avatar chromakey-io avatar ksun0 avatar lnky79 avatar lookfirst avatar wardbradt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

peregrine's Issues

Okex seems to be broken

Hi

While trying to incldue okex in multiple exchanges, I am getting error that its unable to connect to okex.

Code:

from peregrinearb import create_weighted_multi_exchange_digraph, bellman_ford_multi, print_profit_opportunity_for_path_multi


graph = create_weighted_multi_exchange_digraph(['bitfinex', 'binance','okex','kucoin'], log=True)


graph, paths = bellman_ford_multi(graph, 'ETH', unique_paths=True)
for path in paths:
    print_profit_opportunity_for_path_multi(graph, path)

image

Adding unlisted exchanges/token pairs?

I might have overlooked this while reading the project details and I apologize if I did, but I'm having a bit of trouble figuring out the scheme of the json file containing all of the exchange/token pairs. What would be the approach to adding in an unlisted exchange/token pair?

Thank you

ValueError: exchange is not a ccxt Exchange instance.

Python 3.6.5 (default, Apr 25 2018, 14:23:58)
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

from peregrinearb import get_opportunity_for_market
import asyncio
opportunity = asyncio.get_event_loop().run_until_complete(get_opportunity_for_market("BTC/USD"))
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py", line 468, in run_until_complete
return future.result()
File "/usr/local/lib/python3.6/site-packages/peregrinearb/async_find_opportunities.py", line 62, in get_opportunity_for_market
return await finder.find_min_max()
File "/usr/local/lib/python3.6/site-packages/peregrinearb/async_find_opportunities.py", line 54, in find_min_max
[await self._test_bid_and_ask(exchange_name) for exchange_name in self.exchange_list]
File "/usr/local/lib/python3.6/site-packages/peregrinearb/async_find_opportunities.py", line 54, in
[await self._test_bid_and_ask(exchange_name) for exchange_name in self.exchange_list]
File "/usr/local/lib/python3.6/site-packages/peregrinearb/async_find_opportunities.py", line 32, in _test_bid_and_ask
raise ValueError("exchange is not a ccxt Exchange instance.")
ValueError: exchange is not a ccxt Exchange instance.

I got the above error. What can I do?

Run time error in Multiple Exchanges

Hi

When I try to run the given example, I get run time error as below.

from peregrinearb import create_weighted_multi_exchange_digraph, bellman_ford_multi, print_profit_opportunity_for_path_multi

graph = create_weighted_multi_exchange_digraph(['kraken', 'bittrex', 'gemini'], log=True)
graph, paths = bellman_ford_multi(graph, 'ETH')
for path in paths:
    print_profit_opportunity_for_path_multi(graph, path)

Error:
2019-05-11_19h27_22

As noted in another similar issue, I tried installing your networkx as below explicitly ( I already ran your pip install which should have taken this networkx as per requirements.txt)

git+git://github.com/wardbradt/networkx.git#egg=networkx

And I still get the same above error.

Win 10 OS, Anaconda 4.6.4. Python 3.7.1

Not the best path from bellman_ford

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.

Poor performance with utils.single_exchange.py._add_weighted_edge_to_graph()

async def _add_weighted_edge_to_graph(exchange: ccxt.Exchange, market_name: str, graph: nx.DiGraph, log=True, fee=0,

Hi, wardbradt. You sent multi http requests (by coroutine) refer to single symbol ( trade pair) with fetch_ticker(symbol=?) ,then fill with weighted edge. But fetch_tickers() contains all symbols` tick info at current time. Just one http request.

Maybe It will work.

No module named 'cythonperegrine.CollectionBuilder'

Run
python bench.py

Get
Traceback (most recent call last):
File "bench.py", line 6, in
from cythonperegrine import build_specific_collections as cython_build
File "/home/ytigiev/.local/share/virtualenvs/peregrine-W46Z6EVM/lib/python3.7/site-packages/peregrinearb-1.2.2-py3.7.egg/cythonperegrine/init.py", line 1, in
ModuleNotFoundError: No module named 'cythonperegrine.CollectionBuilder'

Please check configs.

Instruction

Hello,

Please, write a useful instruction on how to install and use the software. Not all users have enough experience for doing that themselves. The software is good and very interesting.

Flash Loan

Have you considered incorporating a flash loan component into the protocol so that the money that is used to arbitrage is unlimited?

<exchange> requires to release all resources with an explicit call to the .close() coroutine.

import asyncio
from peregrinearb import load_exchange_graph, print_profit_opportunity_for_path, bellman_ford

loop = asyncio.get_event_loop()
exchange = load_exchange_graph('binance', fees=True)
graph = loop.run_until_complete(exchange)
exchange.close()

paths = bellman_ford(graph, 'BTC', unique_paths=True, loop_from_source=False, ensure_profit=True)
for path in paths:
    print_profit_opportunity_for_path(graph, path)

seems to be a problem with ccxt, see this issue.

Trying

  • await exchange.close() fails b/c it's not in a coroutine
  • exchange.close() seems to do nothing.

No such file or directory issue

when I run

from peregrinearb import get_opportunity_for_market
import asyncio
opportunity = asyncio.get_event_loop().run_until_complete(get_opportunity_for_market('BTC/USD'))

I receive

Traceback (most recent call last):
File "", line 1, in
File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py", line 468, in run_until_complete
return future.result()
File "/usr/local/lib/python3.6/site-packages/peregrinearb/async_find_opportunities.py", line 61, in get_opportunity_for_market
finder = OpportunityFinder(ticker, exchanges=exchanges, name=name)
File "/usr/local/lib/python3.6/site-packages/peregrinearb/async_find_opportunities.py", line 16, in init
exchanges = get_exchanges_for_market(market_name)
File "/usr/local/lib/python3.6/site-packages/peregrinearb/utils/general.py", line 24, in get_exchanges_for_market
with open('./../peregrinearb/collections/collections.json') as f:
FileNotFoundError: [Errno 2] No such file or directory: './../peregrinearb/collections/collections.json'

What should I do?
I Installed all the modules peregrinearb required.

Module missing

Hi,

Using python 3.8.6 and Peregrine 1.8.0 (I think...) I get next error when executing the code in the example multiple_coins_multiple_exchanges.py:

ModuleNotFoundError: No module named 'networkx'

Can you please explain how can I install it or if I'm doing something wrong?

Thank you

Market not found

I found a issue that market HONEY/ETC not found on coinexchange

Starting with 100 in BTC
BTC to HONEY at 37764.350453 = 3776435.045317
HONEY to ETC at 0.014000 = 52870.128399
ETC to ZEIT at 112359.550562 = 5940463865.032758
ZEIT to ETC at 0.000006 = 38613.015123
ETC to COUPE at 263157.894737 = 10161319769.134989
COUPE to ETC at 0.000003 = 32617.836459
ETC to BTC at 0.002070 = 67.522836
BTC to LVPS at 9090909.090909 = 613843960.094057
LVPS to ETC at 0.000200 = 122768.792019
ETC to ERAPS at 17857.142857 = 2192299857.478777
ERAPS to BTC at 0.000000 = 306.921980

raise RuntimeError('This event loop is already running')

Try to exec:
`import asyncio
from peregrinearb import load_exchange_graph, print_profit_opportunity_for_path, bellman_ford

loop = asyncio.get_event_loop()
graph = loop.run_until_complete(load_exchange_graph('binance', fees=True))

paths = bellman_ford(graph, 'BTC', unique_paths=True)
for path in paths:
print_profit_opportunity_for_path(graph, path)
`

File "C:\Python36\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile
execfile(filename, namespace)

File "C:\Python36\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)

File "C:/Users/cosmaz/.spyder-py3/temp.py", line 12, in
graph = loop.run_until_complete(load_exchange_graph('binance', fees=True))

File "C:\Python36\lib\asyncio\base_events.py", line 455, in run_until_complete
self.run_forever()

File "C:\Python36\lib\asyncio\base_events.py", line 409, in run_forever
raise RuntimeError('This event loop is already running')

RuntimeError: This event loop is already running

Loss route suggested

Hi

Often I also observe, the route ends up in loss as below. How to avoid that?

Code:

import asyncio
from peregrinearb import load_exchange_graph, print_profit_opportunity_for_path, bellman_ford

loop = asyncio.get_event_loop()
graph = loop.run_until_complete(load_exchange_graph('bitfinex', fees=True))
paths = bellman_ford(graph, 'BTC', unique_paths=True)
for path in paths:
    print_profit_opportunity_for_path(graph, path)

Output:
image

"This event loop is already running"

Hello!

I am trying to run example "multiple_coins_multiple_exchanges", but constantly encounter an error. It seems to be a problem in Asyncio, but I still can't figure out what the problem is.

Also already saw this issue, but I suppose this problem still existing.
https://github.com/wardbradt/peregrine/issues/36

python 3.7.3
asyncio 3.4.3
ccxt 1.18.594
peregrinearb 1.2.2

Code:

from peregrinearb import create_weighted_multi_exchange_digraph, bellman_ford_multi, \
    print_profit_opportunity_for_path_multi


graph = create_weighted_multi_exchange_digraph(['bittrex', 'gemini', 'kraken'], log=True)

graph, paths = bellman_ford_multi(graph, 'ETH', loop_from_source=False, unique_paths=True)
for path in paths:
    print_profit_opportunity_for_path_multi(graph, path)

Output:
image

limit to a triangle

Hello,
multiple_coins_one_exchange.py is working fine on my config, not the other examples.
In multiple_coins_one_exchange.py, I would like to limit the arb path to a triangle (3 transactions). I am new to graph theory and a small help would be great. I guess it would be somewhere in NegativeWeightFinder::bellman_ford but then I'm getting lost.
Thank you

Settings base coin?

Hello,
How do I set the target coin/currency that I want to be arbitrage trading on? For example if I set BTC as the base coin it should convert from BTC to something and then back to BTC. Just as I would if I set it as $.

test_bellmannx.py failing

Traceback (most recent call last): File "test_bellmannx.py", line 10, in <module> from ..utils import wss_add_market, wss_update_graph ImportError: attempted relative import with no known parent package

Much of the project seems to be not working, on my part. It was fine a year ago.

Ubuntu 18, Python 3.7.5

ValueError: math domain error

Hi,
when do
`from peregrinearb import create_weighted_multi_exchange_digraph, bellman_ford_multi, print_profit_opportunity_for_path_multi

graph = create_weighted_multi_exchange_digraph(['hitbtc','exmo','bitfinex','poloniex','kraken', 'bittrex', 'binance'], log=True)
graph, paths = bellman_ford_multi(graph, 'BTC', unique_paths=True)
for path in paths:
print_profit_opportunity_for_path_multi(graph, path)`

its appear 6 times
Task exception was never retrieved future: <Task finished coro=<_add_market_to_multi_digraph() done, defined at /h/z/Documents/Arbitrage program/peregrine/peregrinearb/utils/multi_exchange.py:98> exception=ValueError('math domain error')> Traceback (most recent call last): File "/home/tech/Documents/Arbitrage program/peregrine/peregrinearb/utils/multi_exchange.py", line 135, in _add_market_to_multi_digraph weight=-math.log(fee_scalar*ticker_bid)) ValueError: math domain error
and finish with this:
Starting with 100 in BTC BTC to MEME at 3990000.000000001 = 399000000.0000001 on bittrex for MEME/BTC MEME to USDT at 195.37864091391904 = 77956077724.65372 on poloniex for MEME/USDT USDT to STX at 127.95389048991358 = 9974783432203.533 on hitbtc for STX/USDT STX to BNB at 0.008031959999999998 = 80117061536.12148 on binance for STX/BNB BNB to COCOS at 100909.09090909087 = 8084539845917709.0 on binance for COCOS/BNB COCOS to BTC at 1.6413570000000026e-08 = 132696160.67875974 on hitbtc for COCOS/BTC
Could you tell me why throw error with math domain error ?
Thanks

Error on installation

Got an error when tried to install peregrine use the following command:

pip install git+https://github.com/wardbradt/peregrine.git

_Collecting git+https://github.com/wardbradt/peregrine.git
Cloning https://github.com/wardbradt/peregrine.git to c:\users\eduardo\appdata\local\temp\pip-riqw15ab-build
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "c:\users\eduardo\anaconda3update\lib\tokenize.py", line 452, in open
buffer = _builtin_open(filename, 'rb')
FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\Eduardo\AppData\Local\Temp\pip-riqw15ab-build\setup.py'

----------------------------------------

Command "python setup.py egg_info" failed with error code 1 in C:\Users\Eduardo\AppData\Local\Temp\pip-riqw15ab-build_

average price v.s. best price

The algorithm is using the best bid and best ask as input to the graph. However, for most coins, their price is much lower than BTC/ETH, thus the actual filled price will differ from the best bid/ask.

Any plan to support average price rather than best price?

import asyncio errors

When I want to import asyncio I get next error message:

"import-im6.q16: not authorized `asyncio' @ error/constitute.c/WriteImage/1037"

The solution in #16 doesn't help or I don't know how it would help me.

Any suggestion please?

Thanks!

Duplicate outputs for multi exchange

Hi

For below combination of exchanges, I am getting CBT/ETH pair, same message printed over multiple times (screen shot below shows only part of it due to space)

Code:

from peregrinearb import create_weighted_multi_exchange_digraph, bellman_ford_multi, print_profit_opportunity_for_path_multi


graph = create_weighted_multi_exchange_digraph(['bitfinex', 'huobiru', 'okex'], log=True, fees=True)
graph, paths = bellman_ford_multi(graph, 'ETH')
for path in paths:
    print_profit_opportunity_for_path_multi(graph, path)

Output:
image

Enhance peregrine-flask

The website currently displays PNGs generated using Networkx/ Pydot's write_png functionality. It would be much better if we could draw the JSON into the page using HTML/ JS. Here is a link explaining how to turn graphs into JSON. (If you do not understand this, that's fine. I could make the back-end JSON "outputter" very easily. If it is helpful, D3.js has some pretty good tools for drawing graphs.

ImportError: No module named pyximport

Hi, I am running into the following;

~/peregrine $ python ./examples/bench.py
Traceback (most recent call last):
  File "./examples/bench.py", line 2, in <module>
    import pyximport
ImportError: No module named pyximport

pyximport is not listed in the requirements. I tried pip install pyximport but that did not locate such a package. Any ideas?

Syntax error in running the first example

File "/home/a/PycharmProjects/untitled4/xdfg.py", line 1, in
from peregrinearb import get_opportunity_for_market
File "/usr/local/lib/python3.5/dist-packages/peregrinearb/init.py", line 1, in
from .async_find_opportunities import OpportunityFinder, get_opportunity_for_market
File "/usr/local/lib/python3.5/dist-packages/peregrinearb/async_find_opportunities.py", line 54
[await self._test_bid_and_ask(exchange_name) for exchange_name in self.exchange_list]
^
SyntaxError: 'await' expressions in comprehensions are not supported

TypeError: unsupported operand type(s) for *: 'int' and 'NoneType'

from peregrinearb import create_weighted_multi_exchange_digraph, bellman_ford_multi, print_profit_opportunity_for_path_multi

graph = create_weighted_multi_exchange_digraph(['exmo', 'binance', 'bitmex', 'bittrex', 'gemini', 'kraken'], log=True)

graph, paths = bellman_ford_multi(graph, 'ETH', unique_paths=True)
for path in paths:
print_profit_opportunity_for_path_multi(graph, path)

=============================================================
D:\python mutiexchangecurrency.py

Task exception was never retrieved
future: <Task finished coro=<_add_market_to_multi_digraph() done, defined at C:\Python36\lib\site-packages\peregrinearb\utils\multi_exchange.py:93> exception=TypeError("unsupported operand type(s) for *: 'int' and 'NoneType'",)>
Traceback (most recent call last):
File "C:\Python36\lib\site-packages\peregrinearb\utils\multi_exchange.py", line 130, in _add_market_to_multi_digraph
weight=-math.log(fee_scalar * ticker_bid))
TypeError: unsupported operand type(s) for *: 'int' and 'NoneType'
Task exception was never retrieved
future: <Task finished coro=<_add_market_to_multi_digraph() done, defined at C:\Python36\lib\site-packages\peregrinearb\utils\multi_exchange.py:93> exception=TypeError("unsupported operand type(s) for *: 'int' and 'NoneType'",)>
Traceback (most recent call last):
File "C:\Python36\lib\site-packages\peregrinearb\utils\multi_exchange.py", line 130, in _add_market_to_multi_digraph
weight=-math.log(fee_scalar * ticker_bid))
TypeError: unsupported operand type(s) for *: 'int' and 'NoneType'

Setting starting currency no longer works.

Been a while since I played with this project. One issue I'm running into, which wasn't a problem before, is that setting the starting currency for one exchange, multiple coins seems to no longer work properly.

Whether its

paths = bellman_ford(graph, 'BTC', unique_paths=True)
or
paths = bellman_ford(graph, 'ETH', unique_paths=True)

or any currency I put, it seems that the starting currency is different everytime depending on the current opportunities.

Ignored Precision limitations could create deceptive gains

Hi

Exchanges have precision limitations which are not taken care in the calculation, but might affect the output. Can you please include them? As that could mean, significant loss in certain coins.

image

Here is the precision limits link for coins in bitfinex exchange. They use only 5 significant digits.

If its difficult to include for all exchanges, at least you could provide an option to let us specify some where.

Error

  File "C:\Users\Admin\Desktop\bittrex-getmarketsalert-master\test.py", line 6, in <module>
    for path in paths:
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\peregrinearb\bellman_multi_graph.py", line 16, in bellman_ford
    self._first_iteration()
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\peregrinearb\bellman_multi_graph.py", line 43, in _first_iteration
    [self._process_edge_bunch(edge_bunch) for edge_bunch in self.graph.edge_bunches(data=True)]
AttributeError: 'MultiDiGraph' object has no attribute 'edge_bunches'

I get the error above when running the following code. why is that?

from peregrinearb import create_weighted_multi_exchange_digraph, bellman_ford_multi, print_profit_opportunity_for_path_multi


graph = create_weighted_multi_exchange_digraph(['bittrex', 'binance', 'huobi', 'kucoin'], log=True)
graph, paths = bellman_ford_multi(graph, 'BTC')
for path in paths:
    print_profit_opportunity_for_path_multi(graph, path)

Multiple exchanges arbitrage seems impossible?

How can a trader make a profit across multiple exchanges?
He should withdraw a coin from an exchange and deposit in another exchange. If there are more than 2 exchanges, this would drastically increase the whole time.

Even if we have assets in all the exchanges already, we would notice that when we sold out all the base coin in one exchange, we will never have the chance to buy them back.

So, it is possible to make a profit across multiple exchanges?

Order_book

future: <Task finished coro=<_add_weighted_edge_to_graph() done, defined at /Users/shivamgoyal/bitcoin_arb/preregine/peregrine/peregrinearb/utils/single_exchange.py:95> exception=UnboundLocalError("local variable 'order_book' referenced before assignment",)>
Traceback (most recent call last):
  File "/Users/shivamgoyal/bitcoin_arb/preregine/peregrine/peregrinearb/utils/single_exchange.py", line 115, in _add_weighted_edge_to_graph
    ticker_bid = order_book['bids'][0][0]
UnboundLocalError: local variable 'order_book' referenced before assignment
Task exception was never retrieved
future: <Task finished coro=<_add_weighted_edge_to_graph() done, defined at /Users/shivamgoyal/bitcoin_arb/preregine/peregrine/peregrinearb/utils/single_exchange.py:95> exception=UnboundLocalError("local variable 'order_book' referenced before assignment",)>
Traceback (most recent call last):
  File "/Users/shivamgoyal/bitcoin_arb/preregine/peregrine/peregrinearb/utils/single_exchange.py", line 115, in _add_weighted_edge_to_graph
    ticker_bid = order_book['bids'][0][0]
UnboundLocalError: local variable 'order_book' referenced before assignment
Task exception was never retrieved
future: <Task finished coro=<_add_weighted_edge_to_graph() done, defined at /Users/shivamgoyal/bitcoin_arb/preregine/peregrine/peregrinearb/utils/single_exchange.py:95> exception=UnboundLocalError("local variable 'order_book' referenced before assignment",)>```


The program I'm running is: 
```import asyncio
from peregrinearb import load_exchange_graph, print_profit_opportunity_for_path, bellman_ford


loop = asyncio.get_event_loop()
graph = loop.run_until_complete(load_exchange_graph('binance'))

paths = bellman_ford(graph, 'BTC', unique_paths=True)
for path in paths:
    print_profit_opportunity_for_path(graph, path)```




AttributeError: module 'ccxt.async_support' has no attribute '/'

Hello,

Thank you for this very useful application.
But i have some issues when running,
here is my stack trace:

"C:\Users\NV Master\AppData\Local\Programs\Python\Python36\python.exe" "C:/Users/NV Master/Documents/arbitrage/peregrine-master/peregrine-master/examples/example.py"
Traceback (most recent call last):
  File "C:/Users/NV Master/Documents/arbitrage/peregrine-master/peregrine-master/examples/example.py", line 5, in <module>
    opportunity = asyncio.get_event_loop().run_until_complete(get_opportunity_for_market("BTC/USD", collections_dir))
  File "C:\Users\NV Master\AppData\Local\Programs\Python\Python36\lib\asyncio\base_events.py", line 466, in run_until_complete
    return future.result()
  File "C:\Users\NV Master\Documents\arbitrage\peregrine-master\peregrine-master\peregrinearb\async_find_opportunities.py", line 324, in get_opportunity_for_market
    finder = OpportunityFinder(ticker, exchanges=exchanges, name=name)
  File "C:\Users\NV Master\Documents\arbitrage\peregrine-master\peregrine-master\peregrinearb\async_find_opportunities.py", line 52, in __init__
    exchanges = [getattr(ccxt, exchange_id)() for exchange_id in exchanges]
  File "C:\Users\NV Master\Documents\arbitrage\peregrine-master\peregrine-master\peregrinearb\async_find_opportunities.py", line 52, in <listcomp>
    exchanges = [getattr(ccxt, exchange_id)() for exchange_id in exchanges]
AttributeError: module 'ccxt.async_support' has no attribute '/'

for this example:

from peregrinearb import get_opportunity_for_market
import asyncio

collections_dir = '/Users/wardbradt/cs/peregrine/'
opportunity = asyncio.get_event_loop().run_until_complete(get_opportunity_for_market("BTC/USD", collections_dir))
print(opportunity)

what refer to collections_dir ?
Otherwise other examples in the project are working fine.

thanks for your help.

Fails to install under pypy3

When installing it gives EOFError

running install
running bdist_egg
running egg_info
writing peregrinearb.egg-info/PKG-INFO
writing dependency_links to peregrinearb.egg-info/dependency_links.txt
writing top-level names to peregrinearb.egg-info/top_level.txt
Traceback (most recent call last):
  File "setup.py", line 12, in <module>
    url='https://github.com/wardbradt/peregrinearb',
  File "/home/soogy/Downloads/pypy-opt/site-packages/setuptools/__init__.py", line 143, in setup
    return distutils.core.setup(**attrs)
  File "/home/soogy/Downloads/pypy-opt/lib-python/3/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/home/soogy/Downloads/pypy-opt/lib-python/3/distutils/dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "/home/soogy/Downloads/pypy-opt/lib-python/3/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/home/soogy/Downloads/pypy-opt/site-packages/setuptools/command/install.py", line 67, in run
    self.do_egg_install()
  File "/home/soogy/Downloads/pypy-opt/site-packages/setuptools/command/install.py", line 109, in do_egg_install
    self.run_command('bdist_egg')
  File "/home/soogy/Downloads/pypy-opt/lib-python/3/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/home/soogy/Downloads/pypy-opt/lib-python/3/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/home/soogy/Downloads/pypy-opt/site-packages/setuptools/command/bdist_egg.py", line 163, in run
    self.run_command("egg_info")
  File "/home/soogy/Downloads/pypy-opt/lib-python/3/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/home/soogy/Downloads/pypy-opt/lib-python/3/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/home/soogy/Downloads/pypy-opt/site-packages/setuptools/command/egg_info.py", line 296, in run
    self.find_sources()
  File "/home/soogy/Downloads/pypy-opt/site-packages/setuptools/command/egg_info.py", line 303, in find_sources
    mm.run()
  File "/home/soogy/Downloads/pypy-opt/site-packages/setuptools/command/egg_info.py", line 534, in run
    self.add_defaults()
  File "/home/soogy/Downloads/pypy-opt/site-packages/setuptools/command/egg_info.py", line 570, in add_defaults
    sdist.add_defaults(self)
  File "/home/soogy/Downloads/pypy-opt/site-packages/setuptools/command/py36compat.py", line 34, in add_defaults
    self._add_defaults_python()
  File "/home/soogy/Downloads/pypy-opt/site-packages/setuptools/command/sdist.py", line 127, in _add_defaults_python
    build_py = self.get_finalized_command('build_py')
  File "/home/soogy/Downloads/pypy-opt/lib-python/3/distutils/cmd.py", line 298, in get_finalized_command
    cmd_obj = self.distribution.get_command_obj(command, create)
  File "/home/soogy/Downloads/pypy-opt/lib-python/3/distutils/dist.py", line 846, in get_command_obj
    klass = self.get_command_class(command)
  File "/home/soogy/Downloads/pypy-opt/site-packages/setuptools/dist.py", line 707, in get_command_class
    self.cmdclass[command] = cmdclass = ep.load()
  File "/home/soogy/Downloads/pypy-opt/site-packages/pkg_resources/__init__.py", line 2346, in load
    return self.resolve()
  File "/home/soogy/Downloads/pypy-opt/site-packages/pkg_resources/__init__.py", line 2352, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/home/soogy/Downloads/pypy-opt/site-packages/setuptools/command/build_py.py", line 15, in <module>
    from setuptools.lib2to3_ex import Mixin2to3
  File "/home/soogy/Downloads/pypy-opt/site-packages/setuptools/lib2to3_ex.py", line 12, in <module>
    from lib2to3.refactor import RefactoringTool, get_fixers_from_package
  File "/home/soogy/Downloads/pypy-opt/lib-python/3/lib2to3/refactor.py", line 27, in <module>
    from .fixer_util import find_root
  File "/home/soogy/Downloads/pypy-opt/lib-python/3/lib2to3/fixer_util.py", line 9, in <module>
    from .pygram import python_symbols as syms
  File "/home/soogy/Downloads/pypy-opt/lib-python/3/lib2to3/pygram.py", line 32, in <module>
    python_grammar = driver.load_grammar(_GRAMMAR_FILE)
  File "/home/soogy/Downloads/pypy-opt/lib-python/3/lib2to3/pgen2/driver.py", line 133, in load_grammar
    g.load(gp)
  File "/home/soogy/Downloads/pypy-opt/lib-python/3/lib2to3/pgen2/grammar.py", line 108, in load
    d = pickle.load(f)
  File "/home/soogy/Downloads/pypy-opt/lib-python/3/pickle.py", line 1580, in _load
    encoding=encoding, errors=errors).load()
  File "/home/soogy/Downloads/pypy-opt/lib-python/3/pickle.py", line 1061, in load
    raise EOFError
EOFError

AttributeError: 'MultiDiGraph' object has no attribute 'edge_bunches'

Hello,

I'm trying to run Multiple Exchanges/ Multiple Currencies example from the README and get the following error:

$ python3 script.py 
Traceback (most recent call last):
  File "peregrine.py", line 6, in <module>
    for path in paths:
  File "/home/username/.local/lib/python3.7/site-packages/peregrinearb/bellman_multi_graph.py", line 20, in bellman_ford
    self._first_iteration()
  File "/home/username/.local/lib/python3.7/site-packages/peregrinearb/bellman_multi_graph.py", line 43, in _first_iteration
    [self._process_edge_bunch(edge_bunch) for edge_bunch in self.graph.edge_bunches(data=True)]
AttributeError: 'MultiDiGraph' object has no attribute 'edge_bunches'

I'm using dev branch.

Having issues installing

Hi, I'm running the example code and getting this error:

Traceback (most recent call last):
  File "multiple_coins_multiple_exchanges.py", line 1, in <module>
    from peregrinearb import create_weighted_multi_exchange_digraph, bellman_ford_multi, \
  File "/Library/Python/2.7/site-packages/peregrinearb/__init__.py", line 1, in <module>
    from .async_find_opportunities import *
  File "/Library/Python/2.7/site-packages/peregrinearb/async_find_opportunities.py", line 31
    async def _test_bid_and_ask(self, exchange):
            ^
SyntaxError: invalid syntax```

utils.logging_utils

Hi and thanks for the cool software!

I am getting this:

ModuleNotFoundError: No module named 'utils.logging_utils'

When I do this:

pip install utils.logging_utils

I get this:

No matching distribution found for utils.logging_utils

Would you have any suggestion for this? Thank you! :D

$ python
Python 3.6.8 (default, Apr 9 2019, 04:59:38)
[GCC 8.3.0] on linux

Error in asyncio

Hi! Thank you for creating this. I am trying the following;

~/peregrine $ python ./examples/multiple_coins_one_exchange.py
Traceback (most recent call last):
  File "./examples/multiple_coins_one_exchange.py", line 1, in <module>
    import asyncio
  File "/usr/local/lib/python2.7/dist-packages/asyncio/__init__.py", line 9, in <module>
    from . import selectors
  File "/usr/local/lib/python2.7/dist-packages/asyncio/selectors.py", line 39
    "{!r}".format(fileobj)) from None
                               ^
SyntaxError: invalid syntax

Any idea what may be going wrong here? The asyncio lib was installed with pip install.

Multiple coins one exchange

I run example multiple_coins_one_exchange on coinexchange exchange and got this output bellow:

Starting with 100 in BTC
BTC to ETC at 467.285352 = 46728.535247
ETC to RVR at 250.002500 = 11682250.634340
RVR to ETC at 0.002000 = 23364.501269
ETC to HONEY at 47.619070 = 1112595.828316
HONEY to ETC at 0.014000 = 15576.352722
ETC to ZEIT at 151285.930408 = 2356483013.976343
ZEIT to ETC at 0.000006 = 14138.898084
ETC to ETH at 0.024150 = 341.454389
ETH to LVPS at 751879.699248 = 256732623.101633
LVPS to ETC at 0.000200 = 51346.524620
ETC to BTC at 0.002120 = 108.855146
BTC to LVPS at 9090909.090909 = 989592233.275805
LVPS to ETC at 0.000200 = 197918.446655
ETC to BTC at 0.002120 = 419.589086

Can you expand what are 467.285352, 250.002500, etc. I don't think they are market's price.

Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.