mirror of
https://github.com/wassname/catalyst.git
synced 2026-08-08 11:16:58 +08:00
First version which runs end-to-end.
This commit is contained in:
@@ -66,8 +66,6 @@ def handle_data(context, data):
|
||||
)
|
||||
|
||||
|
||||
start = datetime(2015, 3, 1, 0, 0, 0, 0, pytz.utc)
|
||||
end = datetime(2017, 6, 28, 0, 0, 0, 0, pytz.utc)
|
||||
exchange_conn = dict(
|
||||
name='bitfinex',
|
||||
key='',
|
||||
@@ -77,8 +75,6 @@ exchange_conn = dict(
|
||||
run_algorithm(
|
||||
initialize=initialize,
|
||||
handle_data=handle_data,
|
||||
start=start,
|
||||
end=end,
|
||||
capital_base=100000,
|
||||
exchange_conn=exchange_conn,
|
||||
live=True
|
||||
|
||||
@@ -292,7 +292,12 @@ class Bitfinex(Exchange):
|
||||
|
||||
def get_single_spot_value(self, asset, field, data_frequency):
|
||||
symbol = self._get_v2_symbol(asset)
|
||||
log.debug('fetching spot value for symbol {}'.format(symbol))
|
||||
log.debug(
|
||||
'fetching spot value {field} for symbol {symbol}'.format(
|
||||
symbol=symbol,
|
||||
field=field
|
||||
)
|
||||
)
|
||||
|
||||
if data_frequency == 'minute':
|
||||
frequency = '1m'
|
||||
@@ -378,6 +383,17 @@ class Bitfinex(Exchange):
|
||||
:func:`catalyst.api.order_value`
|
||||
:func:`catalyst.api.order_percent`
|
||||
"""
|
||||
log.debug(
|
||||
'ordering {amount} {symbol} {style}'.format(
|
||||
amount=amount,
|
||||
symbol=asset.symbol,
|
||||
style=style
|
||||
)
|
||||
)
|
||||
|
||||
if amount == 0:
|
||||
log.warn('skipping order amount of 0')
|
||||
return None
|
||||
|
||||
is_buy = (amount > 0)
|
||||
|
||||
@@ -400,7 +416,7 @@ class Bitfinex(Exchange):
|
||||
exchange_symbol = self.get_symbol(asset)
|
||||
req = dict(
|
||||
symbol=exchange_symbol,
|
||||
amount=str(float(amount)),
|
||||
amount=str(float(abs(amount))),
|
||||
price=str(float(price)),
|
||||
side='buy' if is_buy else 'sell',
|
||||
type='exchange ' + order_type, # TODO: support margin trades
|
||||
|
||||
@@ -131,6 +131,10 @@ def _run(handle_data,
|
||||
else:
|
||||
click.echo(algotext)
|
||||
|
||||
if exchange is not None:
|
||||
start = pd.Timestamp.utcnow()
|
||||
end = start + pd.Timedelta('365', 'D')
|
||||
|
||||
open_calendar = get_calendar('OPEN')
|
||||
if bundle is not None:
|
||||
bundles = bundle.split(',')
|
||||
@@ -233,17 +237,13 @@ def _run(handle_data,
|
||||
exchange=exchange,
|
||||
asset_finder=env.asset_finder,
|
||||
trading_calendar=open_calendar,
|
||||
first_trading_day=start
|
||||
first_trading_day=pd.to_datetime('today', utc=True)
|
||||
)
|
||||
choose_loader = None
|
||||
else:
|
||||
env = TradingEnvironment(environ=environ)
|
||||
choose_loader = None
|
||||
|
||||
if exchange:
|
||||
start = pd.Timestamp.utcnow()
|
||||
end = start + pd.Timedelta('1', 'D')
|
||||
|
||||
TradingAlgorithmClass = (
|
||||
partial(ExchangeTradingAlgorithm, exchange=exchange)
|
||||
if exchange else TradingAlgorithm)
|
||||
@@ -334,10 +334,10 @@ def load_extensions(default, extensions, strict, environ, reload=False):
|
||||
_loaded_extensions.add(ext)
|
||||
|
||||
|
||||
def run_algorithm(start,
|
||||
end,
|
||||
initialize,
|
||||
def run_algorithm(initialize,
|
||||
capital_base,
|
||||
start=None,
|
||||
end=None,
|
||||
handle_data=None,
|
||||
before_trading_start=None,
|
||||
analyze=None,
|
||||
|
||||
Reference in New Issue
Block a user