def markets(): ''' Retrieves information about supported markets. @see: http://www.questrade.com/api/documentation/rest-operations/market-calls/markets ''' return api_utils.call_api(__api_ops__['markets'])
def symbols_options(id_): ''' Retrieves an option chain for a particular underlying symbol. @see: http://www.questrade.com/api/documentation/rest-operations/market-calls/symbols-id-options ''' return api_utils.call_api(__api_ops__['options'].format(id_))
def symbol(id_): ''' Retrieves detailed information about one symbol. @see: http://www.questrade.com/api/documentation/rest-operations/market-calls/symbols-id ''' return api_utils.call_api(__api_ops__['symbol'].format(id_))
def accounts(): ''' Retrieves the accounts associated with the user on behalf of which the API client is authorized. @see: http://www.questrade.com/api/documentation/rest-operations/account-calls/accounts ''' return api_utils.call_api(__api_ops__['accounts'])
def accounts_balances(id_): ''' Retrieves per-currency and combined balances for a specified account. @see: http://www.questrade.com/api/documentation/rest-operations/account-calls/accounts-id-balances ''' return api_utils.call_api(__api_ops__['balances'].format(id_))
def accounts_positions(id_): ''' Retrieves positions in a specified account. @see: http://www.questrade.com/api/documentation/rest-operations/account-calls/accounts-id-positions ''' return api_utils.call_api(__api_ops__['positions'].format(id_))
def markets_quotes(ids): ''' Retrieves a single Level 1 market data quote for one or more symbols. @note: ids must be a list or comma separated string @see: http://www.questrade.com/api/documentation/rest-operations/market-calls/markets-quotes-id ''' syms = [] if isinstance(ids, basestring): syms = syms.split(',') else: syms = ids result = {'quotes': []} arry_chunks = __array_chunks(syms, 200) for ids_array in arry_chunks: ids_str = '' for s in ids_array: ids_str += str(s) + ',' ids_str = ids_str[:-1] # remove last , params = {'ids': ids_str} r = api_utils.call_api(__api_ops__['quotes'], params) if 'quotes' in r: result['quotes'] = result['quotes'] + r.get('quotes') return result
def markets_quote(id_): ''' Retrieves a single Level 1 market data quote for one symbol. @see: http://www.questrade.com/api/documentation/rest-operations/market-calls/markets-quotes-id ''' return api_utils.call_api(__api_ops__['quote'].format(id_))
def time(): ''' Retrieves current server time. @see: http://www.questrade.com/api/documentation/rest-operations/account-calls/time ''' return api_utils.call_api(__api_ops__['time'])
def accounts_orders(id_, start_time=None, end_time=None, state_filter=None, order_id=None): ''' Retrieves orders for specified account @see: http://www.questrade.com/api/documentation/rest-operations/account-calls/accounts-id-orders ''' if start_time == None: start_time = datetime_utils.iso_today_starttime() if end_time == None: end_time = datetime_utils.iso_today_endtime() if state_filter == None: state_filter = enums.OrderStateFilterType.All params = { 'startTime': start_time, 'endTime': end_time, 'stateFilter': state_filter } if not order_id == None: params['orderId'] = order_id return api_utils.call_api(__api_ops__['orders'].format(id_), params)
def markets_quotes_strategies(): ''' Retrieve a calculated L1 market data quote for a single or many multi-leg strategies @see: http://www.questrade.com/api/documentation/rest-operations/market-calls/markets-quotes-strategies @todo: Need to finish implementation ''' return api_utils.call_api(__api_ops__['strategies'])
def symbols_search(prefix, offset='0'): ''' Retrieves symbol(s) using several search criteria. @see: http://www.questrade.com/api/documentation/rest-operations/market-calls/symbols-search ''' params = {'prefix': prefix, 'offset': offset} return api_utils.call_api(__api_ops__['search'], params)
def markets_quotes_options(option_id_filters, ids): ''' Retrieves a single Level 1 market data quote and Greek data for one or more option symbols. @see: http://www.questrade.com/api/documentation/rest-operations/market-calls/markets-quotes-options @todo: Need to finish implementation ''' params = {'filters': option_id_filters, 'ids': ids} return api_utils.call_api(__api_ops__['moptions'], params, "POST")
def accounts_executions(id_, start_time=None, end_time=None): ''' Retrieves executions for a specific account. @see: http://www.questrade.com/api/documentation/rest-operations/account-calls/accounts-id-executions ''' if start_time == None: start_time = datetime_utils.iso_today_starttime() if end_time == None: end_time = datetime_utils.iso_today_endtime() params = {'startTime': start_time, 'endTime': end_time} return api_utils.call_api(__api_ops__['executions'].format(id_), params)
def accounts_activities(id_, start_time=None, end_time=None): ''' Retrieve account activities, including cash transactions, dividends, trades, etc. @see: http://www.questrade.com/api/documentation/rest-operations/account-calls/accounts-id-activities ''' if start_time == None: start_time = datetime_utils.iso_today_starttime() if end_time == None: end_time = datetime_utils.iso_today_endtime() params = {'startTime': start_time, 'endTime': end_time} return api_utils.call_api(__api_ops__['activities'].format(id_), params)
def list_profiles() -> Generator[int, None, None]: def item_to_profile(position: int, item: Dict) -> str: if "profile" not in item: raise TransformationError(position, item, "no 'profile' in item") profile = item["profile"] if not profile: raise TransformationError( position, item, f"malformed profile `{profile!r}`: empty") return str(profile) headers = {"AUTHORIZATION": f"Token {API_TOKEN}"} profiles = call_api(API, headers=headers, transform=item_to_profile, logger=LOGGER) yield from profiles
def accounts_place_order(id_, symbolId, quantity, askPrice): params = { "accountNumber": id_, "symbolId": symbolId, "quantity": quantity, "limitPrice": askPrice, "isAllOrNone": False, "isAnonymous": False, "orderType": "Limit", "timeInForce": "Day", "action": "Buy", "primaryRoute": "AUTO", "secondaryRoute": "AUTO" } return api_utils.call_api(__api_ops__['orders'].format(id_), params, "POST")
def symbolNames(names): ''' Retrieves detailed information about one or more symbols. @note: names must be a list or comma separated string @see: http://www.questrade.com/api/documentation/rest-operations/market-calls/symbols-id ''' syms = '' if isinstance(names, list): for s in names: syms += str(s) + ',' syms = syms[:-1] # remove last , else: syms = names params = {'names': syms} return api_utils.call_api(__api_ops__['symbols'], params)
def markets_candles(id_, start_time=None, end_time=None, interval=None): ''' Retrieves historical market data in the form of OHLC candlesticks for a specified symbol. This call is limited to returning 2,000 candlesticks in a single response. @see: http://www.questrade.com/api/documentation/rest-operations/market-calls/markets-candles-id ''' if start_time == None: start_time = datetime_utils.iso_now() if end_time == None: end_time = datetime_utils.iso_now() if interval == None: interval = enumerations.HistoricalDataGranularity.FiveMinutes params = { 'startTime': start_time, 'endTime': end_time, 'interval': interval } return api_utils.call_api(__api_ops__['candles'].format(id_), params)