Comments (9)
I believe this should be addressed in a recent update. Try running pip install blankly --upgrade
and tell me how it goes.
from blankly.
Google Colab Output
Initializing...
Backtesting...
Progress: [######----] 60.61% Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/blankly/exchanges/interfaces/paper_trade/backtest_controller.py", line 769, in run
'state_object'])
File "<ipython-input-11-aad4e5fddf26>", line 10, in price_event
state.interface.market_order(symbol, side='buy', size=buy)
File "/usr/local/lib/python3.7/dist-packages/blankly/exchanges/interfaces/paper_trade/paper_trade_interface.py", line 366, in market_order
raise InvalidOrder(f"Size is too small. Minimum is: {min_size}. You requested {size}.")
blankly.utils.exceptions.InvalidOrder: Size is too small. Minimum is: 0.0001. You requested 0.0.
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/blankly/exchanges/interfaces/paper_trade/backtest_controller.py", line 769, in run
'state_object'])
File "<ipython-input-11-aad4e5fddf26>", line 10, in price_event
state.interface.market_order(symbol, side='buy', size=buy)
File "/usr/local/lib/python3.7/dist-packages/blankly/exchanges/interfaces/paper_trade/paper_trade_interface.py", line 366, in market_order
raise InvalidOrder(f"Size is too small. Minimum is: {min_size}. You requested {size}.")
blankly.utils.exceptions.InvalidOrder: Size is too small. Minimum is: 0.0001. You requested 0.0.
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/blankly/exchanges/interfaces/paper_trade/backtest_controller.py", line 769, in run
'state_object'])
File "<ipython-input-11-aad4e5fddf26>", line 10, in price_event
state.interface.market_order(symbol, side='buy', size=buy)
File "/usr/local/lib/python3.7/dist-packages/blankly/exchanges/interfaces/paper_trade/paper_trade_interface.py", line 366, in market_order
raise InvalidOrder(f"Size is too small. Minimum is: {min_size}. You requested {size}.")
blankly.utils.exceptions.InvalidOrder: Size is too small. Minimum is: 0.0001. You requested 0.0.
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/blankly/exchanges/interfaces/paper_trade/backtest_controller.py", line 769, in run
'state_object'])
File "<ipython-input-11-aad4e5fddf26>", line 10, in price_event
state.interface.market_order(symbol, side='buy', size=buy)
File "/usr/local/lib/python3.7/dist-packages/blankly/exchanges/interfaces/paper_trade/paper_trade_interface.py", line 366, in market_order
raise InvalidOrder(f"Size is too small. Minimum is: {min_size}. You requested {size}.")
blankly.utils.exceptions.InvalidOrder: Size is too small. Minimum is: 0.0001. You requested 0.0.
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/blankly/exchanges/interfaces/paper_trade/backtest_controller.py", line 769, in run
'state_object'])
File "<ipython-input-11-aad4e5fddf26>", line 10, in price_event
state.interface.market_order(symbol, side='buy', size=buy)
File "/usr/local/lib/python3.7/dist-packages/blankly/exchanges/interfaces/paper_trade/paper_trade_interface.py", line 366, in market_order
raise InvalidOrder(f"Size is too small. Minimum is: {min_size}. You requested {size}.")
blankly.utils.exceptions.InvalidOrder: Size is too small. Minimum is: 0.0001. You requested 0.0.
Historical Dataframes:
Account History:
USDT ETH time Account Value (USDT)
0 1000 0 1.641946e+09 1000.0
1 1000 0 1.641946e+09 1000.0
2 1000 0 1.641949e+09 1000.0
3 1000 0 1.641953e+09 1000.0
4 1000 0 1.641956e+09 1000.0
.. ... .. ... ...
163 1000 0 1.642529e+09 1000.0
164 1000 0 1.642532e+09 1000.0
165 1000 0 1.642536e+09 1000.0
166 1000 0 1.642540e+09 1000.0
167 1000 0 1.642543e+09 1000.0
[168 rows x 4 columns]
Account Returns:
time value
0 1641945600 None
1 1642032000 0
2 1642118400 0
3 1642204800 0
4 1642291200 0
5 1642377600 0
6 1642464000 0
Resampled Account Value:
time value
0 1.641946e+09 1000.0
1 1.642032e+09 1000.0
2 1.642118e+09 1000.0
3 1.642205e+09 1000.0
4 1.642291e+09 1000.0
5 1.642378e+09 1000.0
6 1.642464e+09 1000.0
Blankly Metrics:
Compound Annual Growth Rate (%): 0.0%
Cumulative Returns (%): 0.0%
Max Drawdown (%): 0.0%
Variance (%): 0.0%
Sortino Ratio: None
Sharpe Ratio: None
Calmar Ratio: failed: float division by zero
Volatility: 0.0
Value-at-Risk: None
Conditional Value-at-Risk: 0.0
Risk Free Return Rate: 0.0
Resampled Time: 86400.0
/usr/local/lib/python3.7/dist-packages/blankly/metrics/portfolio.py:55: RuntimeWarning: invalid value encountered in double_scalars
return mean / std
Windows Output
Traceback (most recent call last):
File "c:\python38\lib\site-packages\blankly\exchanges\interfaces\paper_trade\backtest_controller.py", line 704, in run
no_trade = []
File "J:\Blankly2022\BlanklyRSI.py", line 10, in price_event
state.interface.market_order(symbol, side='buy', size=buy)
File "c:\python38\lib\site-packages\blankly\exchanges\interfaces\paper_trade\paper_trade_interface.py", line 363, in market_order
max_size = market_limits['market_order']["base_max_size"]
blankly.utils.exceptions.InvalidOrder: Size is too small. Minimum is: 0.0001. You requested 0.
c:\python38\lib\site-packages\blankly\metrics\portfolio.py:55: RuntimeWarning: invalid value encountered in double_scalars
return mean / std
c:\python38\lib\site-packages\blankly\metrics\portfolio.py:60: RuntimeWarning: invalid value encountered in double_scalars
return return_series.mean() * n / abs(max_drawdown(return_series))
Historical Dataframes:
Account History:
USDT ETH time Account Value (USDT)
0 1000 0 1.611014e+09 1000.0
1 1000 0 1.611014e+09 1000.0
2 1000 0 1.611018e+09 1000.0
3 1000 0 1.611022e+09 1000.0
4 1000 0 1.611025e+09 1000.0
... ... .. ... ...
8755 1000 0 1.642529e+09 1000.0
8756 1000 0 1.642532e+09 1000.0
8757 1000 0 1.642536e+09 1000.0
8758 1000 0 1.642540e+09 1000.0
8759 1000 0 1.642543e+09 1000.0
[8760 rows x 4 columns]
Account Returns:
time value
0 1.611014e+09 NaN
1 1.611101e+09 0.0
2 1.611187e+09 0.0
3 1.611274e+09 0.0
4 1.611360e+09 0.0
.. ... ...
360 1.642118e+09 0.0
361 1.642205e+09 0.0
362 1.642291e+09 0.0
363 1.642378e+09 0.0
364 1.642464e+09 0.0
[365 rows x 2 columns]
Resampled Account Value:
time value
0 1.611014e+09 1000.0
1 1.611101e+09 1000.0
2 1.611187e+09 1000.0
3 1.611274e+09 1000.0
4 1.611360e+09 1000.0
.. ... ...
360 1.642118e+09 1000.0
361 1.642205e+09 1000.0
362 1.642291e+09 1000.0
363 1.642378e+09 1000.0
364 1.642464e+09 1000.0
[365 rows x 2 columns]
Blankly Metrics:
Compound Annual Growth Rate (%): 0.0%
Cumulative Returns (%): 0.0%
Max Drawdown (%): 0.0%
Variance (%): 0.0%
Sortino Ratio: None
Sharpe Ratio: None
Calmar Ratio: None
Volatility: 0.0
Value-at-Risk: 0.0
Conditional Value-at-Risk: 0.0
Risk Free Return Rate: 0.0
Resampled Time: 86400.0
from blankly.
Looks like it worked great. I think the size might be casted to an int
so none of the orders are going through. Try using the rsi.py
script in the examples
folder of the repo.
from blankly.
I try rsi.py but it is not worked.
Traceback (most recent call last):
File "c:\python38\lib\site-packages\blankly\exchanges\interfaces\paper_trade\backtest_controller.py", line 704, in run
no_trade = []
File "J:\Blankly2022\BlanklyRSI.py", line 12, in price_event
state.interface.market_order(symbol, side='buy', size=buy)
File "c:\python38\lib\site-packages\blankly\exchanges\interfaces\paper_trade\paper_trade_interface.py", line 363, in market_order
max_size = market_limits['market_order']["base_max_size"]
blankly.utils.exceptions.InvalidOrder: Size is too small. Minimum is: 0.0001. You requested 0.0.
c:\python38\lib\site-packages\blankly\metrics\portfolio.py:55: RuntimeWarning: invalid value encountered in double_scalars
return mean / std
c:\python38\lib\site-packages\blankly\metrics\portfolio.py:60: RuntimeWarning: invalid value encountered in double_scalars
return return_series.mean() * n / abs(max_drawdown(return_series))
Historical Dataframes:
Account History:
USDT ETH time Account Value (USDT)
0 100000 0 1.641946e+09 100000.0
1 100000 0 1.641946e+09 100000.0
2 100000 0 1.641949e+09 100000.0
3 100000 0 1.641953e+09 100000.0
4 100000 0 1.641956e+09 100000.0
.. ... .. ... ...
from blankly.
I believe the blankly code is working correctly, it is mainly due to issues with order sizing. Try out this version:
import blankly
def price_event(price, symbol, state: blankly.StrategyState):
""" This function will give an updated price every 15 seconds from our definition below """
state.variables['history'].append(price)
rsi = blankly.indicators.rsi(state.variables['history'])
if rsi[-1] < 30 and not state.variables['owns_position']:
# Dollar cost average buy
buy = blankly.trunc(state.interface.cash/price, 2)
state.interface.market_order(symbol, side='buy', size=buy)
state.variables['owns_position'] = True
elif rsi[-1] > 70 and state.variables['owns_position']:
# Dollar cost average sell
curr_value = state.interface.account[state.base_asset].available
state.interface.market_order(symbol, side='sell', size=curr_value)
state.variables['owns_position'] = False
def init(symbol, state: blankly.StrategyState):
# Download price data to give context to the algo
state.variables['history'] = state.interface.history(symbol, to=150, return_as='deque',
resolution=state.resolution)['close']
state.variables['owns_position'] = False
if __name__ == "__main__":
# Authenticate coinbase pro strategy
exchange = blankly.CoinbasePro()
# Use our strategy helper on coinbase pro
strategy = blankly.Strategy(exchange)
# Run the price event function every time we check for a new price - by default that is 15 seconds
strategy.add_price_event(price_event, symbol='BTC-USDT', resolution='1h', init=init)
# Start the strategy. This will begin each of the price event ticks
# strategy.start()
# Or backtest using this
results = strategy.backtest(to='1y', initial_values={'USDT': 10000})
print(results)
from blankly.
I guess i'm on a day when i'm unlucky and incompetent.
from blankly.
This is extremely interesting to me - I'm testing the code locally with the same 1h for 1 week resolution & I'm getting a result. I think that to make it work you
- Must be using live keys
- Must delete the
price_caches
folder beforehand
Thanks for sticking through this process. We're trying to identify and reduce the pains with onboarding new users and we are learning a ton from this and will give debugging prints when users hit this error in the future.
from blankly.
I found the error. I hope you don't get mad at me.😟 error messages could be very instructive. The cash setting is BUSD in the setting file, but the result failed because I tried USDT in the code I tested. I noticed it in the VM where I installed Linux Mint.
I want to check results with busd and usdt pair and be able to do additional tests with btc pair. For this, I think that there should be no obligation to constantly interfere with the settings file.
Thank you very much for your hard work and helpfulness. 👏
from blankly.
Awesome I'm glad you got it working. These symbol and quote errors can be extremely easy to miss and will require more work on our part to get everything working. Just let me know if you have any more issues and I'm glad to help out. We learn a lot every time we help someone get up and running.
from blankly.
Related Issues (20)
- state.interface.history duplicating prices HOT 3
- Title:Trailing Stop with limit orders in Blankly Finance paper trading environment HOT 9
- Implementing Upbit Exchange HOT 1
- Cannot run blankly login HOT 6
- Alpaca not working with crypto HOT 1
- Integrate Blankly with a timeseries database HOT 1
- Accept in memory data for backtest
- strategy.backtest without `to` argument should infer `start_time` and `end_time`
- KeyError: 'bidMultiplierUp' HOT 3
- Alpaca Cryptocurrency error(maybe just an alpaca related data error) HOT 1
- Inconsistencies in asset visualisation HOT 1
- Ow
- Innaccurate Historical Data HOT 2
- bar_event squashes price_event price HOT 1
- `state.interface.history` not returning history with correct time intervals
- `ignore_user_exceptions=False` parameter in `strategy.backtest` doesn't work
- Error installing blankly. 'ti.pxd' not found HOT 2
- Can't place bracket orders (stop-loss and take-profit) one after the other HOT 1
- Closing orders by id HOT 2
- Any plan to support IBKR ?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blankly.