Open vivekbasappa opened 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,
)
`
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.
@fredfortier Any updates on this enhancement?
Hi @calclavia , unfortunately other issues were prioritized before this feature. I hope we could address it at the near future.
Dear Catalyst Maintainers,
Before I tell you about my issue, let me describe my environment:
Environment
Operating System: (Windows Version or
$ uname --all
) Linux ubuntu 4.4.0-112-generic #135-Ubuntu SMP Fri Jan 19 11:48:36 UTC 2018 x86_64 x86_64 x86_64 GNU/LinuxPython Version:
$ python --version
Python 2.7.12Python Bitness:
$ python -c 'import math, sys;print(int(math.log(sys.maxsize + 1, 2) + 1))'
64How did you install Catalyst: (
pip
,conda
, orother (please explain)
) pipPython packages:
$ pip freeze
or$ conda list
vivek@ubuntu:~/catalyst$ pip freeze absl-py==0.1.10 adium-theme-ubuntu==0.3.4 alembic==0.9.8 attrdict==2.0.0 backports-abc==0.5 backports.functools-lru-cache==1.5 backports.shutil-get-terminal-size==1.0.0 backports.weakref==1.0.post1 bcolz==0.12.1 bleach==2.1.2 boto3==1.5.31 botocore==1.8.45 Bottleneck==1.2.1 ccxt==1.10.1152 certifi==2018.1.18 chardet==3.0.4 click==6.7 configparser==3.5.0 contextlib2==0.5.5 CVXcanon==0.1.1 cvxopt==1.1.9 cvxpy==0.4.11 cycler==0.10.0 cyordereddict==1.0.0 Cython==0.27.3 cytoolz==0.9.0 decorator==4.2.1 dill==0.2.7.1 docutils==0.14 ecos==2.0.5 empyrical==0.2.1 enigma-catalyst==0.5.3 entrypoints==0.2.3 enum34==1.1.6 eth-abi==1.0.0b0 eth-account==0.1.0a2 eth-keyfile==0.5.1 eth-keys==0.2.0b1 eth-rlp==0.1.0a2 eth-utils==1.0.0b1 fastcache==1.0.2 funcsigs==1.0.2 functools32==3.2.3.post2 futures==3.2.0 h5py==2.7.1 hexbytes==0.1.0b0 html5lib==1.0.1 idna==2.6 influxdb==5.0.0 intervaltree==2.1.0 ipykernel==4.8.1 ipython==5.5.0 ipython-genutils==0.2.0 ipywidgets==7.1.2 Jinja2==2.10 jmespath==0.9.3 joblib==0.11 jsonschema==2.6.0 jupyter==1.0.0 jupyter-client==5.2.2 jupyter-console==5.2.0 jupyter-core==4.4.0 Logbook==1.2.1 lru-dict==1.1.6 lxml==4.1.1 Mako==1.0.7 Markdown==2.6.11 MarkupSafe==1.0 matplotlib==2.1.2 mistune==0.8.3 mock==2.0.0 multipledispatch==0.4.9 multiprocess==0.70.5 nbconvert==5.3.1 nbformat==4.4.0 networkx==2.1 notebook==5.4.0 numexpr==2.6.4 numpy==1.14.0 pandas==0.19.2 pandas-datareader==0.6.0 pandocfilters==1.4.2 pathlib2==2.3.0 patsy==0.5.0 pbr==3.1.1 pexpect==4.4.0 pickleshare==0.7.4 prompt-toolkit==1.0.15 protobuf==3.5.1 ptyprocess==0.5.2 pycryptodome==3.4.11 pyfolio==0.8.0 Pygments==2.2.0 pykalman==0.9.5 pymc3==3.3 pyparsing==2.2.0 pysha3==1.0.2 python-dateutil==2.6.1 python-editor==1.0.3 pytz==2018.3 PyYAML==3.12 pyzmq==17.0.0 qtconsole==4.3.1 redo==1.6 requests==2.18.4 requests-file==1.4.3 requests-ftp==0.3.1 requests-toolbelt==0.8.0 rlp==0.6.0 s3transfer==0.1.13 scandir==1.7 scikit-learn==0.19.1 scipy==1.0.0 scs==2.0.2 seaborn==0.8.1 Send2Trash==1.5.0 simplegeneric==0.8.1 singledispatch==3.4.0.3 six==1.11.0 sklearn==0.0 sortedcontainers==1.5.9 SQLAlchemy==1.2.3 statsmodels==0.8.0 subprocess32==3.2.7 TA-Lib==0.4.16 tables==3.4.2 tensorflow==1.5.0 tensorflow-tensorboard==1.5.1 terminado==0.8.1 testpath==0.3.1 Theano==1.0.1 toolz==0.9.0 tornado==4.5.3 tqdm==4.19.5 traitlets==4.3.2 unity-lens-photos==1.0 urllib3==1.22 wcwidth==0.1.7 web3==4.0.0b9 webencodings==0.5.1 Werkzeug==0.14.1 widgetsnbextension==3.1.4 wrapt==1.10.11Now that you know a little about me, let me tell you about the issue I am having:
Description of Issue
What did you expect to happen? algorithm should run
What happened instead? it fails with below error $ python test.py WARNING (theano.tensor.blas): Using NumPy C-API based implementation for BLAS functions. /home/vivek/.local/lib/python2.7/site-packages/h5py/init.py:36: FutureWarning: Conversion of the second argument of issubdtype from
live=True,)
File "/home/vivek/.local/lib/python2.7/site-packages/catalyst/utils/run_algo.py", line 549, in run_algorithm
stats_output=stats_output
File "/home/vivek/.local/lib/python2.7/site-packages/catalyst/utils/run_algo.py", line 331, in _run
overwrite_sim_params=False,
File "/home/vivek/.local/lib/python2.7/site-packages/catalyst/exchange/exchange_algorithm.py", line 309, in run
data, overwrite_sim_params
File "/home/vivek/.local/lib/python2.7/site-packages/catalyst/algorithm.py", line 724, in run
for perf in self.get_generator():
File "/home/vivek/.local/lib/python2.7/site-packages/catalyst/exchange/exchange_algorithm.py", line 553, in get_generator
self._init_trading_client()
File "/home/vivek/.local/lib/python2.7/site-packages/catalyst/exchange/exchange_algorithm.py", line 546, in _init_trading_client
benchmark_source=self._create_benchmark_source(),
File "/home/vivek/.local/lib/python2.7/site-packages/catalyst/algorithm.py", line 573, in _create_benchmark_source
benchmark_returns=benchmark_returns,
File "/home/vivek/.local/lib/python2.7/site-packages/catalyst/sources/benchmark_source.py", line 49, in init
self.data_portal
File "/home/vivek/.local/lib/python2.7/site-packages/catalyst/sources/benchmark_source.py", line 161, in _initialize_precalculated_series
ffill=True
File "/home/vivek/.local/lib/python2.7/site-packages/catalyst/exchange/exchange_data_portal.py", line 95, in get_history_window
ffill))
File "/home/vivek/.local/lib/python2.7/site-packages/redo/init.py", line 162, in retry
return action(*args, **kwargs)
File "/home/vivek/.local/lib/python2.7/site-packages/catalyst/exchange/exchange_data_portal.py", line 69, in _get_history_window
ffill)
File "/home/vivek/.local/lib/python2.7/site-packages/catalyst/exchange/exchange_data_portal.py", line 218, in get_exchange_history_window
False)
File "/home/vivek/.local/lib/python2.7/site-packages/catalyst/exchange/exchange.py", line 512, in get_history_window
end_dt=end_dt if not is_current else None,
File "/home/vivek/.local/lib/python2.7/site-packages/catalyst/exchange/ccxt/ccxt_exchange.py", line 420, in get_candles
freqs=freqs,
catalyst.exchange.exchange_errors.UnsupportedHistoryFrequencyError: poloniex does not support candle frequency 1T, please choose from: ['15T', '5T', '30T', '4H', '2H', '1D'].
Exception TypeError: TypeError("'NoneType' object is not callable",) in <bound method _NonClosingTextIOWrapper.del of <_io.TextIOWrapper encoding='UTF-8'>> ignored
float
tonp.floating
is deprecated. In future, it will be treated asnp.float64 == np.dtype(float).type
. from ._conv import register_converters as _register_converters [2018-02-23 03:49:26.871687] WARNING: run_algo: Catalyst is currently in ALPHA. It is going through rapid development and it is subject to errors. Please use carefully. We encourage you to report any issue on GitHub: https://github.com/enigmampc/catalyst/issues [2018-02-23 03:49:29.874946] INFO: run_algo: running algo in paper-trading mode [2018-02-23 03:49:30.402982] INFO: exchange_bundle: pricing data for [u'btc_usd'] not found in range 2015-03-01 00:00:00+00:00 to 2018-02-22 00:00:00+00:00, updating the bundles. [====================================] Ingesting daily price data for btc_usd on bitfinex: 100% [2018-02-23 03:49:32.321139] WARNING: Loader: Refusing to download new treasury data because a download succeeded at 2018-02-23 03:10:42.488702+00:00. Traceback (most recent call last): File "minitmum_variance_with_slash_constraint.py", line 199, inmy 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,)
Here is how you can reproduce this issue on your machine:
but if exchange only supports 5m and 15m how do I change that in my code?
Reproduction Steps
What steps have you taken to resolve this already?
...
Anything else?
...
Sincerely, `$ vivek