mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-08 13:02:03 +08:00
BLD: live mode accepts end parameter, when algo finishes
This commit is contained in:
@@ -394,6 +394,12 @@ def catalyst_magic(line, cell=None):
|
||||
help='The base currency used to calculate statistics '
|
||||
'(e.g. usd, btc, eth).',
|
||||
)
|
||||
@click.option(
|
||||
'-e',
|
||||
'--end',
|
||||
type=Date(tz='utc', as_timestamp=True),
|
||||
help='An optional end date at which to stop the execution.',
|
||||
)
|
||||
@click.option(
|
||||
'--live-graph/--no-live-graph',
|
||||
is_flag=True,
|
||||
@@ -419,6 +425,7 @@ def live(ctx,
|
||||
exchange_name,
|
||||
algo_namespace,
|
||||
base_currency,
|
||||
end,
|
||||
live_graph,
|
||||
simulate_orders):
|
||||
"""Trade live with the given algorithm.
|
||||
@@ -461,7 +468,7 @@ def live(ctx,
|
||||
bundle=None,
|
||||
bundle_timestamp=None,
|
||||
start=None,
|
||||
end=None,
|
||||
end=end,
|
||||
output=output,
|
||||
print_algo=print_algo,
|
||||
local_namespace=local_namespace,
|
||||
|
||||
@@ -351,6 +351,7 @@ class ExchangeTradingAlgorithmLive(ExchangeTradingAlgorithmBase):
|
||||
self.live_graph = kwargs.pop('live_graph', None)
|
||||
self.stats_output = kwargs.pop('stats_output', None)
|
||||
self._analyze_live = kwargs.pop('analyze_live', None)
|
||||
self.end = kwargs.pop('end', None)
|
||||
|
||||
self._clock = None
|
||||
self.frame_stats = list()
|
||||
@@ -710,6 +711,10 @@ class ExchangeTradingAlgorithmLive(ExchangeTradingAlgorithmBase):
|
||||
if not self.is_running:
|
||||
return
|
||||
|
||||
if self.end is not None and self.end < data.current_dt:
|
||||
log.info('Algorithm has reached specified end time. Finishing...')
|
||||
self.interrupt_algorithm()
|
||||
|
||||
# Resetting the frame stats every day to minimize memory footprint
|
||||
today = data.current_dt.floor('1D')
|
||||
if self.current_day is not None and today > self.current_day:
|
||||
|
||||
@@ -206,7 +206,8 @@ def _run(handle_data,
|
||||
start = pd.Timestamp.utcnow()
|
||||
|
||||
# TODO: fix the end data.
|
||||
end = start + timedelta(hours=8760)
|
||||
if end is None:
|
||||
end = start + timedelta(hours=8760)
|
||||
|
||||
data = DataPortalExchangeLive(
|
||||
exchanges=exchanges,
|
||||
@@ -234,6 +235,7 @@ def _run(handle_data,
|
||||
simulate_orders=simulate_orders,
|
||||
stats_output=stats_output,
|
||||
analyze_live=analyze_live,
|
||||
end=end,
|
||||
)
|
||||
elif exchanges:
|
||||
# Removed the existing Poloniex fork to keep things simple
|
||||
|
||||
Reference in New Issue
Block a user