def __init__(self, instrument, depth: int, output_dir: str, interval: float, fmt: str, maxfilesize: int, *, loop=None): if maxfilesize <= 1024: raise ValueError('maxsize must be greater than 1KB') self._loop = (loop if loop is not None else asyncio.get_event_loop()) self._gateway = gdax.MDGateway(loop=self._loop) self._subscriber = MDSubscriber(instrument, gateway=self._gateway) self._tasks = [] self._interval = max(interval, 0.001) self._depth = max(depth, 1) self._maxfilesize = maxfilesize if fmt == 'json': self._write_update = self._write_json elif fmt == 'msgpack': self._write_update = self._write_msgpack else: raise ValueError('Unsupported format: {}'.format(fmt)) self._output_dir = os.path.expanduser(output_dir) self._rollover_file()
def main(): app = AsyncApp(name='gdax_example') gw = gdax.MDGateway(loop=app.loop) sub = MDSubscriber(make_btc_usd(ExchangeID.GDAX), gateway=gw) app.add_run_callback(gw.launch, shutdown_cb=gw.request_shutdown) app.add_run_callback(poll_subscriber(sub)) app.run()
async def run(self, web_params, feed_params): await self.start_web_server() instrument = instruments_lookup[feed_params['instrument']] self.gw = gdax.MDGateway(loop=self.loop) sub = MDSubscriber(instrument, gateway=self.gw) await self.web_server.init(self.loop, web_params['ip'], web_params['port']) tasks = [ asyncio.ensure_future(self.launch_gw()), asyncio.ensure_future( poll_subscriber(sub, self.web_server, feed_params)) ] await asyncio.gather(*tasks, loop=self.loop)
async def run(self, params): await self.start_web_server() StrategyConfig["instrument"] = instruments_lookup[params['instrument']] # Start up the Market Data self.marketDataGw = gdax.MDGateway(loop=self.loop) sub = MDSubscriber(StrategyConfig["instrument"], gateway=self.marketDataGw) # Start up the Order Adapter if params['sandbox']: api_url = gdax.OrderEntryGateway.SANDBOX_URL else: api_url = gdax.OrderEntryGateway.API_URL self.orderEntryGw = gdax.OrderEntryGateway( api_url=api_url, api_key=params['api_key'], secret_key=params['api_secret'], passphrase=params['passphrase'], loop=self.loop) # Start up the trader self.trader = Trader(gateway=self.orderEntryGw, instrument=StrategyConfig["instrument"], limits=StrategyConfig['limits']) self.strategy = Strategy(self.trader, self.web_server.broadcast_msg) await self.web_server.init(self.loop, params['ip'], params['port'], StrategyConfig["instrument"]) tasks = [ asyncio.ensure_future(self.launch_market_data()), asyncio.ensure_future(self.launch_order_adapter()), asyncio.ensure_future(self.poll_sub(sub, self.web_server)) ] self._future_tasks = asyncio.ensure_future( asyncio.gather(*tasks, loop=self.loop)) try: await self._future_tasks except asyncio.CancelledError: self.orderEntryGw.shutdown()
async def run(self, web_params): await self.start_web_server() gw = gdax.MDGateway(loop=self.loop) sub = MDSubscriber(make_btc_usd(ExchangeID.GDAX), gateway=gw) tasks = [ asyncio.ensure_future(self.launch_gw(gw)), asyncio.ensure_future(poll_subscriber(sub, self.web_server)), asyncio.ensure_future( self.web_server.init(self.loop, web_params['ip'], web_params['port'])) ] self._future_tasks = asyncio.ensure_future( asyncio.gather(*tasks, loop=self.loop)) try: await self._future_tasks except asyncio.CancelledError: pass
async def run(self, params): await self._start_web_server() self._interval = int(params['interval']) self._instruments = [ instruments_lookup[instrument] for instrument in params['instruments'] ] self._instr_str = str(self._instrument) await self._web_server.init(self._loop, params['web']['ip'], params['web']['port']) # Start Market Data md_gateways = set() subscribers = set() for instrument in self._instruments: md_gw = gdax.MDGateway(loop=self._loop) md_gateways.add(md_gw) subscribers.add(MDSubscriber(instrument, gateway=md_gw)) await self._web_server.add_handler(str(instrument), 'weighted_mid') tasks = [] for md_gw in md_gateways: tasks.append(asyncio.ensure_future( self._launch_market_data(md_gw))) for sub in subscribers: tasks.append( asyncio.ensure_future(self._poll_sub(sub, self._web_server))) self._future_tasks = asyncio.ensure_future( asyncio.gather(*tasks, loop=self._loop)) try: await self._future_tasks except asyncio.CancelledError: pass