async def execute(): namespace = parser.parse_args() from_time = datetime(*[int(i) for i in namespace.from_time.split('-')]) to_time = datetime(*[int(i) for i in namespace.to_time.split('-')]) granularity = namespace.granularity out_file = namespace.out_file async with OandaClient(rest_timeout=120) as client: df = await get_data(client, namespace.instrument, granularity, from_time, to_time) df.to_msgpack(out_file)
async def account(): async with OandaClient() as client: return await client.post_order(order_request=order)
import asyncio from async_v20 import OandaClient client = OandaClient() # This coroutine_1 = client.create_order('AUD_USD', 10) # Is the same as this from async_v20 import InstrumentName, Unit coroutine_2 = client.create_order( InstrumentName('AUD_USD'), Unit(10) ) # Is the same as this from async_v20 import OrderRequest coroutine_3 = client.post_order( order_request=OrderRequest( instrument='AUD_USD', units=10 ) ) loop = asyncio.get_event_loop() loop.run_until_complete( asyncio.gather( coroutine_1, coroutine_2, coroutine_3
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()
async def candles(): async with OandaClient() as client: return await client.get_candles('AUD_USD', granularity='M')
async def poll_account(poll_interval=6): async with OandaClient() as client: while True: account = await client.account() print(account) await asyncio.sleep(poll_interval)
from time import time from async_v20 import OandaClient class Time(object): def __enter__(self): self.start = time() return self def __exit__(self, exc_type, exc_val, exc_tb): self.end = time() print(f'Took {self.end - self.start}') client = OandaClient(rest_host='127.0.0.1', rest_port=8080, rest_scheme='http', stream_host='127.0.0.1', stream_port=8080, stream_scheme='http', health_host='127.0.0.1', health_port=8080, health_scheme='http', rest_timeout=60, max_simultaneous_connections=1000, max_requests_per_second=99999, token='')
async def account(): async with OandaClient() as client: return await client.account_changes()
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())
async def stream(): async with OandaClient() as client: async for rsp in await client.stream_transactions(): print(rsp.dict(json=True))
async def stream(instruments): async with OandaClient() as client: async for rsp in await client.stream_pricing(instruments): print(rsp.dict(json=True))
import asyncio from async_v20 import OandaClient client = OandaClient() # This coroutine_1 = client.create_order('AUD_USD', 10) # Is the same as this from async_v20 import InstrumentName, DecimalNumber coroutine_2 = client.create_order(InstrumentName('AUD_USD'), DecimalNumber(10)) # Is the same as this from async_v20 import OrderRequest coroutine_3 = client.post_order( order_request=OrderRequest(instrument='AUD_USD', units=10, type='MARKET')) loop = asyncio.get_event_loop() loop.run_until_complete(asyncio.gather(coroutine_1, coroutine_2, coroutine_3))
import asyncio from time import time import random from async_v20 import OandaClient, LastTransactionID, OrderSpecifier, TransactionID, TradeSpecifier loop = asyncio.get_event_loop() client = OandaClient() run = lambda *x: loop.run_until_complete(asyncio.gather(*x)) print('RUNNING TEST') rsp = run( client.account(), client.list_accounts(), client.get_account_details(), client.account_summary(), client.account_instruments(), client.get_candles('AUD_USD'), # should be ok client.account_instruments(instruments='AUD_USD,EUR_USD,AUD_JPY'), # should give error client.account_instruments(instruments='AUD_USD EUR_USD'), # error client.configure_account(margin_rate=200), # ok client.configure_account(margin_rate=20), client.account_changes(), client.get_candles('AUD_USD', price='BMA',
async def get_account(): async with OandaClient() as client: return await client.account()