gbeced / basana Goto Github PK
View Code? Open in Web Editor NEWA Python async and event driven framework for algorithmic trading, with a focus on crypto currencies.
License: Other
A Python async and event driven framework for algorithmic trading, with a focus on crypto currencies.
License: Other
An excellent trading framework!Expected more functions, such as trading visualizations、add more backtest analysis indicator、support more exchange
basana/external/binance/tools/download_bars.py:79: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
Check discussion in #19
There seems to be a bug in how the Binance exchange returns pair info.
E.g.,
pair_info = await exchange.get_pair_info(bs.Pair(base_symbol="DOGE", quote_symbol="USDT"))
print(pair_info.base_precision, pair_info.quote_precision)
Returns
0, 5
But going by the raw output from the binance symbol info, it should be 8 / 8:
{'symbol': 'DOGEUSDT',
'status': 'TRADING',
'baseAsset': 'DOGE',
'baseAssetPrecision': 8,
'quoteAsset': 'USDT',
'quotePrecision': 8,
'quoteAssetPrecision': 8,
'baseCommissionPrecision': 8,
'quoteCommissionPrecision': 8,
...
Hello,
it could be a nice improvement to have such a plot ie plot of each owned stocks/cryptos/fiat over time.
from Blankly
Kind regards
Is it possible to include some csv file in tests or samples directory?
I have difficulty downloading that csv file following your instruction. It reports timeout.
Following instructions in DEVELOPER.md results in test failures:
FAIL Required test coverage of 100.0% not reached. Total coverage: 41.25% ================================================================== short test summary info ================================================================== ERROR tests/test_backtesting_charts.py !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ===================================================================== 1 error in 0.57s ======================================================================
Specifying poetry install --all-extras
in DEVELOPER.md resolves:
`
Required test coverage of 100.0% reached. Total coverage: 100.00%
=================================================================== slowest 10 durations ====================================================================
2.41s call tests/test_bitstamp_bars.py::test_bars_from_trades
2.10s call tests/test_backtesting_charts.py::test_save_line_chart[order_plan0]
1.02s call tests/test_core_websockets.py::test_schedule_reconnection
1.00s call tests/test_dispatcher.py::test_realtime_scheduler[1]
0.84s call tests/test_binance_bars.py::test_bars
0.51s call tests/test_dispatcher.py::test_realtime_scheduler[0.5]
0.50s call tests/test_token_bucket.py::test_token_wait
0.38s call tests/test_event.py::test_mutiple_sources
0.30s call tests/test_dispatcher.py::test_out_of_order_events_are_skipped
0.26s call tests/test_bitstamp_orders.py::test_authentication_fails
============================================================ 226 passed, 2523 warnings in 18.72s ============================================================
GM.
Loved your previous work on PyAlgoTrade.
Basana is tremendous upgrade. Thank you.
Could you please extend the TradingSignal to allow kwargs to be passed. This allows the Strategy to pass other attributes than just the order operation and pair to the PositionManager?
This is useful when the strategy is passing a weighting to be bought/sold.
As an example, I have shown the RSI example extended to pass the oversold
value in the TradingSignal:
# RSI crossed below oversold level
if self.rsi[-2] >= self._oversold_level and self.rsi[-1] < self._oversold_level:
self.push(bs.TradingSignal(bar_event.when, bs.OrderOperation.BUY, bar_event.bar.pair, oversold=self.rsi[-1]))
# RSI crossed above overbought level
elif self.rsi[-2] <= self._overbought_level and self.rsi[-1] > self._overbought_level:
self.push(bs.TradingSignal(bar_event.when, bs.OrderOperation.SELL, bar_event.bar.pair, oversold=self.rsi[-1]))
Hello,
Under Windows 10
python -m basana.external.bitstamp.tools.download_bars -c BTC/USD -p 1d -s 2014-01-01 -e 2021-01-31 > bitstamp_btcusd_day.csv
output a UTF-16 LE encoded CSV file
Running example raises
> python .\app.py
Traceback (most recent call last):
File "C:\Users\femto\github\scls19fr\crypto-trading-bots\basana\app.py", line 111, in <module>
asyncio.run(main())
File "C:\Users\femto\anaconda3\Lib\asyncio\runners.py", line 190, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "C:\Users\femto\anaconda3\Lib\asyncio\runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\femto\anaconda3\Lib\asyncio\base_events.py", line 654, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "C:\Users\femto\github\scls19fr\crypto-trading-bots\basana\app.py", line 101, in main
await event_dispatcher.run()
File "C:\Users\femto\anaconda3\Lib\site-packages\basana\core\dispatcher.py", line 288, in run
await super().run(stop_signals=stop_signals)
File "C:\Users\femto\anaconda3\Lib\site-packages\basana\core\dispatcher.py", line 231, in run
async with helpers.TaskGroup() as tg:
File "C:\Users\femto\anaconda3\Lib\site-packages\basana\core\helpers.py", line 43, in __aexit__
await asyncio.gather(*self._tasks)
File "C:\Users\femto\anaconda3\Lib\site-packages\basana\core\dispatcher.py", line 298, in _dispatch_loop
next_dt = self._event_mux.peek_next_event_dt()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\femto\anaconda3\Lib\site-packages\basana\core\dispatcher.py", line 76, in peek_next_event_dt
self._prefetch()
File "C:\Users\femto\anaconda3\Lib\site-packages\basana\core\dispatcher.py", line 114, in _prefetch
if event := source.pop():
^^^^^^^^^^^^
File "C:\Users\femto\anaconda3\Lib\site-packages\basana\core\event_sources\csv.py", line 87, in pop
ret = next(self._row_it)
^^^^^^^^^^^^^^^^^^
File "C:\Users\femto\anaconda3\Lib\site-packages\basana\core\event_sources\csv.py", line 61, in load_and_yield
for ev in row_parser.parse_row(row):
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\femto\anaconda3\Lib\site-packages\basana\external\common\csv\bars.py", line 38, in parse_row
volume = Decimal(row_dict["volume"])
~~~~~~~~^^^^^^^^^^
KeyError: 'volume'
because row_dict
looks like
{'ÿþd\x00a\x00t\x00e\x00t\x00i\x00m\x00e\x00': '\x00', '\x00o\x00p\x00e\x00n\x00': None, '\x00h\x00i\x00g\x00h\x00': None, '\x00l\x00o\x00w\x00': None, '\x00c\x00l\x00o\x00s\x00e\x00': None, '\x00v\x00o\x00l\x00u\x00m\x00e\x00': None}
Saving to file should be left to the Python script and not delegated to Bash, PowerShell.
My proposal is to have an output flag (-o
, --ouput
)
python -m basana.external.bitstamp.tools.download_bars -c BTC/USD -p 1d -s 2014-01-01 -e 2021-01-31 -o bitstamp_btcusd_day.csv
Any opinion?
Hi, is there a way to interact with CCXT ? or other exchanges ?
Can I both use spot account and margin account at one strategy? I've look at the example, It seen that one strategy subscribe to one trading signals, either spot or margin.
What's the expected role for this two class? To me they works similarly.
Hi @gbeced,
Can you please guide us on how to use a recursive indicators in any strategy.
Sample Implementation
self._rsi = RSI(period=21)
self._sma_of_rsi = SMA(self._rsi, period=15)
I want to calculate the sma from the RSI values.
Hi, do you have idea for order features like backtesting.py ? Like stoploss price, take profit price or I want order at the close price of the previous bar but class bs.TradingSignal just get 3 params.
`class TradingSignal(event.Event):
"""A trading signal is an event that instructs to buy or sell a given pair.
:param when: The datetime when the trading signal occurred. It must have timezone information set.
:param operation: The operation.
:param pair: The pair to trade.
"""
def __init__(self, when: datetime.datetime, operation: enums.OrderOperation, pair: pair.Pair):
super().__init__(when)
#: The operation.
self.operation = operation
#: The pair to trade.
self.pair = pair`
Making cancel_order idempotent simplifies state management.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.