def cancel_collections(codes, queues=None): """ Cancel running or pending historical data collections. Parameters ---------- codes : list of str, required the database code(s) to cancel collections for queues : list of str, optional only cancel collections in these queues. Possible choices: standard, priority Returns ------- dict standard and priority queues """ params = {} if codes: params["codes"] = codes if queues: params["queues"] = queues response = houston.delete("/history/queue", params=params) houston.raise_for_status_with_json(response) return response.json()
def delete_universe(code, domain=None): """ Delete a universe. The listings details of the member securities won't be deleted, only their grouping as a universe. Parameters ---------- code : str, required the universe code domain : str, optional the domain from which to delete the universe (default is 'main', which runs against quantrocket.master.main.sqlite. Possible choices: main, sharadar) Returns ------- dict status message """ url = "/master/{0}universes/{1}".format( "{0}/".format(domain) if domain else "", code) response = houston.delete(url) houston.raise_for_status_with_json(response) return response.json()
def cancel_orders(order_ids=None, conids=None, order_refs=None, accounts=None, cancel_all=None): """ Cancel one or more orders by order ID, conid, or order ref. Parameters ---------- order_ids : list of str, optional cancel these order IDs conids : list of int, optional cancel orders for these conids order_refs: list of str, optional cancel orders for these order refs accounts : list of str, optional cancel orders for these accounts cancel_all : bool cancel all open orders Returns ------- dict status message Examples -------- Cancel orders by order ID: >>> cancel_orders(order_ids=['6002:45','6002:46']) Cancel orders by conid: >>> cancel_orders(conids=[123456]) Cancel orders by order ref: >>> cancel_orders(order_refs=['my-strategy']) Cancel all open orders: >>> cancel_orders(cancel_all=True) """ params = {} if order_ids: params["order_ids"] = order_ids if conids: params["conids"] = conids if order_refs: params["order_refs"] = order_refs if accounts: params["accounts"] = accounts if cancel_all: params["cancel_all"] = cancel_all response = houston.delete("/blotter/orders", params=params) houston.raise_for_status_with_json(response) return response.json()
def drop_db(code, confirm_by_typing_db_code_again=None): """ Delete a history database. Parameters ---------- code : str, required the database code confirm_by_typing_db_code_again : str, required enter the db code again to confirm you want to drop the database, its config, and all its data Returns ------- dict status message """ params = { "confirm_by_typing_db_code_again": confirm_by_typing_db_code_again } response = houston.delete("/history/databases/{0}".format(code), params=params) houston.raise_for_status_with_json(response) return response.json()
def clean_bundles(bundles, before=None, after=None, keep_last=None, clean_all=False): """ Remove previously ingested data for one or more bundles. Parameters ---------- bundles : list of str, required the data bundles to clean before : str (YYYY-MM-DD[ HH:MM:SS]), optional clear all data before this timestamp. Mutually exclusive with keep_last and clean_all. after : str (YYYY-MM-DD[ HH:MM:SS]), optional clear all data after this timestamp. Mutually exclusive with keep_last and clean_all. keep_last : int, optional clear all but the last N ingestions. Mutually exclusive with before, after, and clean_all. clean_all : bool clear all ingestions for bundle(s), and delete bundle configuration. Default False. Mutually exclusive with before, after, and keep_last. Returns ------- dict bundles removed Examples -------- Remove all but the last ingestion for a bundle called 'aus-1min': >>> from quantrocket.zipline import clean_bundles >>> clean_bundles("aus-1min", keep_last=1) Remove all ingestions for bundles called 'aus-1min' and 'usa-1min': >>> clean_bundles(["aus-1min", "usa-1min"], clean_all=True) """ params = {} params["bundles"] = bundles if before: params["before"] = before if after: params["after"] = after if keep_last: params["keep_last"] = keep_last if clean_all: params["clean_all"] = clean_all response = houston.delete("/zipline/bundles", params=params) houston.raise_for_status_with_json(response) return response.json()
def drop_db(code, confirm_by_typing_db_code_again=None, cascade=False): """ Delete a tick database or aggregate database. Deleting a tick database deletes its configuration and data and any associated aggregate databases. Deleting an aggregate database does not delete the tick database from which it is derived. Deleting databases is irreversible. Parameters ---------- code : str, required the tick database code or aggregate database code confirm_by_typing_db_code_again : str, required enter the db code again to confirm you want to drop the database, its config, and all its data cascade : bool also delete associated aggregated databases, if any. Only applicable when deleting a tick database. Returns ------- dict status message """ params = {"confirm_by_typing_db_code_again": confirm_by_typing_db_code_again} if cascade: params["cascade"] = cascade response = houston.delete("/realtime/databases/{0}".format(code), params=params) houston.raise_for_status_with_json(response) return response.json()
def cancel_orders(order_ids=None, conids=None, strategies=None, cancel_all=None): """ Cancel one or more orders by order ID, conid, or strategy (order ref). Parameters ---------- order_ids : list of str, optional cancel these order IDs conids : list of int, optional cancel orders for these conids strategies: list of str, optional cancel orders for these strategy codes) cancel_all : bool cancel all open orders Returns ------- dict status message Examples -------- Cancel orders by order ID: >>> cancel_orders(order_ids=['DU12345:7002:45','DU12345:7002:46']) Cancel orders by conid: >>> cancel_orders(conids=[123456]) Cancel orders by strategy (order ref): >>> cancel_orders(strategies=['my-strategy']) Cancel all open orders: >>> cancel_orders(cancel_all=True) """ params = {} if order_ids: params["order_ids"] = order_ids if conids: params["conids"] = conids if strategies: params["strategies"] = strategies if cancel_all: params["cancel_all"] = cancel_all response = houston.delete("/blotter/orders", params=params) houston.raise_for_status_with_json(response) return response.json()
def delist_security(conid=None, symbol=None, exchange=None, currency=None, sec_type=None): """ Mark a security as delisted. The security can be specified by conid or a combination of other parameters (for example, symbol + exchange). As a precaution, the request will fail if the parameters match more than one security. Parameters ---------- conid : int, optional the conid of the security to be delisted symbol : str, optional the symbol to be delisted (if conid not provided) exchange : str, optional the exchange of the security to be delisted (if needed to disambiguate) currency : str, optional the currency of the security to be delisted (if needed to disambiguate) sec_type : str, optional the security type of the security to be delisted (if needed to disambiguate). Possible choices: STK, ETF, FUT, CASH, IND Returns ------- dict status message """ params = {} if conid: params["conids"] = conid if symbol: params["symbols"] = symbol if exchange: params["exchanges"] = exchange if currency: params["currencies"] = currency if sec_type: params["sec_types"] = sec_type response = houston.delete("/master/securities", params=params) houston.raise_for_status_with_json(response) return response.json()
def cancel_market_data(codes=None, conids=None, universes=None, cancel_all=False): """ Cancel market data collection. Parameters ---------- codes : list of str, optional the tick database code(s) to cancel collection for conids : list of int, optional cancel market data for these conids, overriding db config universes : list of str, optional cancel market data for these universes, overriding db config cancel_all : bool cancel all market data collection Returns ------- dict subscribed tickers by vendor and database, after cancellation Examples -------- Cancel market data collection for a tick database called 'globex-fut-taq': >>> cancel_market_data("globex-fut-taq") Cancel all market data collection: >>> cancel_market_data(cancel_all=True) """ params = {} if codes: params["codes"] = codes if conids: params["conids"] = conids if universes: params["universes"] = universes if cancel_all: params["cancel_all"] = cancel_all response = houston.delete("/realtime/collections", params=params) houston.raise_for_status_with_json(response) return response.json()
def delete_universe(code): """ Delete a universe. (The listings details of the member securities won't be deleted, only their grouping as a universe). Parameters ---------- code : str, required the universe code Returns ------- dict status message """ response = houston.delete("/master/universes/{0}".format(code)) houston.raise_for_status_with_json(response) return response.json()
def stop_gateways(exchanges=None, sec_type=None, research_vendors=None, gateways=None, wait=False): """ Stop one or more IB Gateway services. Parameters ---------- exchanges : list of str, optional limit to IB Gateway services with market data permission for these exchanges sec_type : str, optional limit to IB Gateway services with market data permission for this securitiy type (useful for disambiguating permissions for exchanges that trade multiple asset classes). Possible choices: STK, FUT, CASH, OPT research_vendors : list of str, optional limit to IB Gateway services with permission for these research vendors (choices: reuters, wsh) gateways : list of str, optional limit to these IB Gateway services wait: bool wait for the IB Gateway services to stop before returning (default is to stop the gateways asynchronously) Returns ------- dict status message """ params = {"wait": wait} if sec_type: params["sec_type"] = sec_type if exchanges: params["exchanges"] = exchanges if research_vendors: params["research_vendors"] = research_vendors if gateways: params["gateways"] = gateways response = houston.delete("/launchpad/gateways", params=params, timeout=45) houston.raise_for_status_with_json(response) return response.json()
def clean_bundles(bundle=None, before=None, after=None, keep_last=None): """ Clean up data downloaded with the ingest command. Parameters ---------- bundle : str, optional the data bundle to clean (default is quantopian-quandl) before : str, optional clear all data before this TIMESTAMP. This may not be passed with keep_last after : str, optional clear all data after this TIMESTAMP. This may not be passed with keep_last keep_last : int, optional clear all but the last N downloads. This may not be passed with before or after. Returns ------- list bundles removed """ params = {} if bundle: params["bundle"] = bundle if before: params["before"] = before if after: params["after"] = after if keep_last: params["keep_last"] = keep_last response = houston.delete("/zipline/bundles", params=params) houston.raise_for_status_with_json(response) return response.json()
def close_positions(filepath_or_buffer=None, output="csv", order_refs=None, accounts=None, conids=None, params=None): """ Generate orders to close positions. Doesn't actually place any orders but returns an orders file that can be placed separately. Additional order parameters can be appended with the `params` argument. Parameters ---------- filepath_or_buffer : str or file-like object filepath to write the data to, or file-like object (defaults to stdout) output : str output format (json or csv, default is csv) order_refs : list of str, optional limit to these order refs accounts : list of str, optional limit to these accounts conids : list of int, optional limit to these conids params : dict of PARAM:VALUE, optional additional parameters to append to each row in output (pass as {param:value}, for example {"OrderType":"MKT"}) Returns ------- None Examples -------- Get orders to close positions, then place the orders: >>> from quantrocket.blotter import place_orders, close_positions >>> import io >>> orders_file = io.StringIO() >>> close_positions(orders_file, params={"OrderType":"MKT", "Tif":"DAY", "Exchange":"SMART"}) >>> place_orders(infilepath_or_buffer=orders_file) """ _params = {} if order_refs: _params["order_refs"] = order_refs if accounts: _params["accounts"] = accounts if conids: _params["conids"] = conids if params: _params["params"] = dict_to_dict_strs(params) output = output or "csv" if output not in ("csv", "json"): raise ValueError("Invalid ouput: {0}".format(output)) response = houston.delete("/blotter/positions.{0}".format(output), params=_params) houston.raise_for_status_with_json(response) # Don't write a null response to file if response.content[:4] == b"null": return filepath_or_buffer = filepath_or_buffer or sys.stdout write_response_to_filepath_or_buffer(filepath_or_buffer, response)