Skip to content

Commit

Permalink
update to new data v2
Browse files Browse the repository at this point in the history
  • Loading branch information
camelpac committed Mar 4, 2021
1 parent 3b0a398 commit 69d70f8
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions alpaca_backtrader_api/alpacadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
unicode_literals)

from datetime import datetime, timedelta

import pandas as pd
from backtrader.feed import DataBase
from backtrader import date2num, num2date
from backtrader.utils.py3 import queue, with_metaclass
Expand Down Expand Up @@ -338,7 +338,7 @@ def _load(self):
# passing None to fetch max possible in 1 request
dtbegin = None

dtend = datetime.utcfromtimestamp(int(msg['time']))
dtend = pd.Timestamp(msg['time'], unit='ns')

self.qhist = self.o.candles(
self.p.dataname, dtbegin, dtend,
Expand Down Expand Up @@ -401,7 +401,7 @@ def _load(self):
return False

def _load_tick(self, msg):
dtobj = datetime.utcfromtimestamp(msg['time'])
dtobj = pd.Timestamp(msg['time'], unit='ns')
dt = date2num(dtobj)
if dt <= self.lines.datetime[-1]:
return False # time already seen
Expand All @@ -413,8 +413,8 @@ def _load_tick(self, msg):

# Put the prices into the bar
tick = float(
msg['askprice']) if self.p.useask else float(
msg['bidprice'])
msg['ask_price']) if self.p.useask else float(
msg['bid_price'])
self.lines.open[0] = tick
self.lines.high[0] = tick
self.lines.low[0] = tick
Expand All @@ -425,7 +425,7 @@ def _load_tick(self, msg):
return True

def _load_agg(self, msg):
dtobj = datetime.utcfromtimestamp(int(msg['time']))
dtobj = pd.Timestamp(msg['time'], unit='ns')
dt = date2num(dtobj)
if dt <= self.lines.datetime[-1]:
return False # time already seen
Expand Down

0 comments on commit 69d70f8

Please sign in to comment.