scrtlabs / catalyst

An Algorithmic Trading Library for Crypto-Assets in Python
http://enigma.co
Apache License 2.0
2.49k stars 725 forks source link

running algo with poloniex exchange fails with does not support candle frequency 1T error #247

Open vivekbasappa opened 6 years ago

vivekbasappa commented 6 years ago

Dear Catalyst Maintainers,

Before I tell you about my issue, let me describe my environment:

Environment

Now that you know a little about me, let me tell you about the issue I am having:

Description of Issue

my run algorithm call looks like this run_algorithm( capital_base=1000, data_frequency='minute', initialize=initialize, handle_data=handle_data, analyze=analyze, exchange_name='poloniex', algo_namespace=NAMESPACE, base_currency='usd', simulate_orders=True, live=True,)

 I am calling history call  to get 1 minute price data 
 prices = data.history(context.stocks,'price',context.N*390,'1m')

Here is how you can reproduce this issue on your machine:

  1. call history call with 1 minute price data in the algortim, it will fail with above error.
  2. I tried to debug catalyst code base. catalyst/sources/benchmark_source.py in _initialize_precalculated_series, values are hardcoded to 1m if self.emission_rate == "minute": minutes = trading_calendar.minutes_for_sessions_in_range( self.sessions[0], self.sessions[-1] ) benchmark_series = data_portal.get_history_window( [asset], minutes[-1], bar_count=len(minutes) + 1, frequency="1m", field="price", data_frequency=self.emission_rate, ffill=True )[asset]

but if exchange only supports 5m and 15m how do I change that in my code?

Reproduction Steps

  1. add history in the algorithm with 1m price data fetch call
  2. set exchange to poloniex
  3. run the algorithm ...

What steps have you taken to resolve this already?

...

Anything else?

...

Sincerely, `$ vivek

vivekbasappa commented 6 years ago

Here is my code ` def initialize(context): context.ASSET_NAME = 'btc_usdt' context.TARGET_HODL_RATIO = 0.8 context.RESERVE_RATIO = 1.0 - context.TARGET_HODL_RATIO

 # For all trading pairs in the poloniex bundle, the default denomination
 # currently supported by Catalyst is 1/1000th of a full coin. Use this
 # constant to scale the price of up to that of a full coin if desired.
 context.TICK_SIZE = 1000.0

 context.is_buying = True
 context.asset = symbol(context.ASSET_NAME)

 context.i = 0
 schedule_function(test_data, date_rules.every_day(), time_rules.every_minute())

def test_data(context, data): context.i += 1

 prices = data.history(context.asset, 'price',390,'1m')
 starting_cash = context.portfolio.starting_cash
 target_hodl_value = context.TARGET_HODL_RATIO * starting_cash
 reserve_value = context.RESERVE_RATIO * starting_cash

 # Cancel any outstanding orders
 #orders = get_open_orders(context.asset) or []
 #for order in orders:
 #    cancel_order(order)

 # Stop buying after passing the reserve threshold
 cash = context.portfolio.cash
 if cash <= reserve_value:
     context.is_buying = False

 # Retrieve current asset price from pricing data
 price = data.current(context.asset, 'price')

 # Check if still buying and could (approximately) afford another purchase
 if context.is_buying and cash > price:
     # Place order to make position in asset equal to target_hodl_value
     order_target_value(
         context.asset,
         target_hodl_value,
         limit_price=price*1.1
         #stop_price=price*0.9,
     )

 record(
     price=price,
     volume=data.current(context.asset,'volume'),
     cash=cash,
     starting_cash=context.portfolio.starting_cash,
     leverage=context.account.leverage,
 )

`

fredfortier commented 6 years ago

This is correct. Currently, in live mode, we are delegating OHLCV computations to each exchange. If an exchange does not publish the specified OHLCV timeframe, there is no simple way to force it.

This issue came up before. We're working on an enhancement which fetches trades and computes OHLCV candles on-the-fly from them. This will be available in the coming weeks.

calclavia commented 6 years ago

@fredfortier Any updates on this enhancement?

lenak25 commented 6 years ago

Hi @calclavia , unfortunately other issues were prioritized before this feature. I hope we could address it at the near future.