Skip to content

Commit

Permalink
【Feature】将 ETF 行情数据存入 Index 数据库中
Browse files Browse the repository at this point in the history
  • Loading branch information
buginux committed Jul 3, 2019
1 parent 8b925fc commit b1561b6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 24 deletions.
6 changes: 2 additions & 4 deletions zvt/api/technical.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,11 @@ def get_securities(security_list: List[str] = None,
session=session, order=order, limit=limit, index=index, index_is_time=index_is_time)


def get_kdata(security_id, data_schema=None, level=TradingLevel.LEVEL_1DAY.value, provider='eastmoney', columns=None,
def get_kdata(security_id, level=TradingLevel.LEVEL_1DAY.value, provider='eastmoney', columns=None,
return_type='df', start_timestamp=None, end_timestamp=None,
filters=None, session=None, order=None, limit=None):
security_type, exchange, code = decode_security_id(security_id)

if data_schema is None:
data_schema = get_kdata_schema(security_type, level=level)
data_schema = get_kdata_schema(security_type, level=level)

return get_data(data_schema=data_schema, security_id=security_id, level=level, provider=provider, columns=columns,
return_type=return_type,
Expand Down
5 changes: 1 addition & 4 deletions zvt/domain/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
Stock1DKdataBase = declarative_base()
Stock1WKKdataBase = declarative_base()

ETF1DKdataBase = declarative_base()
Index1DKdataBase = declarative_base()

FinanceBase = declarative_base()
Expand Down Expand Up @@ -65,7 +64,6 @@ class StoreCategory(enum.Enum):
stock_1d_kdata = 'stock_1d_kdata'
stock_1wk_kdata = 'stock_1wk_kdata'

etf_1d_kdata = 'etf_1d_kdata'
index_1d_kdata = 'index_1d_kdata'

finance = 'finance'
Expand Down Expand Up @@ -94,7 +92,7 @@ class StoreCategory(enum.Enum):
StoreCategory.trading],

Provider.SINA: [StoreCategory.meta,
StoreCategory.etf_1d_kdata,
StoreCategory.index_1d_kdata,
StoreCategory.stock_1d_kdata,
StoreCategory.money_flow],

Expand Down Expand Up @@ -132,7 +130,6 @@ class StoreCategory(enum.Enum):
StoreCategory.stock_1d_kdata: Stock1DKdataBase,
StoreCategory.stock_1wk_kdata: Stock1WKKdataBase,

StoreCategory.etf_1d_kdata: ETF1DKdataBase,
StoreCategory.index_1d_kdata: Index1DKdataBase,
StoreCategory.finance: FinanceBase,
StoreCategory.dividend_financing: DividendFinancingBase,
Expand Down
16 changes: 6 additions & 10 deletions zvt/domain/quote.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from sqlalchemy import Column, String, DateTime, Float

from zvt.domain.common import Stock1DKdataBase, ETF1DKdataBase, Index1DKdataBase, Stock1HKdataBase, Stock15MKdataBase, \
from zvt.domain.common import Stock1DKdataBase, Index1DKdataBase, Stock1HKdataBase, Stock15MKdataBase, \
Coin15MKdataBase, Coin1HKdataBase, Coin1DKdataBase, Coin1MKdataBase, Coin5MKdataBase, Coin1WKKdataBase, \
Stock1MKdataBase, Stock5MKdataBase, Stock30MKdataBase, Stock1WKKdataBase, CoinTickKdataBase

Expand Down Expand Up @@ -100,19 +100,15 @@ class Stock1MKdata(Stock1MKdataBase, StockKdataCommon):
__tablename__ = 'stock_1m_kdata'


class ETF1DKdata(ETF1DKdataBase, KdataCommon):
__tablename__ = 'etf_1d_kdata'

# 累计净值(货币 ETF 为七日年化)
cumulative_net_value = Column(Float)
# 净值增长率
change_pct = Column(Float)


class Index1DKdata(Index1DKdataBase, KdataCommon):
__tablename__ = 'index_1d_kdata'
turnover_rate = Column(Float)

# ETF 累计净值(货币 ETF 为七日年化)
cumulative_net_value = Column(Float)
# ETF 净值增长率
change_pct = Column(Float)


class CoinTickKdata(CoinTickKdataBase, TickCommon):
__tablename__ = 'coin_tick_kdata'
Expand Down
12 changes: 6 additions & 6 deletions zvt/recorders/sina/china_etf_day_kdata_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from zvt.api.common import generate_kdata_id
from zvt.recorders.consts import EASTMONEY_ETF_NET_VALUE_HEADER
from zvt.api.technical import get_kdata
from zvt.domain import Index, ETF1DKdata, Provider, SecurityType, StoreCategory, TradingLevel
from zvt.domain import Index, Provider, SecurityType, StoreCategory, TradingLevel, Index1DKdata
from zvt.recorders.recorder import ApiWrapper, FixedCycleDataRecorder, TimeSeriesFetchingStyle
from zvt.utils.time_utils import to_time_str
from zvt.utils.utils import init_process_log
Expand Down Expand Up @@ -44,8 +44,8 @@ class ChinaETFDayKdataRecorder(FixedCycleDataRecorder):
meta_schema = Index

provider = Provider.SINA
store_category = StoreCategory.etf_1d_kdata
data_schema = ETF1DKdata
store_category = StoreCategory.index_1d_kdata
data_schema = Index1DKdata
url = 'http://money.finance.sina.com.cn/quotes_service/api/json_v2.php/CN_MarketData.getKLineData?' \
'symbol={}{}&scale=240&&datalen={}&ma=no'
api_wrapper = MyApiWrapper()
Expand Down Expand Up @@ -75,10 +75,10 @@ def generate_request_param(self, security_item, start, end, size, timestamp):
}

def on_finish(self, security_item):
kdatas = get_kdata(security_id=security_item.id, data_schema=ETF1DKdata, level=TradingLevel.LEVEL_1DAY.value,
order=ETF1DKdata.timestamp.asc(),
kdatas = get_kdata(security_id=security_item.id, level=TradingLevel.LEVEL_1DAY.value,
order=Index1DKdata.timestamp.asc(),
return_type='domain', session=self.session,
filters=[ETF1DKdata.cumulative_net_value.is_(None)])
filters=[Index1DKdata.cumulative_net_value.is_(None)])

if kdatas and len(kdatas) > 0:
start = kdatas[0].timestamp
Expand Down

0 comments on commit b1561b6

Please sign in to comment.