Hi all,
I have a strategy that requires my next() to be called on every tick of the price. I have succesfully implemented the ccxtbt module which bridges the gap between backtrader and my broker.
This works great, however it doesn't seem to support live ticker data. When I try to use bt.TimeFrame.Ticks I get the following error:
ValueError: backtrader CCXT module doesn't support fetching OHLCV data for time frame Tick, comression 1
The lowest I can go seems to be bt.TimeFrame.Minutes with compression=1.
But in the background I can see the following network traffic to my broker:
2021-02-14 21:19:23.265920 - fetch_ohlcv - Attempt 0
Fetching: ETH/BTC, TF: 1m, Since: 1613337540000, Limit: 30
Request:
GET https://api.binance.com/api/v3/klines?
symbol=ETHBTC&
interval=1m&
limit=30&
startTime=1613337540000&
endTime=1613337563766
{'User-Agent': 'python-requests/2.25.1', 'Accept-Encoding': 'gzip, deflate'} None
Response:
GET https://api.binance.com/api/v3/klines?symbol=ETHBTC&interval=1m&limit=30&startTime=1613337540000&endTime=1613337563766 200 {
'Content-Type': 'application/json;charset=UTF-8',
'Content-Length': '144',
'Connection': 'keep-alive',
'Date': 'Sun, 14 Feb 2021 21:19:24 GMT',
'Server':'nginx', 'x-mbx-uuid': '2e6s5db1-c4b4-49b2-b476-5358206245f2',
'x-mbx-used-weight':'12',
'x-mbx-used-weight-1m': '12',
'Strict-Transport-Security': 'max-age=31536000; includeSubdomains',
'X-Frame-Options': 'SAMEORIGIN',
'X-Xss-Protection': '1; mode=block',
'X-Content-Type-Options': 'nosniff',
'Content-Security-Policy': "default-src 'self'",
'X-Content-Security-Policy': "default-src 'self'",
'X-WebKit-CSP': "default-src 'self'",
'Cache-Control': 'no-cache, no-store, must-revalidate',
'Pragma': 'no-cache',
'Expires': '0',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, HEAD, OPTIONS',
'X-Cache': 'Miss from cloudfront',
'Via': '1.1 fc8f1559s65d4fs6dd42c7d90.cloudfront.net (CloudFront)',
'X-Amz-Cf-Pop': 'AMS50-C1',
'X-Amz-Cf-Id': 'eQ965__94s8fd4s6fs55sd0-8ab61s46sd6sYx-d15sd6s6d5hVg=='} [
[1613337540000,"0.03718400","0.03720500","0.03718300","0.03719000","36.00300000",1613337599999,"1.33899282",85,"11.29600000","0.42016946","0"]]
2021-02-14 21:19:24.014237 - fetch_ohlcv - Attempt 0
Fetching: ETH/BTC, TF: 1m, Since: 1613337540000, Limit: 30
Request:
GET https://api.binance.com/api/v3/klines?
symbol=ETHBTC&
interval=1m&
limit=30&
startTime=1613337540000&
endTime=1613337564524
{'User-Agent': 'python-requests/2.25.1', 'Accept-Encoding': 'gzip, deflate'} None
Response:
GET https://api.binance.com/api/v3/klines?symbol=ETHBTC&interval=1m&limit=30&startTime=1613337540000&endTime=1613337564524 200 {
'Content-Type': 'application/json;charset=UTF-8',
'Content-Length': '144',
'Connection': 'keep-alive',
'Date': 'Sun, 14 Feb 2021 21:19:24 GMT',
'Server': 'nginx',
'x-mbx-uuid': 'as56d5a6-70cc-4967-bsd51-1a21sd8545e',
'x-mbx-used-weight': '13',
'x-mbx-used-weight-1m': '13',
'Strict-Transport-Security': 'max-age=31536000; includeSubdomains',
'X-Frame-Options': 'SAMEORIGIN',
'X-Xss-Protection': '1; mode=block',
'X-Content-Type-Options': 'nosniff',
'Content-Security-Policy': "default-src 'self'",
'X-Content-Security-Policy': "default-src 'self'",
'X-WebKit-CSP': "default-src 'self'",
'Cache-Control': 'no-cache, no-store, must-revalidate',
'Pragma': 'no-cache',
'Expires': '0',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, HEAD, OPTIONS',
'X-Cache': 'Miss from cloudfront',
'Via': '1.1 fc8f1s84d64fsd54fs5d5sdsdfsdcx56590.cloudfront.net (CloudFront)',
'X-Amz-Cf-Pop': 'AMS50-C1',
'X-Amz-Cf-Id': 'vV6s4d8g4hgfh5f46sdsfcAZ-3W6k5MTn__GtwA0-m9l7Rbw=='} [
[1613337540000,"0.03718400","0.03720500","0.03718300","0.03719100","36.41400000",1613337599999,"1.35427825",87,"11.64200000","0.43303754","0"]]
As you can see (in the latest line of the responses) the ccxtbt module does in fact continously poll my broker for the latest OHLCV data, and receives the latest tick price as the "Close".
So now my question is: How can I make this latest tick price be my dataClose[0], and call the next() of my strategy?
Thanks