code
stringlengths
66
870k
docstring
stringlengths
19
26.7k
func_name
stringlengths
1
138
language
stringclasses
1 value
repo
stringlengths
7
68
path
stringlengths
5
324
url
stringlengths
46
389
license
stringclasses
7 values
def nullify_frame_stats(self, now): """ Save all period_stats to local directory erase old files from the folder and nullify self.frame_stats Parameters ---------- now: Timestamp Returns ------- """ save_algo_object( ...
Save all period_stats to local directory erase old files from the folder and nullify self.frame_stats Parameters ---------- now: Timestamp Returns -------
nullify_frame_stats
python
scrtlabs/catalyst
catalyst/exchange/exchange_algorithm.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/exchange_algorithm.py
Apache-2.0
def handle_data(self, data): """ Wrapper around the handle_data method of each algo. Parameters ---------- data """ if not self.is_running: return # Resetting the frame stats every day to minimize memory footprint today = data.curren...
Wrapper around the handle_data method of each algo. Parameters ---------- data
handle_data
python
scrtlabs/catalyst
catalyst/exchange/exchange_algorithm.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/exchange_algorithm.py
Apache-2.0
def get_order(self, order_id, asset_or_symbol=None, return_price=False, params={}): """Lookup an order based on the order id returned from one of the order functions. Parameters ---------- order_id : str The unique identifier for the order. ...
Lookup an order based on the order id returned from one of the order functions. Parameters ---------- order_id : str The unique identifier for the order. asset_or_symbol: Asset or str The asset or the tradingPair symbol of the order. return_price:...
get_order
python
scrtlabs/catalyst
catalyst/exchange/exchange_algorithm.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/exchange_algorithm.py
Apache-2.0
def cancel_order(self, order_param, symbol=None, params={}): """Cancel an open order. Parameters ---------- order_param : str or Order The order_id or order object to cancel. symbol: str The tradingPair symbol params: dict, optional Ex...
Cancel an open order. Parameters ---------- order_param : str or Order The order_id or order object to cancel. symbol: str The tradingPair symbol params: dict, optional Extra parameters to pass to the exchange
cancel_order
python
scrtlabs/catalyst
catalyst/exchange/exchange_algorithm.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/exchange_algorithm.py
Apache-2.0
def sids(self): """ This seems to be used to pre-fetch assets. I don't think that we need this for live-trading. Leaving the list empty. """ all_sids = [] for exchange_name in self.exchanges: # This is what initializes each exchanges at the beginning ...
This seems to be used to pre-fetch assets. I don't think that we need this for live-trading. Leaving the list empty.
sids
python
scrtlabs/catalyst
catalyst/exchange/exchange_asset_finder.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/exchange_asset_finder.py
Apache-2.0
def retrieve_asset(self, sid, default_none=False): """ Retrieve the first Asset found for a given sid. """ asset = None for exchange_name in self.exchanges: if asset is not None: break exchange = self.exchanges[exchange_name] a...
Retrieve the first Asset found for a given sid.
retrieve_asset
python
scrtlabs/catalyst
catalyst/exchange/exchange_asset_finder.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/exchange_asset_finder.py
Apache-2.0
def lookup_symbol(self, symbol, exchange, data_frequency=None, as_of_date=None, fuzzy=False): """Lookup an asset by symbol. Parameters ---------- symbol : str The ticker symbol to resolve. as_of_date : datetime or None Look up the la...
Lookup an asset by symbol. Parameters ---------- symbol : str The ticker symbol to resolve. as_of_date : datetime or None Look up the last owner of this symbol as of this datetime. If ``as_of_date`` is None, then this can only resolve the equity ...
lookup_symbol
python
scrtlabs/catalyst
catalyst/exchange/exchange_asset_finder.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/exchange_asset_finder.py
Apache-2.0
def calculate(self, order, transaction): """ Calculate the final fee based on the order parameters. :param order: Order :param transaction: Transaction :return float: The total commission. """ cost = abs(transaction.amount) * transaction.price ...
Calculate the final fee based on the order parameters. :param order: Order :param transaction: Transaction :return float: The total commission.
calculate
python
scrtlabs/catalyst
catalyst/exchange/exchange_blotter.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/exchange_blotter.py
Apache-2.0
def check_open_orders(self): """ Loop through the list of open orders in the Portfolio object. For each executed order found, create a transaction and apply to the Portfolio. Returns ------- list[Transaction] """ for asset in self.open_orders: ...
Loop through the list of open orders in the Portfolio object. For each executed order found, create a transaction and apply to the Portfolio. Returns ------- list[Transaction]
check_open_orders
python
scrtlabs/catalyst
catalyst/exchange/exchange_blotter.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/exchange_blotter.py
Apache-2.0
def get_reader(self, data_frequency, path=None): """ Get a data writer object, either a new object or from cache Returns ------- BcolzMinuteBarReader | BcolzDailyBarReader """ if path is None: root = get_exchange_folder(self.exchange_name) ...
Get a data writer object, either a new object or from cache Returns ------- BcolzMinuteBarReader | BcolzDailyBarReader
get_reader
python
scrtlabs/catalyst
catalyst/exchange/exchange_bundle.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/exchange_bundle.py
Apache-2.0
def get_writer(self, start_dt, end_dt, data_frequency): """ Get a data writer object, either a new object or from cache Returns ------- BcolzMinuteBarWriter | BcolzDailyBarWriter """ root = get_exchange_folder(self.exchange_name) path = BUNDLE_NAME_TEMPL...
Get a data writer object, either a new object or from cache Returns ------- BcolzMinuteBarWriter | BcolzDailyBarWriter
get_writer
python
scrtlabs/catalyst
catalyst/exchange/exchange_bundle.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/exchange_bundle.py
Apache-2.0
def filter_existing_assets(self, assets, start_dt, end_dt, data_frequency): """ For each asset, get the close on the start and end dates of the chunk. If the data exists, the chunk ingestion is complete. If any data is missing we ingest the data. Parameters -----...
For each asset, get the close on the start and end dates of the chunk. If the data exists, the chunk ingestion is complete. If any data is missing we ingest the data. Parameters ---------- assets: list[TradingPair] The assets is scope. start_...
filter_existing_assets
python
scrtlabs/catalyst
catalyst/exchange/exchange_bundle.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/exchange_bundle.py
Apache-2.0
def get_calendar_periods_range(self, start_dt, end_dt, data_frequency): """ Get a list of dates for the specified range. Parameters ---------- start_dt: pd.Timestamp end_dt: pd.Timestamp data_frequency: str Returns ------- list[datetime] ...
Get a list of dates for the specified range. Parameters ---------- start_dt: pd.Timestamp end_dt: pd.Timestamp data_frequency: str Returns ------- list[datetime]
get_calendar_periods_range
python
scrtlabs/catalyst
catalyst/exchange/exchange_bundle.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/exchange_bundle.py
Apache-2.0
def ingest_df(self, ohlcv_df, data_frequency, asset, writer, empty_rows_behavior='warn', duplicates_threshold=None): """ Ingest a DataFrame of OHLCV data for a given market. Parameters ---------- ohlcv_df: DataFrame data_frequency: str asset: Tr...
Ingest a DataFrame of OHLCV data for a given market. Parameters ---------- ohlcv_df: DataFrame data_frequency: str asset: TradingPair writer: empty_rows_behavior: str
ingest_df
python
scrtlabs/catalyst
catalyst/exchange/exchange_bundle.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/exchange_bundle.py
Apache-2.0
def ingest_ctable(self, asset, data_frequency, period, writer, empty_rows_behavior='strip', duplicates_threshold=100, cleanup=False): """ Merge a ctable bundle chunk into the main bundle for the exchange. Parameters ---------- asset: T...
Merge a ctable bundle chunk into the main bundle for the exchange. Parameters ---------- asset: TradingPair data_frequency: str period: str writer: empty_rows_behavior: str Ensure that the bundle does not have any missing data. clean...
ingest_ctable
python
scrtlabs/catalyst
catalyst/exchange/exchange_bundle.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/exchange_bundle.py
Apache-2.0
def get_adj_dates(self, start, end, assets, data_frequency): """ Contains a date range to the trading availability of the specified markets. Parameters ---------- start: pd.Timestamp end: pd.Timestamp assets: list[TradingPair] data_frequency: str ...
Contains a date range to the trading availability of the specified markets. Parameters ---------- start: pd.Timestamp end: pd.Timestamp assets: list[TradingPair] data_frequency: str Returns ------- pd.Timestamp, pd.Timestamp ...
get_adj_dates
python
scrtlabs/catalyst
catalyst/exchange/exchange_bundle.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/exchange_bundle.py
Apache-2.0
def prepare_chunks(self, assets, data_frequency, start_dt, end_dt): """ Split a price data request into chunks corresponding to individual bundles. Parameters ---------- assets: list[TradingPair] data_frequency: str start_dt: pd.Timestamp end_dt: ...
Split a price data request into chunks corresponding to individual bundles. Parameters ---------- assets: list[TradingPair] data_frequency: str start_dt: pd.Timestamp end_dt: pd.Timestamp Returns ------- dict[TradingPair, list[di...
prepare_chunks
python
scrtlabs/catalyst
catalyst/exchange/exchange_bundle.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/exchange_bundle.py
Apache-2.0
def ingest_assets(self, assets, data_frequency, start_dt=None, end_dt=None, show_progress=False, show_breakdown=False, show_report=False): """ Determine if data is missing from the bundle and attempt to ingest it. Parameters ---------- ...
Determine if data is missing from the bundle and attempt to ingest it. Parameters ---------- assets: list[TradingPair] data_frequency: str start_dt: pd.Timestamp end_dt: pd.Timestamp show_progress: bool show_breakdown: bool
ingest_assets
python
scrtlabs/catalyst
catalyst/exchange/exchange_bundle.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/exchange_bundle.py
Apache-2.0
def ingest_csv(self, path, data_frequency, empty_rows_behavior='strip', duplicates_threshold=100): """ Ingest price data from a CSV file. Parameters ---------- path: str data_frequency: str Returns ------- list[str] ...
Ingest price data from a CSV file. Parameters ---------- path: str data_frequency: str Returns ------- list[str] A list of potential problems detected during ingestion.
ingest_csv
python
scrtlabs/catalyst
catalyst/exchange/exchange_bundle.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/exchange_bundle.py
Apache-2.0
def ingest(self, data_frequency, include_symbols=None, exclude_symbols=None, start=None, end=None, csv=None, show_progress=True, show_breakdown=True, show_report=True): """ Inject data based on specified parameters. Parameters ---------- data_freque...
Inject data based on specified parameters. Parameters ---------- data_frequency: str include_symbols: str exclude_symbols: str start: pd.Timestamp end: pd.Timestamp show_progress: bool environ:
ingest
python
scrtlabs/catalyst
catalyst/exchange/exchange_bundle.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/exchange_bundle.py
Apache-2.0
def get_history_window_series_and_load(self, assets, end_dt, bar_count, field, data_frequency, ...
Retrieve price data history, ingest missing data. Parameters ---------- assets: list[TradingPair] end_dt: pd.Timestamp bar_count: int field: str data_frequency: str algo_end_dt: pd.Timestamp force_auto_ingest: Returns ---...
get_history_window_series_and_load
python
scrtlabs/catalyst
catalyst/exchange/exchange_bundle.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/exchange_bundle.py
Apache-2.0
def get_spot_values(self, assets, field, dt, data_frequency, reset_reader=False ): """ The spot values for the gives assets, field and date. Reads from ...
The spot values for the gives assets, field and date. Reads from the exchange data bundle. Parameters ---------- assets: list[TradingPair] field: str dt: pd.Timestamp data_frequency: str reset_reader: Returns ------- floa...
get_spot_values
python
scrtlabs/catalyst
catalyst/exchange/exchange_bundle.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/exchange_bundle.py
Apache-2.0
def clean(self, data_frequency): """ Removing the bundle data from the catalyst folder. Parameters ---------- data_frequency: str """ log.debug('cleaning exchange {}, frequency {}'.format( self.exchange_name, data_frequency )) root = ...
Removing the bundle data from the catalyst folder. Parameters ---------- data_frequency: str
clean
python
scrtlabs/catalyst
catalyst/exchange/exchange_bundle.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/exchange_bundle.py
Apache-2.0
def get_exchange_history_window(self, exchange_name, assets, end_dt, bar_count, frequency, field, ...
Fetching price history window from the exchange. Parameters ---------- exchange_name: Exchange assets: list[TradingPair] end_dt: datetime bar_count: int frequency: str field: str data_frequency: str ffill: bool Returns ...
get_exchange_history_window
python
scrtlabs/catalyst
catalyst/exchange/exchange_data_portal.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/exchange_data_portal.py
Apache-2.0
def get_exchange_spot_value(self, exchange_name, assets, field, dt, data_frequency): """ A spot value for the exchange. Parameters ---------- exchange_name: str assets: list[TradingPair] field: str dt: datetime data...
A spot value for the exchange. Parameters ---------- exchange_name: str assets: list[TradingPair] field: str dt: datetime data_frequency: str Returns ------- float
get_exchange_spot_value
python
scrtlabs/catalyst
catalyst/exchange/exchange_data_portal.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/exchange_data_portal.py
Apache-2.0
def get_exchange_history_window(self, exchange_name, assets, end_dt, bar_count, frequency, field, ...
Fetching price history window from the exchange bundle. Parameters ---------- exchange: Exchange assets: list[TradingPair] end_dt: datetime bar_count: int frequency: str field: str data_frequency: str ffill: bool Returns ...
get_exchange_history_window
python
scrtlabs/catalyst
catalyst/exchange/exchange_data_portal.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/exchange_data_portal.py
Apache-2.0
def get_exchange_spot_value(self, exchange_name, assets, field, dt, data_frequency ): """ A spot value for the e...
A spot value for the exchange bundle. Try to ingest data if not in the bundle. Parameters ---------- exchange_name: str assets: list[TradingPair] field: str dt: datetime data_frequency: str Returns ------- float
get_exchange_spot_value
python
scrtlabs/catalyst
catalyst/exchange/exchange_data_portal.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/exchange_data_portal.py
Apache-2.0
def create_order(self, order): """ Create an open order and store in memory. Parameters ---------- order: Order """ log.debug('creating order {}'.format(order.id)) open_orders = self.open_orders[order.asset] \ if order.asset is self.open_ord...
Create an open order and store in memory. Parameters ---------- order: Order
create_order
python
scrtlabs/catalyst
catalyst/exchange/exchange_portfolio.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/exchange_portfolio.py
Apache-2.0
def execute_order(self, order, transaction): """ Update the open orders and positions to apply an executed order. Unlike with backtesting, we do not need to add slippage and fees. The executed price includes transaction fees. Parameters ---------- order: Order ...
Update the open orders and positions to apply an executed order. Unlike with backtesting, we do not need to add slippage and fees. The executed price includes transaction fees. Parameters ---------- order: Order transaction: Transaction
execute_order
python
scrtlabs/catalyst
catalyst/exchange/exchange_portfolio.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/exchange_portfolio.py
Apache-2.0
def remove_order(self, order): """ Removing an open order. Parameters ---------- order: Order """ log.info('removing cancelled order {}'.format(order.id)) self._remove_open_order(order) order_position = self.positions[order.asset] \ ...
Removing an open order. Parameters ---------- order: Order
remove_order
python
scrtlabs/catalyst
catalyst/exchange/exchange_portfolio.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/exchange_portfolio.py
Apache-2.0
def get_market(self, symbol): """ The CCXT market. Parameters ---------- symbol: The CCXT symbol. Returns ------- dict[str, Object] """ s = self.get_symbol(symbol) market = next( (market for market in self...
The CCXT market. Parameters ---------- symbol: The CCXT symbol. Returns ------- dict[str, Object]
get_market
python
scrtlabs/catalyst
catalyst/exchange/ccxt/ccxt_exchange.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/ccxt/ccxt_exchange.py
Apache-2.0
def get_symbol(self, asset_or_symbol, source='catalyst'): """ The CCXT symbol. Parameters ---------- asset_or_symbol source Returns ------- """ if source == 'ccxt': if isinstance(asset_or_symbol, string_types): ...
The CCXT symbol. Parameters ---------- asset_or_symbol source Returns -------
get_symbol
python
scrtlabs/catalyst
catalyst/exchange/ccxt/ccxt_exchange.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/ccxt/ccxt_exchange.py
Apache-2.0
def map_frequency(value, source='ccxt', raise_error=True): """ Map a frequency value between CCXT and Catalyst Parameters ---------- value: str source: str raise_error: bool Returns ------- Notes ----- The Pandas offset a...
Map a frequency value between CCXT and Catalyst Parameters ---------- value: str source: str raise_error: bool Returns ------- Notes ----- The Pandas offset aliases supported by Catalyst: Alias Description W week...
map_frequency
python
scrtlabs/catalyst
catalyst/exchange/ccxt/ccxt_exchange.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/ccxt/ccxt_exchange.py
Apache-2.0
def get_timeframe(freq, raise_error=True): """ The CCXT timeframe from the Catalyst frequency. Parameters ---------- freq: str The Catalyst frequency (Pandas convention) Returns ------- str """ return CCXT.map_frequency( ...
The CCXT timeframe from the Catalyst frequency. Parameters ---------- freq: str The Catalyst frequency (Pandas convention) Returns ------- str
get_timeframe
python
scrtlabs/catalyst
catalyst/exchange/ccxt/ccxt_exchange.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/ccxt/ccxt_exchange.py
Apache-2.0
def get_frequency(timeframe, raise_error=True): """ Test Catalyst frequency from the CCXT timeframe Catalyst uses the Pandas offset alias convention: http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases Parameters ---------- timeframe ...
Test Catalyst frequency from the CCXT timeframe Catalyst uses the Pandas offset alias convention: http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases Parameters ---------- timeframe Returns -------
get_frequency
python
scrtlabs/catalyst
catalyst/exchange/ccxt/ccxt_exchange.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/ccxt/ccxt_exchange.py
Apache-2.0
def get_asset_defs(self, market): """ The local and Catalyst definitions of the specified market. Parameters ---------- market: dict[str, Object] The CCXT market dicts. Returns ------- dict[str, Object] The asset definition. ...
The local and Catalyst definitions of the specified market. Parameters ---------- market: dict[str, Object] The CCXT market dicts. Returns ------- dict[str, Object] The asset definition.
get_asset_defs
python
scrtlabs/catalyst
catalyst/exchange/ccxt/ccxt_exchange.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/ccxt/ccxt_exchange.py
Apache-2.0
def get_asset_def(self, market, is_local=False): """ The asset definition (in symbols.json files) corresponding to the the specified market. Parameters ---------- market: dict[str, Object] The CCXT market dict. is_local Whether to search i...
The asset definition (in symbols.json files) corresponding to the the specified market. Parameters ---------- market: dict[str, Object] The CCXT market dict. is_local Whether to search in local or Catalyst asset definitions. Returns ...
get_asset_def
python
scrtlabs/catalyst
catalyst/exchange/ccxt/ccxt_exchange.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/ccxt/ccxt_exchange.py
Apache-2.0
def create_trading_pair(self, market, asset_def=None, is_local=False): """ Creating a TradingPair from market and asset data. Parameters ---------- market: dict[str, Object] asset_def: dict[str, Object] is_local: bool Returns ------- """...
Creating a TradingPair from market and asset data. Parameters ---------- market: dict[str, Object] asset_def: dict[str, Object] is_local: bool Returns -------
create_trading_pair
python
scrtlabs/catalyst
catalyst/exchange/ccxt/ccxt_exchange.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/ccxt/ccxt_exchange.py
Apache-2.0
def _create_order(self, order_status): """ Create a Catalyst order object from a CCXT order dictionary Parameters ---------- order_status: dict[str, Object] The order dict from the CCXT api. Returns ------- Order The Catalyst orde...
Create a Catalyst order object from a CCXT order dictionary Parameters ---------- order_status: dict[str, Object] The order dict from the CCXT api. Returns ------- Order The Catalyst order object
_create_order
python
scrtlabs/catalyst
catalyst/exchange/ccxt/ccxt_exchange.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/ccxt/ccxt_exchange.py
Apache-2.0
def _check_order_found(self, previous_orders): """ check if .orders was updated after the fetch api method was called and if so extract the new order which should be returned to the user :param previous_orders: dict(dict()) :return: order: Order if an order was found, otherwise,...
check if .orders was updated after the fetch api method was called and if so extract the new order which should be returned to the user :param previous_orders: dict(dict()) :return: order: Order if an order was found, otherwise, None
_check_order_found
python
scrtlabs/catalyst
catalyst/exchange/ccxt/ccxt_exchange.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/ccxt/ccxt_exchange.py
Apache-2.0
def _fetch_missing_order(self, dt_before, symbol): """ check if order was created by running through all api functions according to ccxt manual :param dt_before: pd.Timestamp :return: order: Order/ order_id: str if an order was found, otherwise None """ ...
check if order was created by running through all api functions according to ccxt manual :param dt_before: pd.Timestamp :return: order: Order/ order_id: str if an order was found, otherwise None
_fetch_missing_order
python
scrtlabs/catalyst
catalyst/exchange/ccxt/ccxt_exchange.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/ccxt/ccxt_exchange.py
Apache-2.0
def _handle_request_timeout(self, dt_before, asset, amount, is_buy, style, prec_amount): """ Check if an order was received during the timeout, if it appeared on the orders dict return it to the user. If an order_id was traced alone, an order is created ma...
Check if an order was received during the timeout, if it appeared on the orders dict return it to the user. If an order_id was traced alone, an order is created manually and returned to the user. Otherwise, send none to raise an error and retry the call. :param dt_before...
_handle_request_timeout
python
scrtlabs/catalyst
catalyst/exchange/ccxt/ccxt_exchange.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/ccxt/ccxt_exchange.py
Apache-2.0
def _process_order_fallback(self, order): """ Fallback method for exchanges which do not play nice with fetch-my-trades. Apparently, about 60% of exchanges will return the correct executed values with this method. Others will support fetch-my-trades. Parameters -...
Fallback method for exchanges which do not play nice with fetch-my-trades. Apparently, about 60% of exchanges will return the correct executed values with this method. Others will support fetch-my-trades. Parameters ---------- order: Order Returns ...
_process_order_fallback
python
scrtlabs/catalyst
catalyst/exchange/ccxt/ccxt_exchange.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/ccxt/ccxt_exchange.py
Apache-2.0
def tickers(self, assets, on_ticker_error='raise'): """ Retrieve current tick data for the given assets Parameters ---------- assets: list[TradingPair] Returns ------- list[dict[str, float] """ if len(assets) == 1 or not self.api.has['fe...
Retrieve current tick data for the given assets Parameters ---------- assets: list[TradingPair] Returns ------- list[dict[str, float]
tickers
python
scrtlabs/catalyst
catalyst/exchange/ccxt/ccxt_exchange.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/ccxt/ccxt_exchange.py
Apache-2.0
def get_bcolz_chunk(exchange_name, symbol, data_frequency, period): """ Download and extract a bcolz bundle. Parameters ---------- exchange_name: str symbol: str data_frequency: str period: str Returns ------- str Filename: bitfinex-daily-neo_eth-2017-10.tar.gz ...
Download and extract a bcolz bundle. Parameters ---------- exchange_name: str symbol: str data_frequency: str period: str Returns ------- str Filename: bitfinex-daily-neo_eth-2017-10.tar.gz
get_bcolz_chunk
python
scrtlabs/catalyst
catalyst/exchange/utils/bundle_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/bundle_utils.py
Apache-2.0
def get_df_from_arrays(arrays, periods): """ A DataFrame from the specified OHCLV arrays. Parameters ---------- arrays: Object periods: DateTimeIndex Returns ------- DataFrame """ ohlcv = dict() for index, field in enumerate( ['open', 'high', 'low', 'close'...
A DataFrame from the specified OHCLV arrays. Parameters ---------- arrays: Object periods: DateTimeIndex Returns ------- DataFrame
get_df_from_arrays
python
scrtlabs/catalyst
catalyst/exchange/utils/bundle_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/bundle_utils.py
Apache-2.0
def range_in_bundle(asset, start_dt, end_dt, reader): """ Evaluate whether price data of an asset is included has been ingested in the exchange bundle for the given date range. Parameters ---------- asset: TradingPair start_dt: datetime end_dt: datetime reader: BcolzBarMinuteReader ...
Evaluate whether price data of an asset is included has been ingested in the exchange bundle for the given date range. Parameters ---------- asset: TradingPair start_dt: datetime end_dt: datetime reader: BcolzBarMinuteReader Returns ------- bool
range_in_bundle
python
scrtlabs/catalyst
catalyst/exchange/utils/bundle_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/bundle_utils.py
Apache-2.0
def get_assets(exchange, include_symbols, exclude_symbols): """ Get assets from an exchange, including or excluding the specified symbols. Parameters ---------- exchange: Exchange include_symbols: str exclude_symbols: str Returns ------- list[TradingPair] """ if in...
Get assets from an exchange, including or excluding the specified symbols. Parameters ---------- exchange: Exchange include_symbols: str exclude_symbols: str Returns ------- list[TradingPair]
get_assets
python
scrtlabs/catalyst
catalyst/exchange/utils/bundle_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/bundle_utils.py
Apache-2.0
def get_seconds_from_date(date): """ The number of seconds from the epoch. Parameters ---------- date: datetime Returns ------- int """ epoch = datetime.utcfromtimestamp(0) epoch = epoch.replace(tzinfo=pytz.UTC) return int((date - epoch).total_seconds())
The number of seconds from the epoch. Parameters ---------- date: datetime Returns ------- int
get_seconds_from_date
python
scrtlabs/catalyst
catalyst/exchange/utils/datetime_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/datetime_utils.py
Apache-2.0
def get_delta(periods, data_frequency): """ Get a time delta based on the specified data frequency. Parameters ---------- periods: int data_frequency: str Returns ------- timedelta """ return timedelta(minutes=periods) \ if data_frequency == 'minute' else timedelta...
Get a time delta based on the specified data frequency. Parameters ---------- periods: int data_frequency: str Returns ------- timedelta
get_delta
python
scrtlabs/catalyst
catalyst/exchange/utils/datetime_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/datetime_utils.py
Apache-2.0
def get_periods_range(freq, start_dt=None, end_dt=None, periods=None): """ Get a date range for the specified parameters. Parameters ---------- start_dt: datetime end_dt: datetime freq: str Returns ------- DateTimeIndex """ if freq == 'minute': freq = 'T' ...
Get a date range for the specified parameters. Parameters ---------- start_dt: datetime end_dt: datetime freq: str Returns ------- DateTimeIndex
get_periods_range
python
scrtlabs/catalyst
catalyst/exchange/utils/datetime_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/datetime_utils.py
Apache-2.0
def get_start_dt(end_dt, bar_count, data_frequency, include_first=True): """ The start date based on specified end date and data frequency. Parameters ---------- end_dt: datetime bar_count: int data_frequency: str include_first Returns ------- datetime """ periods ...
The start date based on specified end date and data frequency. Parameters ---------- end_dt: datetime bar_count: int data_frequency: str include_first Returns ------- datetime
get_start_dt
python
scrtlabs/catalyst
catalyst/exchange/utils/datetime_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/datetime_utils.py
Apache-2.0
def get_period_label(dt, data_frequency): """ The period label for the specified date and frequency. Parameters ---------- dt: datetime data_frequency: str Returns ------- str """ if data_frequency == 'minute': return '{}-{:02d}'.format(dt.year, dt.month) else:...
The period label for the specified date and frequency. Parameters ---------- dt: datetime data_frequency: str Returns ------- str
get_period_label
python
scrtlabs/catalyst
catalyst/exchange/utils/datetime_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/datetime_utils.py
Apache-2.0
def get_month_start_end(dt, first_day=None, last_day=None): """ The first and last day of the month for the specified date. Parameters ---------- dt: datetime first_day: datetime last_day: datetime Returns ------- datetime, datetime """ month_range = calendar.monthrang...
The first and last day of the month for the specified date. Parameters ---------- dt: datetime first_day: datetime last_day: datetime Returns ------- datetime, datetime
get_month_start_end
python
scrtlabs/catalyst
catalyst/exchange/utils/datetime_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/datetime_utils.py
Apache-2.0
def get_year_start_end(dt, first_day=None, last_day=None): """ The first and last day of the year for the specified date. Parameters ---------- dt: datetime first_day: datetime last_day: datetime Returns ------- datetime, datetime """ year_start = first_day if first_d...
The first and last day of the year for the specified date. Parameters ---------- dt: datetime first_day: datetime last_day: datetime Returns ------- datetime, datetime
get_year_start_end
python
scrtlabs/catalyst
catalyst/exchange/utils/datetime_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/datetime_utils.py
Apache-2.0
def get_frequency(freq, data_frequency=None, supported_freqs=['D', 'H', 'T']): """ Takes an arbitrary candle size (e.g. 15T) and converts to the lowest common denominator supported by the data bundles (e.g. 1T). The data bundles only support 1T and 1D frequencies. If another frequency is requested, ...
Takes an arbitrary candle size (e.g. 15T) and converts to the lowest common denominator supported by the data bundles (e.g. 1T). The data bundles only support 1T and 1D frequencies. If another frequency is requested, Catalyst must request the underlying data and resample. Notes ----- We're...
get_frequency
python
scrtlabs/catalyst
catalyst/exchange/utils/datetime_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/datetime_utils.py
Apache-2.0
def get_candles_number_from_minutes(unit, candle_size, minutes): """ Get the number of bars needed for the given time interval in minutes. Notes ----- Supports only "T", "D" and "H" units Parameters ---------- unit: str candle_size : int minutes: int Returns ------...
Get the number of bars needed for the given time interval in minutes. Notes ----- Supports only "T", "D" and "H" units Parameters ---------- unit: str candle_size : int minutes: int Returns ------- int
get_candles_number_from_minutes
python
scrtlabs/catalyst
catalyst/exchange/utils/datetime_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/datetime_utils.py
Apache-2.0
def get_sid(symbol): """ Create a sid by hashing the symbol of a currency pair. Parameters ---------- symbol: str Returns ------- int The resulting sid. """ sid = int( hashlib.sha256(symbol.encode('utf-8')).hexdigest(), 16 ) % 10 ** 6 return sid
Create a sid by hashing the symbol of a currency pair. Parameters ---------- symbol: str Returns ------- int The resulting sid.
get_sid
python
scrtlabs/catalyst
catalyst/exchange/utils/exchange_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/exchange_utils.py
Apache-2.0
def get_remote_folder(environ=None): """ The root path of the remote folder. Parameters ---------- environ: Returns ------- str """ if not environ: environ = os.environ root = data_root(environ) remote_folder = os.path.join(root, 'remote') ensure_directory...
The root path of the remote folder. Parameters ---------- environ: Returns ------- str
get_remote_folder
python
scrtlabs/catalyst
catalyst/exchange/utils/exchange_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/exchange_utils.py
Apache-2.0
def get_exchange_folder(exchange_name): """ The root path of an exchange folder. Parameters ---------- exchange_name: str Returns ------- str """ root = data_root() exchange_folder = os.path.join(root, 'exchanges', exchange_name) ensure_directory(exchange_folder) ...
The root path of an exchange folder. Parameters ---------- exchange_name: str Returns ------- str
get_exchange_folder
python
scrtlabs/catalyst
catalyst/exchange/utils/exchange_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/exchange_utils.py
Apache-2.0
def get_exchange_symbols_filename(exchange_name, is_local=False): """ The absolute path of the exchange's symbol.json file. Parameters ---------- exchange_name: Returns ------- str """ name = 'symbols.json' if not is_local else 'symbols_local.json' exchange_folder = get_ex...
The absolute path of the exchange's symbol.json file. Parameters ---------- exchange_name: Returns ------- str
get_exchange_symbols_filename
python
scrtlabs/catalyst
catalyst/exchange/utils/exchange_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/exchange_utils.py
Apache-2.0
def download_exchange_symbols(exchange_name): """ Downloads the exchange's symbols.json from the repository. Parameters ---------- exchange_name: str environ: Returns ------- str """ filename = get_exchange_symbols_filename(exchange_name) url = SYMBOLS_URL.format(excha...
Downloads the exchange's symbols.json from the repository. Parameters ---------- exchange_name: str environ: Returns ------- str
download_exchange_symbols
python
scrtlabs/catalyst
catalyst/exchange/utils/exchange_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/exchange_utils.py
Apache-2.0
def get_exchange_symbols(exchange_name, is_local=False): """ The de-serialized content of the exchange's symbols.json. Parameters ---------- exchange_name: str is_local: bool environ: Returns ------- Object """ filename = get_exchange_symbols_filename(exchange_name, is...
The de-serialized content of the exchange's symbols.json. Parameters ---------- exchange_name: str is_local: bool environ: Returns ------- Object
get_exchange_symbols
python
scrtlabs/catalyst
catalyst/exchange/utils/exchange_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/exchange_utils.py
Apache-2.0
def save_exchange_symbols(exchange_name, assets, is_local=False): """ Save assets into an exchange_symbols file. Parameters ---------- exchange_name: str assets: list[dict[str, object]] is_local: bool environ Returns ------- """ asset_dicts = dict() for symbol in a...
Save assets into an exchange_symbols file. Parameters ---------- exchange_name: str assets: list[dict[str, object]] is_local: bool environ Returns -------
save_exchange_symbols
python
scrtlabs/catalyst
catalyst/exchange/utils/exchange_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/exchange_utils.py
Apache-2.0
def get_symbols_string(assets): """ A concatenated string of symbols from a list of assets. Parameters ---------- assets: list[TradingPair] Returns ------- str """ array = [assets] if isinstance(assets, TradingPair) else assets return ', '.join([asset.symbol for asset in a...
A concatenated string of symbols from a list of assets. Parameters ---------- assets: list[TradingPair] Returns ------- str
get_symbols_string
python
scrtlabs/catalyst
catalyst/exchange/utils/exchange_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/exchange_utils.py
Apache-2.0
def get_exchange_auth(exchange_name, alias=None): """ The de-serialized contend of the exchange's auth.json file. Parameters ---------- exchange_name: str alias: Returns ------- Object """ exchange_folder = get_exchange_folder(exchange_name) name = 'auth' if alias is N...
The de-serialized contend of the exchange's auth.json file. Parameters ---------- exchange_name: str alias: Returns ------- Object
get_exchange_auth
python
scrtlabs/catalyst
catalyst/exchange/utils/exchange_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/exchange_utils.py
Apache-2.0
def get_remote_auth(alias=None, environ=None): """ The de-serialized content of the remote auth.json file. Parameters ---------- environ: Returns ------- Object """ remote_folder = get_remote_folder(environ) name = 'remote_auth' if alias is None else alias filename = o...
The de-serialized content of the remote auth.json file. Parameters ---------- environ: Returns ------- Object
get_remote_auth
python
scrtlabs/catalyst
catalyst/exchange/utils/exchange_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/exchange_utils.py
Apache-2.0
def get_algo_folder(algo_name, environ=None): """ The algorithm root folder of the algorithm. Parameters ---------- algo_name: str environ: Returns ------- str """ if not environ: environ = os.environ root = data_root(environ) algo_folder = os.path.join(ro...
The algorithm root folder of the algorithm. Parameters ---------- algo_name: str environ: Returns ------- str
get_algo_folder
python
scrtlabs/catalyst
catalyst/exchange/utils/exchange_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/exchange_utils.py
Apache-2.0
def get_algo_object(algo_name, key, environ=None, rel_path=None, how='pickle'): """ The de-serialized object of the algo name and key. Parameters ---------- algo_name: str key: str environ: rel_path: str how: str Returns ------- Object """ if algo_name is None:...
The de-serialized object of the algo name and key. Parameters ---------- algo_name: str key: str environ: rel_path: str how: str Returns ------- Object
get_algo_object
python
scrtlabs/catalyst
catalyst/exchange/utils/exchange_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/exchange_utils.py
Apache-2.0
def save_algo_object(algo_name, key, obj, environ=None, rel_path=None, how='pickle'): """ Serialize and save an object by algo name and key. Parameters ---------- algo_name: str key: str obj: Object environ: rel_path: str how: str """ folder = get_a...
Serialize and save an object by algo name and key. Parameters ---------- algo_name: str key: str obj: Object environ: rel_path: str how: str
save_algo_object
python
scrtlabs/catalyst
catalyst/exchange/utils/exchange_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/exchange_utils.py
Apache-2.0
def get_algo_df(algo_name, key, environ=None, rel_path=None): """ The de-serialized DataFrame of an algo name and key. Parameters ---------- algo_name: str key: str environ: rel_path: str Returns ------- DataFrame """ folder = get_algo_folder(algo_name, environ) ...
The de-serialized DataFrame of an algo name and key. Parameters ---------- algo_name: str key: str environ: rel_path: str Returns ------- DataFrame
get_algo_df
python
scrtlabs/catalyst
catalyst/exchange/utils/exchange_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/exchange_utils.py
Apache-2.0
def save_algo_df(algo_name, key, df, environ=None, rel_path=None): """ Serialize to csv and save a DataFrame by algo name and key. Parameters ---------- algo_name: str key: str df: pd.DataFrame environ: rel_path: str """ folder = get_algo_folder(algo_name, environ) if r...
Serialize to csv and save a DataFrame by algo name and key. Parameters ---------- algo_name: str key: str df: pd.DataFrame environ: rel_path: str
save_algo_df
python
scrtlabs/catalyst
catalyst/exchange/utils/exchange_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/exchange_utils.py
Apache-2.0
def clear_frame_stats_directory(algo_name): """ remove the outdated directory to avoid overloading the disk Parameters ---------- algo_name: str Returns ------- error: str """ error = None algo_folder = get_algo_folder(algo_name) folder = os.path.join(algo_folder, ...
remove the outdated directory to avoid overloading the disk Parameters ---------- algo_name: str Returns ------- error: str
clear_frame_stats_directory
python
scrtlabs/catalyst
catalyst/exchange/utils/exchange_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/exchange_utils.py
Apache-2.0
def remove_old_files(algo_name, today, rel_path, environ=None): """ remove old files from a directory to avoid overloading the disk Parameters ---------- algo_name: str today: Timestamp rel_path: str environ: Returns ------- error: str """ error = None alg...
remove old files from a directory to avoid overloading the disk Parameters ---------- algo_name: str today: Timestamp rel_path: str environ: Returns ------- error: str
remove_old_files
python
scrtlabs/catalyst
catalyst/exchange/utils/exchange_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/exchange_utils.py
Apache-2.0
def get_exchange_minute_writer_root(exchange_name): """ The minute writer folder for the exchange. Parameters ---------- exchange_name: str Returns ------- BcolzExchangeBarWriter """ exchange_folder = get_exchange_folder(exchange_name) minute_data_folder = os.path.join(ex...
The minute writer folder for the exchange. Parameters ---------- exchange_name: str Returns ------- BcolzExchangeBarWriter
get_exchange_minute_writer_root
python
scrtlabs/catalyst
catalyst/exchange/utils/exchange_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/exchange_utils.py
Apache-2.0
def get_exchange_bundles_folder(exchange_name): """ The temp folder for bundle downloads by algo name. Parameters ---------- exchange_name: str Returns ------- str """ exchange_folder = get_exchange_folder(exchange_name) temp_bundles = os.path.join(exchange_folder, 'temp_...
The temp folder for bundle downloads by algo name. Parameters ---------- exchange_name: str Returns ------- str
get_exchange_bundles_folder
python
scrtlabs/catalyst
catalyst/exchange/utils/exchange_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/exchange_utils.py
Apache-2.0
def symbols_serial(obj): """ JSON serializer for objects not serializable by default json code Parameters ---------- obj: Object Returns ------- str """ if isinstance(obj, (datetime, date)): return obj.floor('1D').strftime(DATE_FORMAT) raise TypeError("Type %s not...
JSON serializer for objects not serializable by default json code Parameters ---------- obj: Object Returns ------- str
symbols_serial
python
scrtlabs/catalyst
catalyst/exchange/utils/exchange_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/exchange_utils.py
Apache-2.0
def get_common_assets(exchanges): """ The assets available in all specified exchanges. Parameters ---------- exchanges: list[Exchange] Returns ------- list[TradingPair] """ symbols = [] for exchange_name in exchanges: s = [asset.symbol for asset in exchanges[exchan...
The assets available in all specified exchanges. Parameters ---------- exchanges: list[Exchange] Returns ------- list[TradingPair]
get_common_assets
python
scrtlabs/catalyst
catalyst/exchange/utils/exchange_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/exchange_utils.py
Apache-2.0
def resample_history_df(df, freq, field, start_dt=None): """ Resample the OHCLV DataFrame using the specified frequency. Parameters ---------- df: DataFrame freq: str field: str Returns ------- DataFrame """ if field == 'open': agg = 'first' elif field == '...
Resample the OHCLV DataFrame using the specified frequency. Parameters ---------- df: DataFrame freq: str field: str Returns ------- DataFrame
resample_history_df
python
scrtlabs/catalyst
catalyst/exchange/utils/exchange_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/exchange_utils.py
Apache-2.0
def mixin_market_params(exchange_name, params, market): """ Applies a CCXT market dict to parameters of TradingPair init. Parameters ---------- params: dict[Object] market: dict[Object] Returns ------- """ # TODO: make this more externalized / configurable if 'lot' in mark...
Applies a CCXT market dict to parameters of TradingPair init. Parameters ---------- params: dict[Object] market: dict[Object] Returns -------
mixin_market_params
python
scrtlabs/catalyst
catalyst/exchange/utils/exchange_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/exchange_utils.py
Apache-2.0
def find_exchanges(features=None, skip_blacklist=True, is_authenticated=False, quote_currency=None): """ Find exchanges filtered by a list of feature. Parameters ---------- features: str The list of features. skip_blacklist: bool is_authenticated: bool quote_...
Find exchanges filtered by a list of feature. Parameters ---------- features: str The list of features. skip_blacklist: bool is_authenticated: bool quote_currency: bool Returns ------- list[Exchange]
find_exchanges
python
scrtlabs/catalyst
catalyst/exchange/utils/factory.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/factory.py
Apache-2.0
def format_ax(ax): """ Trying to assign reasonable parameters to the time axis. Parameters ---------- ax: """ # TODO: room for improvement ax.xaxis.set_major_locator(mdates.DayLocator(interval=1)) ax.xaxis.set_major_formatter(fmt) locator = mdates.HourLocator(interval=4) l...
Trying to assign reasonable parameters to the time axis. Parameters ---------- ax:
format_ax
python
scrtlabs/catalyst
catalyst/exchange/utils/live_chart_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/live_chart_utils.py
Apache-2.0
def draw_custom_signals(ax, df): """ Draw custom signals on the chart. """ colors = ['blue', 'green', 'red', 'black', 'orange', 'yellow', 'pink'] ax.clear() ax.set_title('Custom Signals') for index, column in enumerate(df.columns.values.tolist()): ax.plot(df.index, df[column], '-',...
Draw custom signals on the chart.
draw_custom_signals
python
scrtlabs/catalyst
catalyst/exchange/utils/live_chart_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/live_chart_utils.py
Apache-2.0
def draw_exposure(ax, df, context): """ Draw exposure line on the chart. """ # TODO: list exchanges in graph quote_currency = None positions = [] for exchange_name in context.exchanges: exchange = context.exchanges[exchange_name] if not quote_currency: quote_cur...
Draw exposure line on the chart.
draw_exposure
python
scrtlabs/catalyst
catalyst/exchange/utils/live_chart_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/live_chart_utils.py
Apache-2.0
def crossover(source, target): """ The `x`-series is defined as having crossed over `y`-series if the value of `x` is greater than the value of `y` and the value of `x` was less than the value of `y` on the bar immediately preceding the current bar. Parameters ---------- source: Series ...
The `x`-series is defined as having crossed over `y`-series if the value of `x` is greater than the value of `y` and the value of `x` was less than the value of `y` on the bar immediately preceding the current bar. Parameters ---------- source: Series target: Series Returns ------...
crossover
python
scrtlabs/catalyst
catalyst/exchange/utils/stats_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/stats_utils.py
Apache-2.0
def crossunder(source, target): """ The `x`-series is defined as having crossed under `y`-series if the value of `x` is less than the value of `y` and the value of `x` was greater than the value of `y` on the bar immediately preceding the current bar. Parameters ---------- source: Series ...
The `x`-series is defined as having crossed under `y`-series if the value of `x` is less than the value of `y` and the value of `x` was greater than the value of `y` on the bar immediately preceding the current bar. Parameters ---------- source: Series target: Series Returns -----...
crossunder
python
scrtlabs/catalyst
catalyst/exchange/utils/stats_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/stats_utils.py
Apache-2.0
def vwap(df): """ Volume-weighted average price (VWAP) is a ratio generally used by institutional investors and mutual funds to make buys and sells so as not to disturb the market prices with large orders. It is the average share price of a stock weighted against its trading volume within a particul...
Volume-weighted average price (VWAP) is a ratio generally used by institutional investors and mutual funds to make buys and sells so as not to disturb the market prices with large orders. It is the average share price of a stock weighted against its trading volume within a particular time frame, ge...
vwap
python
scrtlabs/catalyst
catalyst/exchange/utils/stats_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/stats_utils.py
Apache-2.0
def set_position_row(row, asset, asset_values=list()): """ Apply the position data as individual columns. Parameters ---------- row: dict[str, Object] asset: TradingPair asset_values: list[str] If a recorded_col contains a tuple which first value is an asset matching a posit...
Apply the position data as individual columns. Parameters ---------- row: dict[str, Object] asset: TradingPair asset_values: list[str] If a recorded_col contains a tuple which first value is an asset matching a position, its value will be displayed with the position and...
set_position_row
python
scrtlabs/catalyst
catalyst/exchange/utils/stats_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/stats_utils.py
Apache-2.0
def prepare_stats(stats, recorded_cols=list()): """ Prepare the stats DataFrame for user-friendly output. Parameters ---------- stats: list[Object] recorded_cols: list[str] Returns ------- """ asset_cols = list() stats = copy.deepcopy(stats) # Using a copy since we ar...
Prepare the stats DataFrame for user-friendly output. Parameters ---------- stats: list[Object] recorded_cols: list[str] Returns -------
prepare_stats
python
scrtlabs/catalyst
catalyst/exchange/utils/stats_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/stats_utils.py
Apache-2.0
def get_pretty_stats(stats, recorded_cols=None, num_rows=10, show_tail=True): """ Format and print the last few rows of a statistics DataFrame. See the pyfolio project for the data structure. Parameters ---------- stats: list[Object] An array of statistics for the period. num_rows:...
Format and print the last few rows of a statistics DataFrame. See the pyfolio project for the data structure. Parameters ---------- stats: list[Object] An array of statistics for the period. num_rows: int The number of rows to display on the screen. Returns ------- ...
get_pretty_stats
python
scrtlabs/catalyst
catalyst/exchange/utils/stats_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/stats_utils.py
Apache-2.0
def get_csv_stats(stats, recorded_cols=None): """ Create a CSV buffer from the stats DataFrame. Parameters ---------- path: str stats: list[Object] recorded_cols: list[str] Returns ------- """ df, columns = prepare_stats(stats, recorded_cols=recorded_cols) return df.t...
Create a CSV buffer from the stats DataFrame. Parameters ---------- path: str stats: list[Object] recorded_cols: list[str] Returns -------
get_csv_stats
python
scrtlabs/catalyst
catalyst/exchange/utils/stats_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/stats_utils.py
Apache-2.0
def stats_to_s3(uri, stats, algo_namespace, recorded_cols=None, folder='catalyst/stats', bytes_to_write=None): """ Uploads the performance stats to a S3 bucket. Parameters ---------- uri: str stats: list[Object] algo_namespace: str recorded_cols: list[str] folder: st...
Uploads the performance stats to a S3 bucket. Parameters ---------- uri: str stats: list[Object] algo_namespace: str recorded_cols: list[str] folder: str bytes_to_write: str Option to reuse bytes instead of re-computing the csv Returns -------
stats_to_s3
python
scrtlabs/catalyst
catalyst/exchange/utils/stats_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/stats_utils.py
Apache-2.0
def stats_to_algo_folder(stats, algo_namespace, folder_name, recorded_cols=None): """ Saves the performance stats to the algo local folder. Parameters ---------- stats: list[Object] algo_namespace: str folder_name: str recorded_cols: list[str] Returns -...
Saves the performance stats to the algo local folder. Parameters ---------- stats: list[Object] algo_namespace: str folder_name: str recorded_cols: list[str] Returns ------- str
stats_to_algo_folder
python
scrtlabs/catalyst
catalyst/exchange/utils/stats_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/stats_utils.py
Apache-2.0
def df_to_string(df): """ Create a formatted str representation of the DataFrame. Parameters ---------- df: DataFrame Returns ------- str """ pd.set_option('display.expand_frame_repr', False) pd.set_option('precision', 8) pd.set_option('display.width', 1000) pd.set...
Create a formatted str representation of the DataFrame. Parameters ---------- df: DataFrame Returns ------- str
df_to_string
python
scrtlabs/catalyst
catalyst/exchange/utils/stats_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/stats_utils.py
Apache-2.0
def extract_transactions(perf): """ Compute indexes for buy and sell transactions Parameters ---------- perf: DataFrame The algo performance DataFrame. Returns ------- DataFrame A DataFrame of transactions. """ trans_list = perf.transactions.values all_tran...
Compute indexes for buy and sell transactions Parameters ---------- perf: DataFrame The algo performance DataFrame. Returns ------- DataFrame A DataFrame of transactions.
extract_transactions
python
scrtlabs/catalyst
catalyst/exchange/utils/stats_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/stats_utils.py
Apache-2.0
def output_df(df, assets, name=None): """ Outputs a price DataFrame to a temp folder. Parameters ---------- df: pd.DataFrame assets name Returns ------- """ if isinstance(assets, TradingPair): asset_folder = '{}_{}'.format(assets.exchange, assets.symbol) else: ...
Outputs a price DataFrame to a temp folder. Parameters ---------- df: pd.DataFrame assets name Returns -------
output_df
python
scrtlabs/catalyst
catalyst/exchange/utils/test_utils.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/exchange/utils/test_utils.py
Apache-2.0
def get_transactions(self, bar_data): """ Creates a list of transactions based on the current open orders, slippage model, and commission model. Parameters ---------- bar_data: catalyst._protocol.BarData Notes ----- This method book-keeps the blo...
Creates a list of transactions based on the current open orders, slippage model, and commission model. Parameters ---------- bar_data: catalyst._protocol.BarData Notes ----- This method book-keeps the blotter's open_orders dictionary, so that i...
get_transactions
python
scrtlabs/catalyst
catalyst/finance/blotter.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/finance/blotter.py
Apache-2.0
def asymmetric_round_price_to_penny(price, prefer_round_down, diff=(0.0095 - .005)): """ Modified the original function because we do not want to round prices on crypto exchange. Parameters ---------- price: float Returns ------- float """ ...
Modified the original function because we do not want to round prices on crypto exchange. Parameters ---------- price: float Returns ------- float
asymmetric_round_price_to_penny
python
scrtlabs/catalyst
catalyst/finance/execution.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/finance/execution.py
Apache-2.0
def get_simulated_impact(self, order, current_price, current_volume, txn_volume, mean_volume, volatility): """ Calculate simulated...
Calculate simulated price impact. Parameters ---------- order : The order being processed. current_price : Current price of the asset being ordered. current_volume : Volume of the asset being ordered for the current bar. txn_volume : Number of shares/contracts b...
get_simulated_impact
python
scrtlabs/catalyst
catalyst/finance/slippage.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/finance/slippage.py
Apache-2.0
def __init__(self, asset, amount, dt, price, order_id, commission=None, fee_currency=None, is_quote_live=False): """ :param asset: :param amount: :param dt: :param price: :param order_id: :param commission: :param fee_currency: str; from ...
:param asset: :param amount: :param dt: :param price: :param order_id: :param commission: :param fee_currency: str; from what currency is the commission reduced from- only on live mode :param is_quote_live: bool; is th...
__init__
python
scrtlabs/catalyst
catalyst/finance/transaction.py
https://github.com/scrtlabs/catalyst/blob/master/catalyst/finance/transaction.py
Apache-2.0