import asyncio from async_v20 import OandaClient client = OandaClient() loop = asyncio.get_event_loop() response = loop.run_until_complete(client.initialize()) # Write your code here loop.run_until_complete(client.close())
import asyncio from async_v20 import OandaClient client = OandaClient() async def poll_account(poll_interval=6, client=client): while True: account = await client.account() print(account) await asyncio.sleep(poll_interval) async def stream(instruments, client=client): async for price in await client.stream_pricing(instruments): print(price) loop = asyncio.get_event_loop() loop.run_until_complete(asyncio.gather(poll_account(), stream('EUR_USD'))) client.close()
account = run(client.account())[0] positions = { r.orderCreateTransaction.instrument: 0 for r in rsp if hasattr(r, 'orderFillTransaction') } for response in rsp: fill = getattr(response, 'orderFillTransaction', None) if fill is not None: positions[fill.instrument] += fill.units print(positions) print(account.positions._instrument_index) print(account.positions._items) for instrument, units in positions.items(): assert account.positions.get_instrument(instrument).long.units == units rsp = run(client.list_open_trades())[0] assert len(rsp.trades) == len(account.trades) print(run(client.close_all_trades())) account = run(client.account())[0] assert len( account.trades) == 0, f'Account still has trades open {account.trades}' run(client.close()) print('TEST SUCCESSFUL!')