You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importpandasaspdimportnumpyasnpimportblanklyfromblankly.data.data_readerimportPriceReaderfromblanklyimportStrategy, StrategyStatedefinit(symbol, state: StrategyState):
print(symbol, state)
state.variables['history'] =state.interface.history(symbol, 50, state.resolution)
defbar_event(bar, symbol, state: StrategyState):
# state.variables['history'].append(bar)state.variables['history'].append(bar, ignore_index=True)
if__name__=="__main__":
# This downloads an example CSV# data = requests.get(# 'https://firebasestorage.googleapis.com/v0/b/blankly-6ada5.appspot.com/o/demo_data.csv?alt=media&token=acfa5c39-8f08-45dc-8be3-2033dc2b7b28').text# with open('./price_examples.csv', 'w') as file:# file.write(data)# Run on the keyless exchange, starting at 100k# exchange = blankly.KeylessExchange(price_reader=PriceReader('./price_examples.csv', 'BTC-USD'))""" df = pd.read_csv("XBTUSDT.csv", names=["time", "price", "volume"]) df["time"] = pd.to_datetime(df["time"], unit="s") df = df.set_index("time") prices = df.resample("2H")["price"].ohlc().fillna(method="ffill") volume = df.resample("2H")["volume"].sum().fillna(value=0) volume.name = "volume" df_1Min = pd.concat([prices, volume], axis=1) df_1Min = df_1Min.reset_index() df_1Min["time"] = df_1Min["time"].map(pd.Timestamp.timestamp) df_1Min.to_csv("XBTUSDT_2H.csv", index=False) """exchange=blankly.KeylessExchange(
price_reader=PriceReader("./XBTUSDT_2H.csv", "BTC-USD")
)
# Use our strategy helperstrategy=Strategy(exchange)
# Make the bar event function above run every 2hstrategy.add_bar_event(bar_event, symbol="BTC-USD", resolution="2h", init=init)
# Backtest the strategyresults=strategy.backtest(
start_date="2019-12-19 18:06:18",
end_date="2022-06-30 23:59:17",
initial_values={"USD": 10000},
)
print(results)
especially
state.variables['history'].append(bar)
raises a warning
Traceback (most recent call last):
File "C:\Users\femto\AppData\Roaming\Python\Python38\site-packages\blankly\frameworks\strategy\strategy.py", line 127, in rest_event
callback(*args)
File "mini.py", line 15, in bar_event
state.variables['history'].append(bar)
File "C:\tools\Anaconda3\lib\site-packages\pandas\core\frame.py", line 9048, in append
return self._append(other, ignore_index, verify_integrity, sort)
File "C:\tools\Anaconda3\lib\site-packages\pandas\core\frame.py", line 9061, in _append
raise TypeError("Can only append a dict if ignore_index=True")
TypeError: Can only append a dict if ignore_index=True
mini.py:16: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
state.variables['history'].append(bar, ignore_index=True)
Hello,
the following code
especially
raises a warning
or
raises
Same also occurs to example mentioned at https://docs.blankly.finance/strategy/functions/#add_bar_eventcallback-typingcallable-symbol-str-resolution-str-or-float-init-typingcallable--none-teardown-typingcallable--none-variables-dict--none
Any workaround?
Kind regards
The text was updated successfully, but these errors were encountered: