Skip to content

Commit

Permalink
staging: fix data lossing when enumrate history data
Browse files Browse the repository at this point in the history
Related to the issue #4

Link: #4
Signed-off-by: Guanjun <guanjun@linux.alibaba.com>
  • Loading branch information
mapicccy committed Aug 10, 2022
1 parent f427caf commit 80af82a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
7 changes: 2 additions & 5 deletions funcat.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
Metadata-Version: 2.1
Metadata-Version: 1.1
Name: funcat
Version: 1.1.0
Summary: funcat
Home-page: https://github.com/cedricporter/funcat
Author: Hua Liang
Author-email: et@everet.org
License: Apache License v2
Description: UNKNOWN
Platform: UNKNOWN
Classifier: Programming Language :: Python
Classifier: Operating System :: Microsoft :: Windows
Expand All @@ -14,7 +15,3 @@ Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
License-File: LICENSE

UNKNOWN

10 changes: 9 additions & 1 deletion funcat/data/tushare_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,14 @@ def get_price(self, order_book_id, start, end, freq):

str_start_date = get_str_date_from_int(start)
str_end_date = get_str_date_from_int(end)
filename = (order_book_id + str_start_date + str_end_date).replace('.', '-') + '.csv'

# should find up-to-date filename, in case of lossing data.
filename = "NAF"
for trade_date_suffix in reversed(self.trading_dates):
filename = (order_book_id + str_start_date + str(trade_date_suffix)).replace('.', '-') + '.csv'
if os.path.exists('data/' + filename):
break

if os.path.exists('data'):
if os.path.exists('data/' + filename):
# csv file may be empty, raise except EmptyDataError
Expand Down Expand Up @@ -145,6 +152,7 @@ def get_price(self, order_book_id, start, end, freq):

df.to_csv('data/' + filename, index=False)

# dataframe needs update if found persistent data from disk and end time is equal to today
if not df.empty and str(df.at[0, 'trade_date']) == str(last_tradeday) and str(end) == now:
rt = get_runtime_data(order_book_id)
if rt is not None and str(rt.at[0, 'trade_date']) == now:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def test_000001():
from funcat.data.tushare_backend import TushareDataBackend
set_data_backend(TushareDataBackend())

T("20200814")
S("000001.SH")
T("20220808")
S("002694.SZ")

print(O, H, L, C, V)
print(MA(C, 5), MA(C, 10), MA(C, 20))
Expand Down

0 comments on commit 80af82a

Please sign in to comment.