Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
lenak25 committed Nov 11, 2018
2 parents 90d9e4e + 141fdf9 commit e96ebe6
Show file tree
Hide file tree
Showing 18 changed files with 162 additions and 113 deletions.
10 changes: 0 additions & 10 deletions catalyst/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,15 +587,6 @@ def live(ctx,
show_default=True,
help='an E-mail address to send the results to',
)
@click.option(
'-o',
'--output',
default='-',
metavar='FILENAME',
show_default=True,
help="The location to write the perf data. If this is '-' the perf"
" will be written to stdout.",
)
@click.option(
'--print-algo/--no-print-algo',
is_flag=True,
Expand Down Expand Up @@ -636,7 +627,6 @@ def remote_run(ctx,
start,
end,
mail,
output,
print_algo,
local_namespace,
exchange_name,
Expand Down
31 changes: 14 additions & 17 deletions catalyst/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1432,7 +1432,7 @@ def order(self,
limit_price : float, optional
The limit price for the order.
stop_price : float, optional
The stop price for the order.
Not supported.
style : ExecutionStyle, optional
The execution style for the order.
Expand All @@ -1444,13 +1444,10 @@ def order(self,
Notes
-----
The ``limit_price`` and ``stop_price`` arguments provide shorthands for
The ``limit_price`` argument provide shorthands for
passing common execution styles. Passing ``limit_price=N`` is
equivalent to ``style=LimitOrder(N)``. Similarly, passing
``stop_price=M`` is equivalent to ``style=StopOrder(M)``, and passing
``limit_price=N`` and ``stop_price=M`` is equivalent to
``style=StopLimitOrder(N, M)``. It is an error to pass both a ``style``
and ``limit_price`` or ``stop_price``.
equivalent to ``style=LimitOrder(N)``. It is an error to pass both
a ``style`` and ``limit_price``.
Currently, orders must be done only with one ``quote_currency``
throughout all the algorithm.
Expand Down Expand Up @@ -1574,7 +1571,7 @@ def order_value(self,
limit_price : float, optional
The limit price for the order.
stop_price : float, optional
The stop price for the order.
Not supported.
style : ExecutionStyle
The execution style for the order.
Expand All @@ -1586,7 +1583,7 @@ def order_value(self,
Notes
-----
See :func:`catalyst.api.order` for more information about
``limit_price``, ``stop_price``, and ``style``
``limit_price``, and ``style``
See Also
--------
Expand Down Expand Up @@ -1820,7 +1817,7 @@ def order_percent(self,
limit_price : float, optional
The limit price for the order.
stop_price : float, optional
The stop price for the order.
Not supported.
style : ExecutionStyle
The execution style for the order.
Expand All @@ -1832,7 +1829,7 @@ def order_percent(self,
Notes
-----
See :func:`catalyst.api.order` for more information about
``limit_price``, ``stop_price``, and ``style``
``limit_price``, and ``style``
See Also
--------
Expand Down Expand Up @@ -1876,7 +1873,7 @@ def order_target(self,
limit_price : float, optional
The limit price for the order.
stop_price : float, optional
The stop price for the order.
Not supported.
style : ExecutionStyle
The execution style for the order.
Expand All @@ -1891,7 +1888,7 @@ def order_target(self,
``order_target`` takes into account open orders as well.
See :func:`catalyst.api.order` for more information about
``limit_price``, ``stop_price``, and ``style``
``limit_price``, and ``style``
See Also
--------
Expand Down Expand Up @@ -1939,7 +1936,7 @@ def order_target_value(self,
limit_price : float, optional
The limit price for the order.
stop_price : float, optional
The stop price for the order.
Not supported.
style : ExecutionStyle
The execution style for the order.
Expand All @@ -1952,7 +1949,7 @@ def order_target_value(self,
-----
See :func:`catalyst.api.order` for more information about
``limit_price``, ``stop_price``, and ``style``
``limit_price`` and ``style``
See Also
--------
Expand Down Expand Up @@ -1992,7 +1989,7 @@ def order_target_percent(self, asset, target,
limit_price : float, optional
The limit price for the order.
stop_price : float, optional
The stop price for the order.
Not supported
style : ExecutionStyle
The execution style for the order.
Expand All @@ -2005,7 +2002,7 @@ def order_target_percent(self, asset, target,
-----
See :func:`catalyst.api.order` for more information about
``limit_price``, ``stop_price``, and ``style``
``limit_price`` and ``style``
See Also
--------
Expand Down
2 changes: 2 additions & 0 deletions catalyst/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
SUPPORTED_WALLETS = ['metamask', 'ledger', 'trezor', 'bitbox', 'keystore',
'key']

DISABLE_ALPHA_WARNING = bool(os.environ.get('CATALYST_DISABLE_ALPHA_WARNING'))

ALPHA_WARNING_MESSAGE = 'Catalyst is currently in ALPHA. It is going ' \
'through rapid development and it is subject to ' \
'errors. Please use carefully. We encourage you to ' \
Expand Down
3 changes: 2 additions & 1 deletion catalyst/exchange/exchange_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1163,13 +1163,14 @@ def _get_orderbook(self, asset, order_type='all', limit=None):
def get_orderbook(self, asset, order_type='all', limit=None):
"""
Retrieve the orderbook for the given trading pair.
This function is supported only in live and paper trading modes.
Parameters
----------
asset: TradingPair
order_type: str
The type of orders: bid, ask or all
The type of the orders: 'bids' or 'asks' or 'all'
limit: int
Expand Down
48 changes: 22 additions & 26 deletions catalyst/exchange/utils/exchange_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from catalyst.exchange.exchange_errors import ExchangeSymbolsNotFound
from catalyst.exchange.utils.serialization_utils import ExchangeJSONEncoder, \
ExchangeJSONDecoder
from catalyst.utils.memoize import weak_lru_cache
from catalyst.utils.paths import data_root, ensure_directory, \
last_modified_time

Expand Down Expand Up @@ -61,57 +62,54 @@ def get_remote_folder(environ=None):
return remote_folder


def get_exchange_folder(exchange_name, environ=None):
@weak_lru_cache()
def get_exchange_folder(exchange_name):
"""
The root path of an exchange folder.
Parameters
----------
exchange_name: str
environ:
Returns
-------
str
"""
if not environ:
environ = os.environ

root = data_root(environ)
root = data_root()
exchange_folder = os.path.join(root, 'exchanges', exchange_name)
ensure_directory(exchange_folder)

return exchange_folder


def is_blacklist(exchange_name, environ=None):
exchange_folder = get_exchange_folder(exchange_name, environ)
def is_blacklist(exchange_name):
exchange_folder = get_exchange_folder(exchange_name)
filename = os.path.join(exchange_folder, 'blacklist.txt')

return os.path.exists(filename)


def get_exchange_symbols_filename(exchange_name, is_local=False, environ=None):
def get_exchange_symbols_filename(exchange_name, is_local=False):
"""
The absolute path of the exchange's symbol.json file.
Parameters
----------
exchange_name:
environ:
Returns
-------
str
"""
name = 'symbols.json' if not is_local else 'symbols_local.json'
exchange_folder = get_exchange_folder(exchange_name, environ)
exchange_folder = get_exchange_folder(exchange_name)
return os.path.join(exchange_folder, name)


def download_exchange_symbols(exchange_name, environ=None):
def download_exchange_symbols(exchange_name):
"""
Downloads the exchange's symbols.json from the repository.
Expand All @@ -131,7 +129,7 @@ def download_exchange_symbols(exchange_name, environ=None):
return response


def get_exchange_symbols(exchange_name, is_local=False, environ=None):
def get_exchange_symbols(exchange_name, is_local=False):
"""
The de-serialized content of the exchange's symbols.json.
Expand All @@ -152,7 +150,7 @@ def get_exchange_symbols(exchange_name, is_local=False, environ=None):
pd.Timestamp('now', tz='UTC') - last_modified_time(
filename)).days > 1):
try:
download_exchange_symbols(exchange_name, environ)
download_exchange_symbols(exchange_name)
except Exception:
pass

Expand All @@ -171,7 +169,7 @@ def get_exchange_symbols(exchange_name, is_local=False, environ=None):
)


def save_exchange_symbols(exchange_name, assets, is_local=False, environ=None):
def save_exchange_symbols(exchange_name, assets, is_local=False):
"""
Save assets into an exchange_symbols file.
Expand All @@ -191,7 +189,7 @@ def save_exchange_symbols(exchange_name, assets, is_local=False, environ=None):
asset_dicts[symbol] = assets[symbol].to_dict()

filename = get_exchange_symbols_filename(
exchange_name, is_local, environ
exchange_name, is_local
)
with open(filename, 'wt') as handle:
json.dump(asset_dicts, handle, indent=4, default=symbols_serial)
Expand All @@ -214,21 +212,21 @@ def get_symbols_string(assets):
return ', '.join([asset.symbol for asset in array])


def get_exchange_auth(exchange_name, alias=None, environ=None):
def get_exchange_auth(exchange_name, alias=None):
"""
The de-serialized contend of the exchange's auth.json file.
Parameters
----------
exchange_name: str
environ:
alias:
Returns
-------
Object
"""
exchange_folder = get_exchange_folder(exchange_name, environ)
exchange_folder = get_exchange_folder(exchange_name)
name = 'auth' if alias is None else alias
filename = os.path.join(exchange_folder, '{}.json'.format(name))

Expand Down Expand Up @@ -511,52 +509,50 @@ def remove_old_files(algo_name, today, rel_path, environ=None):
return error


def get_exchange_minute_writer_root(exchange_name, environ=None):
def get_exchange_minute_writer_root(exchange_name):
"""
The minute writer folder for the exchange.
Parameters
----------
exchange_name: str
environ:
Returns
-------
BcolzExchangeBarWriter
"""
exchange_folder = get_exchange_folder(exchange_name, environ)
exchange_folder = get_exchange_folder(exchange_name)

minute_data_folder = os.path.join(exchange_folder, 'minute_data')
ensure_directory(minute_data_folder)

return minute_data_folder


def get_exchange_bundles_folder(exchange_name, environ=None):
def get_exchange_bundles_folder(exchange_name):
"""
The temp folder for bundle downloads by algo name.
Parameters
----------
exchange_name: str
environ:
Returns
-------
str
"""
exchange_folder = get_exchange_folder(exchange_name, environ)
exchange_folder = get_exchange_folder(exchange_name)

temp_bundles = os.path.join(exchange_folder, 'temp_bundles')
ensure_directory(temp_bundles)

return temp_bundles


def has_bundle(exchange_name, data_frequency, environ=None):
exchange_folder = get_exchange_folder(exchange_name, environ)
def has_bundle(exchange_name, data_frequency):
exchange_folder = get_exchange_folder(exchange_name)

folder_name = '{}_bundle'.format(data_frequency.lower())
folder = os.path.join(exchange_folder, folder_name)
Expand Down
4 changes: 2 additions & 2 deletions catalyst/utils/paths.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Canonical path locations for catalyst data.
Paths are rooted at $ZIPLINE_ROOT if that environment variable is set.
Paths are rooted at $CATALYST_ROOT if that environment variable is set.
Otherwise default to expanduser(~/.catalyst)
"""
from errno import EEXIST
Expand Down Expand Up @@ -124,7 +124,7 @@ def catalyst_root(environ=None):
if environ is None:
environ = os.environ

root = environ.get('ZIPLINE_ROOT', None)
root = environ.get('CATALYST_ROOT', None)
if root is None:
root = os.path.join(expanduser('~'), '.catalyst')

Expand Down
8 changes: 6 additions & 2 deletions catalyst/utils/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,19 @@ def get_remote_status(algo_id):
raise Exception("the id you entered is invalid! "
"please enter a valid id.")
json_file = {'algo_id': algo_id}
log.info("retrieving the status of {} algorithm".format(algo_id))
response = send_digest_request(
json_file=json_file, path=STATUS_PATH, method=GET
)
return handle_response(response, STATUS)


def send_digest_request(json_file, path, method):
key, secret = retrieve_remote_auth()
try:
key, secret = retrieve_remote_auth()
except json.JSONDecodeError as e:
log.error("your key and secret aren't stored properly\n{}".
format(e.msg))
raise
json_file['key'] = key
session = requests.Session()
if method == POST:
Expand Down
Loading

0 comments on commit e96ebe6

Please sign in to comment.