BLD: implemented issue #79, using the capital_base parameter to override the amount of base currency available for trading

This commit is contained in:
fredfortier
2017-11-22 16:03:21 -05:00
parent 3ec9853b75
commit 841acf0203
2 changed files with 27 additions and 8 deletions
+3 -2
View File
@@ -177,7 +177,7 @@ def ipython_only(option):
default='-',
metavar='FILENAME',
show_default=True,
help="The location to write the perf data. If this is '-' the perf"
help="The location to write the perf data. If this is '-' the perf"
" will be written to stdout.",
)
@click.option(
@@ -549,9 +549,10 @@ def ingest_exchange(exchange_name, data_frequency, start, end,
@click.pass_context
def clean_algo(ctx, algo_namespace):
click.echo(
'Deleting the state folder of algo: {}...'.format(algo_namespace)
'Cleaning algo state: {}'.format(algo_namespace)
)
delete_algo_folder(algo_namespace)
click.echo('Done')
@main.command(name='clean-exchange')
+24 -6
View File
@@ -170,8 +170,8 @@ def _run(handle_data,
# This corresponds to the json file containing api token info
exchange_auth = get_exchange_auth(exchange_name)
if live and (
exchange_auth['key'] == '' or exchange_auth['secret'] == ''):
if live and (exchange_auth['key'] == '' \
or exchange_auth['secret'] == ''):
raise ExchangeAuthEmpty(
exchange=exchange_name.title(),
filename=os.path.join(
@@ -263,17 +263,35 @@ def _run(handle_data,
)
if base_currency in balances:
return balances[base_currency]
base_currency_available = balances[base_currency]
log.info(
'base currency available in the account: {} {}'.format(
base_currency_available, base_currency
)
)
if capital_base is not None \
and capital_base < base_currency_available:
log.info(
'using capital base limit: {} {}'.format(
capital_base, base_currency
)
)
amount = capital_base
else:
amount = base_currency_available
return amount
else:
raise BaseCurrencyNotFoundError(
base_currency=base_currency,
exchange=exchange_name
)
capital_base = 0
combined_capital_base = 0
for exchange_name in exchanges:
exchange = exchanges[exchange_name]
capital_base += fetch_capital_base(exchange)
combined_capital_base += fetch_capital_base(exchange)
sim_params = create_simulation_parameters(
start=start,
@@ -338,7 +356,7 @@ def _run(handle_data,
raise ValueError(
"invalid url %r, must begin with 'sqlite:///'" %
str(bundle_data.asset_finder.engine.url),
)
)
env = TradingEnvironment(asset_db_path=connstr, environ=environ)
first_trading_day = \