final_ohlc bugfix
This commit is contained in:
@@ -150,6 +150,7 @@ class OHLCFile:
|
|||||||
# first we write the "final" rows which means rows that have been closed and will get no more data.
|
# first we write the "final" rows which means rows that have been closed and will get no more data.
|
||||||
for row in self._final_rows:
|
for row in self._final_rows:
|
||||||
self.file.write(OHLCFile.row_bytes(row))
|
self.file.write(OHLCFile.row_bytes(row))
|
||||||
|
self._final_rows.clear()
|
||||||
# apply any pending changes to the current row
|
# apply any pending changes to the current row
|
||||||
if self._pending is not None:
|
if self._pending is not None:
|
||||||
self._cur = self._pending
|
self._cur = self._pending
|
||||||
@@ -214,19 +215,25 @@ class OHLCFileSeries:
|
|||||||
self.base_dir = base_dir
|
self.base_dir = base_dir
|
||||||
self.symbol = symbol
|
self.symbol = symbol
|
||||||
self.series_start: Optional[datetime] = None # timestamp of the first datum in the series
|
self.series_start: Optional[datetime] = None # timestamp of the first datum in the series
|
||||||
self.write_offset: int = 0
|
self.write_offset: Optional[int] = None
|
||||||
self.last_flush: Optional[tuple[datetime,dec]] = None
|
self.last_flush: Optional[tuple[datetime,dec]] = None
|
||||||
self.quote_file = None
|
self.quote_file = None
|
||||||
self.dirty_files = set()
|
self.dirty_files = set()
|
||||||
self.quote: Optional[tuple[datetime,dec]] = None
|
self.quote: Optional[tuple[datetime,dec]] = None
|
||||||
|
|
||||||
|
|
||||||
|
@property
|
||||||
|
def quote_filename(self):
|
||||||
|
return os.path.join(self.base_dir, self.symbol, 'quote.csv')
|
||||||
|
|
||||||
|
|
||||||
def update(self, time: datetime, price: dec):
|
def update(self, time: datetime, price: dec):
|
||||||
#
|
#
|
||||||
# load quote file
|
# load quote file
|
||||||
#
|
#
|
||||||
if self.quote_file is None:
|
if self.quote_file is None:
|
||||||
|
|
||||||
quote_filename = os.path.join(self.base_dir, self.symbol, 'quote.csv')
|
quote_filename = self.quote_filename
|
||||||
try:
|
try:
|
||||||
self.quote_file = open(quote_filename, 'br+')
|
self.quote_file = open(quote_filename, 'br+')
|
||||||
# load existing quote file
|
# load existing quote file
|
||||||
@@ -289,14 +296,28 @@ class OHLCFileSeries:
|
|||||||
#
|
#
|
||||||
# flush quote file
|
# flush quote file
|
||||||
#
|
#
|
||||||
|
try:
|
||||||
|
start_of_column = self.quote_file.tell()
|
||||||
self.quote_file.write(f'{ts},{price:f}'.encode('ascii'))
|
self.quote_file.write(f'{ts},{price:f}'.encode('ascii'))
|
||||||
|
self.quote_file.truncate()
|
||||||
self.quote_file.flush()
|
self.quote_file.flush()
|
||||||
self.quote_file.seek(self.write_offset)
|
self.quote_file.seek(start_of_column)
|
||||||
|
except IOError:
|
||||||
|
log.exception(f'While saving quote file {self.quote_filename}')
|
||||||
|
|
||||||
# remember where we were so we can forward-fill again next time
|
# remember the last flush point so we can forward-fill next time
|
||||||
self.last_flush = self.quote
|
self.last_flush = self.quote
|
||||||
|
|
||||||
|
|
||||||
|
def __hash__(self):
|
||||||
|
return hash((self.base_dir,self.symbol))
|
||||||
|
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
return other.base_dir == self.base_dir and other.symbol == self.symbol
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class FinalOHLCRepository:
|
class FinalOHLCRepository:
|
||||||
"""
|
"""
|
||||||
Used for backfill when all data is known to be final. Keeps a simple table of current NativeOHLC candles.
|
Used for backfill when all data is known to be final. Keeps a simple table of current NativeOHLC candles.
|
||||||
|
|||||||
Reference in New Issue
Block a user