Пример #1
0
def main():
    cerebro = bt.Cerebro()

    hist_start_date = datetime.utcnow() - timedelta(minutes=10)
    data_min = bt.feeds.CCXT(exchange='binance', symbol="BTC/USDT", name="btc_usdt_min", fromdate=hist_start_date,
                             timeframe=bt.TimeFrame.Minutes)
    cerebro.adddata(data_min)
    cerebro.addstrategy(TestStrategy)
    cerebro.run()
Пример #2
0
def connect_broker():
    apikey = 'siX-NO9IeVWstmn1zA2e904N'
    secret = 'ieEjNwz9TDAzg_B2EVkpgzkchDeNmyy9_UNB03B567Gwh0A_'

    cerebro = bt.Cerebro(quicknotify=True)

    # Add the strategy
    cerebro.addstrategy(TestStrategy)

    # Create our store
    config = {'apiKey': apikey, 'secret': secret, 'enableRateLimit': True}

    # IMPORTANT NOTE - Kraken (and some other exchanges) will not return any values
    # for get cash or value if You have never held any LTC coins in your account.
    # So switch LTC to a coin you have funded previously if you get errors
    store = CCXTStore(exchange='bitmex',
                      currency='BTC',
                      config=config,
                      retries=5,
                      debug=False,
                      testnet=True)

    print("I am here")
    print(store.exchange.urls)

    broker = store.getbroker()
    cerebro.setbroker(broker)

    # Get our data
    # Drop newest will prevent us from loading partial data from incomplete candles
    hist_start_date = datetime.utcnow() - timedelta(minutes=50)
    data = store.getdata(dataname='BTC/USD',
                         name="BTCUSD",
                         timeframe=bt.TimeFrame.Minutes,
                         fromdate=hist_start_date,
                         compression=1,
                         ohlcv_limit=50,
                         drop_newest=True)  #, historical=True)

    # Add the feed
    cerebro.adddata(data)

    # Run the strategy
    cerebro.run()
Пример #3
0
def connect_broker():
    config = {
        'urls': {
            'api': 'https://api.sandbox.gemini.com'
        },
        'apiKey': 'XXXXX',
        'secret': 'XXXXX',
        'nonce': lambda: str(int(time.time() * 1000))
    }
    broker = bt.brokers.CCXTBroker(exchange='gemini',
                                   currency='USD',
                                   config=config)
    cerebro.setbroker(broker)

    # Create data feeds
    data_ticks = bt.feeds.CCXT(exchange='geminy',
                               symbol='BTC/USD',
                               name="btc_usd_tick",
                               timeframe=bt.TimeFrame.Ticks,
                               compression=1,
                               config=config)
    cerebro.adddata(data_ticks)
Пример #4
0
def connect_broker():
    path = '/home/rick/PycharmProjects/Btc/huobittrade/binance.txt'
    f = open(path, 'r')
    all = f.readlines()
    f.close()
    apikey = all[0].strip()
    skey = all[1].strip()
    config = {'urls': {'api': 'https://api.binance.com/wapi/v3'},
              'apiKey': apikey,
              'secret': skey,
              'nonce': lambda: str(int(time.time() * 1000))
              }

    broker = bt.brokers.CCXTBroker(exchange='binance',
                                   currency='USD', config=config)
    cerebro.setbroker(broker)

    # Create data feeds
    data_ticks = bt.feeds.CCXT(exchange='binance', symbol='BTC/USDT',
                              name="btc_usdt_tick",
                              timeframe=bt.TimeFrame.Ticks,
                              compression=1, config=config)
    cerebro.adddata(data_ticks)
Пример #5
0
                self.sell(size=100)


#Variable for our starting cash
startcash = 10000

if __name__ == '__main__':
    cerebro = bt.Cerebro()

    hist_start_date = datetime.utcnow() - timedelta(minutes=1000)
    data_min = bt.feeds.CCXT(exchange='binance',
                             symbol="BTC/USDT",
                             name="btc_usd_min",
                             fromdate=hist_start_date,
                             todate=datetime.utcnow(),
                             timeframe=bt.TimeFrame.Minutes)
    cerebro.adddata(data_min)
    cerebro.broker.setcash(startcash)
    cerebro.addstrategy(firstStrategy)
    cerebro.run()

    # Get final portfolio Value
    portvalue = cerebro.broker.getvalue()
    pnl = portvalue - startcash

    # Print out the final result
    print('Final Portfolio Value: ${}'.format(portvalue))
    print('P/L: ${}'.format(pnl))

    # Finally plot the end results
    cerebro.plot(style='candlestick')
Пример #6
0
        #cerebro.addsizer(bt.sizers.FixedSize, stake=1)
        #cerebro.addanalyzer(btanalyzers.AnnualReturn, _name='annual')
        # Set the commission
        cerebro.broker.setcommission(leverage=1, mult=lv_mult, commission=0.01)

        tframes = dict(daily=bt.TimeFrame.Days,
                       weekly=bt.TimeFrame.Weeks,
                       monthly=bt.TimeFrame.Months)
        data = None
        data = bt.feeds.PandasData(dataname=p0,
                                   fromdate=starttime,
                                   todate=val,
                                   timeframe=bt.TimeFrame.Minutes,
                                   compression=knum)
        # Add the Data Feed to Cerebro
        cerebro.adddata(data)

        cerebro.resampledata(data, timeframe=tframes["daily"], compression=1)
        # Set our desired cash start
        cerebro.broker.setcash(lv_cash)
        # Run over everything
        cerebro.addanalyzer(btanalyzers.SharpeRatio, _name='mysharpe')
        cerebro.addanalyzer(btanalyzers.VWR,
                            _name='vwr',
                            timeframe=bt.TimeFrame.Years)
        #cerebro.addanalyzer(btanalyzers.AnnualReturn, _name='annual')
        cerebro.addanalyzer(btanalyzers.Returns,
                            _name='logreturn',
                            timeframe=bt.TimeFrame.Years)
        cerebro.addanalyzer(btanalyzers.SQN, _name='SQN')
        cerebro.addanalyzer(btanalyzers.TradeAnalyzer, _name='TradeAnalyzer')