-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
39 lines (36 loc) · 1.18 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#main.py
import asyncio
import numpy as np
from Node import Node
from Edge import Edge
async def strategy(config):
print(config)
return np.random.randint(10)
async def main(settings):
#args are old tasks
tasks = []
print(settings)
global strategy
if 'observe_coins' in settings.keys():
for coin in settings['observe_coins']:
coin1 = Node(coin)
print("Observing {} ...".format(coin))
if 'trade_coins' in settings.keys():
for other_coin in settings['trade_coins']:
coin2 = Node(other_coin)
connection = Edge(coin1, coin2)
print("Trading {} ...".format(other_coin))
tasks.append(connection)
print("Starting now ..")
done, pending = await asyncio.wait([t.run(t, strategy) for t in tasks], return_when=asyncio.FIRST_EXCEPTION)
print("Done ",done)
print("Pending",pending)
if __name__ == '__main__':
#setup all tasks and run
d = {'observe_coins' : ['BRIDGE.LCC'],
'trade_coins': ['BRIDGE.BTC']}
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(main(d))
finally:
loop.close()