Skip to content

'fix_multi_code_share_the_same_lastid' #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions ccxtbt/ccxtfeed.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ def __init__(self, **kwargs):
# self.store = CCXTStore(exchange, config, retries)
self.store = self._store(**kwargs)
self._data = deque() # data queue for price data
self._last_id = '' # last processed trade id for ohlcv
self.trade_id_dict=dict()
#self._last_id = '' # last processed trade id for ohlcv
self._last_ts = 0 # last processed timestamp for ohlcv

def start(self, ):
Expand Down Expand Up @@ -199,19 +200,24 @@ def _fetch_ohlcv(self, fromdate=None):
break

def _load_ticks(self):
if self._last_id is None:
pre_last_id=None
if self.p.dataname in self.trade_id_dict:
pre_last_id=self.trade_id_dict.get(self.p.dataname)
if pre_last_id is None:
self.trade_id_dict[self.p.dataname] = pre_last_id
# first time get the latest trade only
trades = [self.store.fetch_trades(self.p.dataname)[-1]]
else:
trades = self.store.fetch_trades(self.p.dataname)

for trade in trades:
trade_id = trade['id']
current_last_id = trade['id']

if trade_id > self._last_id:

if current_last_id > self.pre_last_id:
trade_time = datetime.strptime(trade['datetime'], '%Y-%m-%dT%H:%M:%S.%fZ')
self._data.append((trade_time, float(trade['price']), float(trade['amount'])))
self._last_id = trade_id
self.trade_id_dict[self.p.dataname] = current_last_id

try:
trade = self._data.popleft()
Expand Down