As people show some interest I decided to get started.
Here is a simplified code just for the start.
I intentionally made it as simple as possible to make it understandable and easy to play with. Please, consider this only as an invitation to collaborate.
I followed suggestions and examples from this guide
This test script:
#!/usr/bin/env python
# -*- coding: utf-8; py-indent-offset:4 -*-
###############################################################################
#
# Copyright (C) 2017 Ed Bartosh
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import sys
import backtrader as bt
class TestStrategy(bt.Strategy):
def notify_data(self, data, status, *args, **kwargs):
print('*' * 5, 'DATA NOTIF:', data._getstatusname(status))
def next(self):
print('*' * 5, 'NEXT:', bt.num2date(self.data0.datetime[0]), self.data0._name, self.data0.open[0],
bt.TimeFrame.getname(self.data0._timeframe), len(self.data0))
def runstrategy(argv):
# Create a cerebro
cerebro = bt.Cerebro()
data = bt.feeds.CCXT(exchange='gdax', symbol='BTC/USD', timeframe=bt.TimeFrame.Ticks, compression=1)
cerebro.resampledata(data, timeframe=bt.TimeFrame.Seconds)
#cerebro.adddata(data)
# Add the strategy
cerebro.addstrategy(TestStrategy)
# Run the strategy
cerebro.run()
if __name__ == '__main__':
sys.exit(runstrategy(sys.argv))
produces this output:
$ ./gdaxtest.py
loaded tick time: 2017-10-28 15:39:39.726000, price: 5715.01, size: 0.01757807
loaded tick time: 2017-10-28 15:39:39.726000, price: 5715.01, size: 0.01757807
loaded tick time: 2017-10-28 15:39:42.513000, price: 5715.01, size: 1.74e-06
***** NEXT: 2017-10-28 15:39:40 5715.01 Second 1
loaded tick time: 2017-10-28 15:39:42.513000, price: 5715.01, size: 1.74e-06
loaded tick time: 2017-10-28 15:39:43.848000, price: 5715.01, size: 0.14919127
***** NEXT: 2017-10-28 15:39:43 5715.01 Second 2
loaded tick time: 2017-10-28 15:39:43.848000, price: 5715.01, size: 0.14919127
loaded tick time: 2017-10-28 15:39:43.848000, price: 5715.01, size: 0.14919127
loaded tick time: 2017-10-28 15:39:43.848000, price: 5715.01, size: 0.14919127
loaded tick time: 2017-10-28 15:39:43.978000, price: 5715.01, size: 0.01624613
loaded tick time: 2017-10-28 15:39:43.978000, price: 5715.01, size: 0.01624613
loaded tick time: 2017-10-28 15:39:43.978000, price: 5715.01, size: 0.01624613
loaded tick time: 2017-10-28 15:39:43.978000, price: 5715.01, size: 0.01624613
loaded tick time: 2017-10-28 15:39:43.978000, price: 5715.01, size: 0.01624613
loaded tick time: 2017-10-28 15:39:43.978000, price: 5715.01, size: 0.01624613
loaded tick time: 2017-10-28 15:39:43.978000, price: 5715.01, size: 0.01624613
loaded tick time: 2017-10-28 15:39:45.516000, price: 5715.01, size: 0.06103097
***** NEXT: 2017-10-28 15:39:44 5715.01 Second 3
loaded tick time: 2017-10-28 15:39:45.516000, price: 5715.01, size: 0.46466909
loaded tick time: 2017-10-28 15:39:49.408000, price: 5715.01, size: 0.17441143
***** NEXT: 2017-10-28 15:39:46 5715.01 Second 4
loaded tick time: 2017-10-28 15:39:49.408000, price: 5715.01, size: 0.17441143
loaded tick time: 2017-10-28 15:39:49.408000, price: 5715.01, size: 0.17441143
loaded tick time: 2017-10-28 15:39:49.408000, price: 5715.01, size: 0.17441143
loaded tick time: 2017-10-28 15:39:49.408000, price: 5715.01, size: 0.17441143
loaded tick time: 2017-10-28 15:40:02.295000, price: 5715.01, size: 1.74e-06
***** NEXT: 2017-10-28 15:39:50 5715.01 Second 5
loaded tick time: 2017-10-28 15:40:02.295000, price: 5715.01, size: 1.74e-06
loaded tick time: 2017-10-28 15:40:02.295000, price: 5715.01, size: 1.74e-06
loaded tick time: 2017-10-28 15:40:02.295000, price: 5715.01, size: 1.74e-06
loaded tick time: 2017-10-28 15:40:02.295000, price: 5715.01, size: 1.74e-06
loaded tick time: 2017-10-28 15:40:02.295000, price: 5715.01, size: 1.74e-06
loaded tick time: 2017-10-28 15:40:02.295000, price: 5715.01, size: 1.74e-06
loaded tick time: 2017-10-28 15:40:11.930000, price: 5715.01, size: 1.74e-06
***** NEXT: 2017-10-28 15:40:03 5715.01 Second 6
loaded tick time: 2017-10-28 15:40:15.836000, price: 5715.0, size: 0.1853
***** NEXT: 2017-10-28 15:40:12 5715.01 Second 7
loaded tick time: 2017-10-28 15:40:15.836000, price: 5715.0, size: 0.1853
loaded tick time: 2017-10-28 15:40:15.836000, price: 5715.0, size: 0.1853
Next I'm going to implement loading historical ohlc data using fetchOHLCV ccxt API.
Any suggestions and help are welcome.