Skip to content

Commit

Permalink
1)use zvdata 1.2.1 for better recorder class constructor 2)improve si…
Browse files Browse the repository at this point in the history
…na block money flow recorder
  • Loading branch information
foolcage committed Feb 1, 2020
1 parent a2f2eec commit 79486e9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
zvdata == 1.2.0
zvdata == 1.2.1
requests == 2.20.1
SQLAlchemy == 1.2.14
pandas == 0.24.2
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
# For a discussion on single-sourcing the version across setup.py and the
# project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='0.7.3', # Required
version='0.7.4', # Required

# This is a one-line description or tagline of what your project does. This
# corresponds to the "Summary" metadata field:
Expand Down Expand Up @@ -119,7 +119,7 @@
# For an analysis of "install_requires" vs pip's requirements files see:
# https://packaging.python.org/en/latest/requirements.html

install_requires=['zvdata>=1.2.0', 'requests>=2.20.1', 'SQLAlchemy>=1.2.14', 'pandas>=0.24.2',
install_requires=['zvdata>=1.2.1', 'requests>=2.20.1', 'SQLAlchemy>=1.2.14', 'pandas>=0.24.2',
'arrow>=0.11.0', 'marshmallow >= 3.2.2', 'tzlocal>=1.5.1', 'xlrd>=1.1.0', 'apscheduler>=3.4.0',
'jqdatasdk', 'demjson>=2.2.4', 'marshmallow-sqlalchemy>=0.19.0', 'ccxt>=1.17.191',
'plotly>=4.1.0', 'simplejson>=3.16.0',
Expand Down
18 changes: 5 additions & 13 deletions tests/recorders/eastmoney/test_dividend_financing_recorder.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,35 @@
# -*- coding: utf-8 -*-
from zvt.domain import DividendDetail, RightsIssueDetail, SpoDetail, DividendFinancing
from ...context import init_test_context

init_test_context()

from zvt.settings import SAMPLE_STOCK_CODES

from zvt.recorders.eastmoney.dividend_financing.dividend_detail_recorder import DividendDetailRecorder
from zvt.recorders.eastmoney.dividend_financing.dividend_financing_recorder import DividendFinancingRecorder
from zvt.recorders.eastmoney.dividend_financing.rights_issue_detail_recorder import RightsIssueDetailRecorder
from zvt.recorders.eastmoney.dividend_financing.spo_detail_recorder import SPODetailRecorder


def test_dividend_detail():
recorder = DividendDetailRecorder(codes=SAMPLE_STOCK_CODES)
try:
recorder.run()
DividendDetail.record_data(provider='eastmoney', codes=SAMPLE_STOCK_CODES)
except:
assert False


def test_rights_issue_detail():
recorder = RightsIssueDetailRecorder(codes=SAMPLE_STOCK_CODES)
try:
recorder.run()
RightsIssueDetail.record_data(provider='eastmoney', codes=SAMPLE_STOCK_CODES)
except:
assert False


def test_spo_detail():
recorder = SPODetailRecorder(codes=SAMPLE_STOCK_CODES)
try:
recorder.run()
SpoDetail.record_data(provider='eastmoney', codes=SAMPLE_STOCK_CODES)
except:
assert False


def test_dividend_financing():
recorder = DividendFinancingRecorder(codes=SAMPLE_STOCK_CODES)
try:
recorder.run()
DividendFinancing.record_data(provider='eastmoney', codes=SAMPLE_STOCK_CODES)
except:
assert False
22 changes: 19 additions & 3 deletions zvt/recorders/sina/money_flow/sina_stock_money_flow_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

from zvdata import IntervalLevel
from zvdata.recorder import FixedCycleDataRecorder
from zvdata.utils.time_utils import to_pd_timestamp
from zvdata.utils.time_utils import to_pd_timestamp, is_same_date, now_pd_timestamp
from zvdata.utils.utils import to_float
from zvt.domain import StockMoneyFlow, Stock
from zvt.domain import StockMoneyFlow, Stock, StockTradeDay


class SinaStockMoneyFlowRecorder(FixedCycleDataRecorder):
Expand All @@ -27,6 +27,22 @@ def __init__(self, exchanges=None, entity_ids=None, codes=None, batch_size=10,
default_size, real_time, fix_duplicate_way, start_timestamp, end_timestamp, close_hour,
close_minute, level, kdata_use_begin_time, one_day_trading_minutes)

def init_entities(self):
super().init_entities()
# 过滤掉退市的
self.entities = [entity for entity in self.entities if
(entity.end_date is None) or (entity.end_date > now_pd_timestamp())]

# TODO:more general for the case using StockTradeDay
def evaluate_start_end_size_timestamps(self, entity):
start, end, size, timestamps = super().evaluate_start_end_size_timestamps(entity)
if start:
trade_day = StockTradeDay.query_data(limit=1, order=StockTradeDay.timestamp.desc(), return_type='domain')
if trade_day:
if is_same_date(trade_day[0].timestamp, start):
size = 0
return start, end, size, timestamps

def generate_url(self, code, number):
return self.url.format(number, code)

Expand Down Expand Up @@ -121,5 +137,5 @@ def record(self, entity, start, end, size, timestamps):
__all__ = ['SinaStockMoneyFlowRecorder']

if __name__ == '__main__':
SinaStockMoneyFlowRecorder(codes=['601318']).run()
SinaStockMoneyFlowRecorder(codes=['000406']).run()
# SinaStockMoneyFlowRecorder().run()

0 comments on commit 79486e9

Please sign in to comment.