mirror of
https://github.com/discountry/ritmex-bot.git
synced 2026-09-11 01:08:07 +00:00
commit
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
- [Async With Threads](./examples/py/)
|
||||
|
||||
|
||||
```python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import asyncio
|
||||
import threading
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
import ccxt.async_support as ccxt # noqa: E402
|
||||
|
||||
|
||||
async def test(loop):
|
||||
exchange = ccxt.bittrex({
|
||||
'asyncio_loop': loop,
|
||||
})
|
||||
print(await exchange.fetch_ticker('ETH/BTC'))
|
||||
await exchange.close()
|
||||
|
||||
|
||||
def function_in_a_thread():
|
||||
# get_event_loop doesn't work inside a thread
|
||||
loop = asyncio.new_event_loop()
|
||||
loop.run_until_complete(test(loop))
|
||||
|
||||
|
||||
def another_threaded_function():
|
||||
global_loop.run_until_complete(test(global_loop))
|
||||
|
||||
|
||||
global_loop = asyncio.get_event_loop()
|
||||
thread = threading.Thread(target=function_in_a_thread)
|
||||
thread2 = threading.Thread(target=another_threaded_function)
|
||||
thread.start()
|
||||
thread2.start()
|
||||
thread.join()
|
||||
thread2.join()
|
||||
|
||||
```
|
||||
Reference in New Issue
Block a user