Skip to content

Commit

Permalink
take into account what instruments are available on what exchanges, s…
Browse files Browse the repository at this point in the history
…upport query instruments for a given exchange
  • Loading branch information
timkpaine committed Jun 2, 2019
1 parent 322e0c0 commit f54ecd0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
11 changes: 8 additions & 3 deletions aat/query.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import List
import operator
from concurrent.futures import ThreadPoolExecutor
from functools import reduce
from typing import List
from .enums import TickType, Side, ExchangeType, CurrencyType, PairType # noqa: F401
from .exceptions import QueryException
from .structs import Instrument, MarketData, TradeRequest, TradeResponse
Expand Down Expand Up @@ -27,8 +29,11 @@ def __init__(self,
self._trade_reqs_by_instrument = {}
self._trade_resps_by_instrument = {}

def query_instruments(self) -> List[PairType]:
return self._instruments
def query_instruments(self, exchange=None) -> List[PairType]:
if exchange:
return self._instruments[exchange]
else:
return reduce(operator.concat, self._instruments.values())

def query_exchanges(self) -> List[ExchangeType]:
return self._exchanges
Expand Down
4 changes: 3 additions & 1 deletion aat/trading.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ def __init__(self, options: TradingEngineConfig, ui_handlers: list, ui_settings:
# instantiate query engine
self._qy = QueryEngine(exchanges=self._exchanges,
pairs=options.exchange_options.currency_pairs,
instruments=options.exchange_options.instruments)
instruments={name:
list(set(options.exchange_options.instruments).intersection(
ex.markets())) for name, ex in self._exchanges.items()})

# register query hooks
if self._live or self._simulation or self._sandbox:
Expand Down
10 changes: 7 additions & 3 deletions aat/ui/handlers/instruments.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import tornado.gen
from ...enums import ExchangeType
from .base import HTTPHandler
from tornado.concurrent import run_on_executor
from perspective import PerspectiveHTTPMixin
Expand All @@ -14,12 +15,15 @@ def initialize(self, trading_engine, **psp_kwargs):
self.psp_kwargs = psp_kwargs

@run_on_executor
def get_data(self, **psp_kwargs):
msgs = [x.to_dict(True, True) for x in self.te.query().query_instruments()]
def get_data(self, exchange, **psp_kwargs):
if exchange:
exchange = ExchangeType(exchange)
msgs = [x.to_dict(True, True) for x in self.te.query().query_instruments(exchange)]
super(InstrumentsHandler, self).loadData(data=msgs, **psp_kwargs)
return super(InstrumentsHandler, self).getData()

@tornado.gen.coroutine
def get(self):
dat = yield self.get_data(**self.psp_kwargs)
exchange = self.get_argument('exchange', '')
dat = yield self.get_data(exchange, **self.psp_kwargs)
self.write(dat)

0 comments on commit f54ecd0

Please sign in to comment.