For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
if balance == 0 or not balance['free'][currency]
-
from future import (absolute_import, division, print_function,
unicode_literals)
import backtrader as bt
from ccxtbt import CCXTStore
from datetime import datetime, timedeltaclass St(bt.Strategy):
def logdata(self):
txt = []
txt.append('{}'.format(len(self)))txt.append('{}'.format( self.data.datetime.datetime(0).isoformat()) ) txt.append('{:.2f}'.format(self.data.open[0])) txt.append('{:.2f}'.format(self.data.high[0])) txt.append('{:.2f}'.format(self.data.low[0])) txt.append('{:.2f}'.format(self.data.close[0])) txt.append('{:.2f}'.format(self.data.volume[0])) print(','.join(txt)) def next(self): self.logdata()
def main(args=None):
cerebro = bt.Cerebro(quicknotify=True)
config = {'apiKey': '****************',
'secret': '********************',
'enableRateLimit': True,
}store = CCXTStore(exchange='bitmex', currency='XBT', config=config, retries=5, debug=False, sandbox=True) broker_mapping = { 'order_types': { bt.Order.Market: 'market', bt.Order.Limit: 'limit', bt.Order.Stop: 'stop', # stop-loss for kraken, stop for bitmex bt.Order.StopLimit: 'stop limit' }, 'mappings': { 'closed_order': { 'key': 'status', 'value': 'closed' }, 'canceled_order': { 'key': 'result', 'value': 1} } } broker = store.getbroker(broker_mapping=broker_mapping) cerebro.setbroker(broker) hist_start_date = datetime.utcnow() - timedelta(minutes=50) data = store.getdata(dataname='XBT/BTC', name="XBTBTC", timeframe=bt.TimeFrame.Minutes, fromdate=hist_start_date, compression=1, ohlcv_limit=50, drop_newest=True) cerebro.resampledata(data, timeframe=bt.TimeFrame.Seconds, compression=10) cerebro.addstrategy(St) cerebro.run() cerebro.plot(style="candlesticks")
if name == 'main':
main()Got this: if balance == 0 or not balance['free'][currency]
KeyError: 'XBT'Considering that I am using sandbox account, whats wrong with code?
-
@kevin said in if balance == 0 or not balance['free'][currency]:
KeyError: 'XBT'
I'm guessing it doesn't like this symbol.