mirror of
https://github.com/wassname/catalyst.git
synced 2026-06-27 16:29:48 +08:00
This commit is contained in:
@@ -13,7 +13,6 @@ from catalyst.exchange.exchange_errors import MismatchingBaseCurrencies, \
|
||||
PricingDataNotLoadedError, \
|
||||
NoDataAvailableOnExchange, NoValueForField, \
|
||||
NoCandlesReceivedFromExchange, \
|
||||
InvalidHistoryFrequencyAlias, \
|
||||
TickerNotFoundError, NotEnoughCashError
|
||||
from catalyst.exchange.utils.datetime_utils import get_delta, \
|
||||
get_periods_range, \
|
||||
@@ -612,7 +611,7 @@ class Exchange:
|
||||
# TODO: this function needs some work,
|
||||
# we're currently using it just for benchmark data
|
||||
freq, candle_size, unit, data_frequency = get_frequency(
|
||||
frequency, data_frequency
|
||||
frequency, data_frequency, supported_freqs=['T', 'D']
|
||||
)
|
||||
adj_bar_count = candle_size * bar_count
|
||||
try:
|
||||
|
||||
@@ -296,7 +296,7 @@ class DataPortalExchangeBacktest(DataPortalExchangeBase):
|
||||
bundle = self.exchange_bundles[exchange_name] # type: ExchangeBundle
|
||||
|
||||
freq, candle_size, unit, adj_data_frequency = get_frequency(
|
||||
frequency, data_frequency
|
||||
frequency, data_frequency, supported_freqs=['T', 'D']
|
||||
)
|
||||
adj_bar_count = candle_size * bar_count
|
||||
|
||||
|
||||
@@ -309,15 +309,14 @@ def get_frequency(freq, data_frequency=None, supported_freqs=['D', 'H', 'T']):
|
||||
data_frequency = 'minute'
|
||||
|
||||
elif unit.lower() == 'h':
|
||||
data_frequency = 'minute'
|
||||
|
||||
if 'H' in supported_freqs:
|
||||
unit = 'H'
|
||||
alias = '{}H'.format(candle_size)
|
||||
data_frequency = 'hourly'
|
||||
|
||||
else:
|
||||
candle_size = candle_size * 60
|
||||
alias = '{}T'.format(candle_size)
|
||||
data_frequency = 'minute'
|
||||
|
||||
else:
|
||||
raise InvalidHistoryFrequencyAlias(freq=freq)
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import pytz
|
||||
from datetime import datetime
|
||||
from catalyst.api import symbol
|
||||
from catalyst.utils.run_algo import run_algorithm
|
||||
|
||||
coin = 'btc'
|
||||
base_currency = 'usd'
|
||||
n_candles = 5
|
||||
|
||||
|
||||
def initialize(context):
|
||||
context.symbol = symbol('%s_%s' % (coin, base_currency))
|
||||
|
||||
|
||||
def handle_data_polo_partial_candles(context, data):
|
||||
history = data.history(symbol('btc_usdt'), ['volume'],
|
||||
bar_count=10,
|
||||
frequency='4H')
|
||||
print('\nnow: %s\n%s' % (data.current_dt, history))
|
||||
if not hasattr(context, 'i'):
|
||||
context.i = 0
|
||||
context.i += 1
|
||||
if context.i > 5:
|
||||
raise Exception('stop')
|
||||
|
||||
|
||||
live = False
|
||||
|
||||
if live:
|
||||
run_algorithm(initialize=lambda ctx: True,
|
||||
handle_data=handle_data_polo_partial_candles,
|
||||
exchange_name='poloniex',
|
||||
base_currency='usdt',
|
||||
algo_namespace='ns',
|
||||
live=True,
|
||||
data_frequency='minute',
|
||||
capital_base=3000)
|
||||
else:
|
||||
run_algorithm(initialize=lambda ctx: True,
|
||||
handle_data=handle_data_polo_partial_candles,
|
||||
exchange_name='poloniex',
|
||||
base_currency='usdt',
|
||||
algo_namespace='ns',
|
||||
live=False,
|
||||
data_frequency='minute',
|
||||
capital_base=3000,
|
||||
start=datetime(2018, 2, 2, 0, 0, 0, 0, pytz.utc),
|
||||
end=datetime(2018, 2, 20, 0, 0, 0, 0, pytz.utc)
|
||||
)
|
||||
Reference in New Issue
Block a user