wardbradt / peregrine

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

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

Closed cosmaz closed 5 years ago

cosmaz commented 6 years ago

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

wardbradt commented 6 years ago

I do not get this error and don't know what could have caused it. What version of Python are you running? Are your versions of ccxt and peregrine fully updated? If you have pip, try the following commands:

pip install peregrinearb -U
pip install ccxt -U

Also, to format a code block, you need to use three accents. (e.g. ```)

wardbradt commented 6 years ago

Does it work?

emersonboyd commented 6 years ago

I am having the same problem, just installed peregrinearb and ccxt both through pip for the first time, so they are both fully updated. peregrinearb version 1.1.2 and ccxt version 1.15.31

wardbradt commented 6 years ago

What version of Python are you using?

emersonboyd commented 6 years ago

3.6.5

quasiiii commented 6 years ago

I am having the same problem I am also using 3.6.5

emersonboyd commented 6 years ago

@wardbradt there is actually a first error that causes the second error.

Here is the full stack trace:

Traceback (most recent call last):
  File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peregrinearb/async_build_markets.py", line 275, in get_exchanges_for_market
    with open('./collections/collections.json') as f:
FileNotFoundError: [Errno 2] No such file or directory: './collections/collections.json'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/emersonboyd/.../run.py", line 5, in <module>
    opportunity = loop.run_until_complete(get_opportunity_for_market("BTC/USD"))
  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/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peregrinearb/async_find_opportunities.py", line 68, in get_opportunity_for_market
    finder = OpportunityFinder(ticker, exchanges=exchanges, name=name)
  File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peregrinearb/async_find_opportunities.py", line 17, in __init__
    exchanges = get_exchanges_for_market(market_name)
  File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peregrinearb/async_build_markets.py", line 281, in get_exchanges_for_market
    return build_specific_collections(symbols=[market_ticker])
  File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peregrinearb/async_build_markets.py", line 255, in build_specific_collections
    return builder.build_all_collections(write, ccxt_errors)
  File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peregrinearb/async_build_markets.py", line 46, in build_all_collections
    asyncio.get_event_loop().run_until_complete(self.async_build_all_collections(write, ccxt_errors))
  File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py", line 455, in run_until_complete
    self.run_forever()
  File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py", line 409, in run_forever
    raise RuntimeError('This event loop is already running')
RuntimeError: This event loop is already running

Process finished with exit code 1
colinrlly commented 6 years ago

+1

lhjk commented 6 years ago

getting the same error

wardbradt commented 6 years ago

I no longer have time to devote to working on this fork of the repository. I do not know what is causing this error. Sorry; someone else will have to try to solve it.

wardbradt commented 5 years ago

@cosmaz @cosmaz @emersonboyd @quasiiii @colinrlly @lhjk I have pushed some changes, hopefully fixing both of the errors @emersonboyd presented. I have also updated the library to Python 3.7. You can update it with Be sure to upgrade your installation of ccxt as the Python 3.7 version of ccxt is not backward compatible with Python 3.6.

I am not sure what is causing the original issue @cosmaz presented. @cosmaz was the file you ran the exact same as the one in the README? If you ran it inside of an asynchronous function that would be the cause of the issue. If any one gets this issue again, please re-open a new issue.

Edit: I have not updated the version in PyPi, so the only way to pull the update is:

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