Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
Former-commit-id: fe81300
  • Loading branch information
foolcage committed Jan 7, 2020
1 parent 04e8c96 commit 7840587
Show file tree
Hide file tree
Showing 51 changed files with 367 additions and 229 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.1.3
#zvdata == 1.1.3
requests == 2.20.1
SQLAlchemy == 1.2.14
pandas == 0.24.2
Expand Down
6 changes: 3 additions & 3 deletions zvt/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def get_cross_market_summary(
order=order, limit=limit,index=index,time_field=time_field)


from zvt.domain import IndexMoneyFlow
from zvt.domain import BlockMoneyFlow

def get_index_money_flow(
ids: List[str] = None,
Expand All @@ -81,10 +81,10 @@ def get_index_money_flow(
limit: int = None,
index: Union[str, list] = 'timestamp',
time_field: str = 'timestamp'):
return get_data(data_schema=IndexMoneyFlow, ids=ids, entity_ids=entity_ids, entity_id=entity_id, codes=codes,
return get_data(data_schema=BlockMoneyFlow, ids=ids, entity_ids=entity_ids, entity_id=entity_id, codes=codes,
code=code, level=level, provider=provider, columns=columns, return_type=return_type,
start_timestamp=start_timestamp, end_timestamp=end_timestamp, filters=filters, session=session,
order=order, limit=limit,index=index,time_field=time_field)
order=order, limit=limit, index=index, time_field=time_field)


from zvt.domain import DragonAndTiger
Expand Down
4 changes: 2 additions & 2 deletions zvt/api/quote.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from zvdata.contract import get_db_session
from zvt.accounts.ccxt_account import CCXTAccount
from zvt.api.common import get_kdata_schema
from zvt.domain import StockCategory, IndexMoneyFlow
from zvt.domain import StockCategory, BlockMoneyFlow
from zvt.domain.meta.stock_meta import Index


Expand Down Expand Up @@ -107,7 +107,7 @@ def get_current_price(entity_ids=None, entity_type='coin'):


if __name__ == '__main__':
money_flow_session = get_db_session(provider='sina', data_schema=IndexMoneyFlow)
money_flow_session = get_db_session(provider='sina', data_schema=BlockMoneyFlow)

entities = get_entities(entity_type='index',
return_type='domain', provider='sina',
Expand Down
21 changes: 6 additions & 15 deletions zvt/domain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,12 @@ class CompanyType(enum.Enum):


# make sure import all the domain schemas before using them
from .business import *
from .meta.coin_meta import *
from .dividend_financing import *
from .finance import *
from .holder import *
from .macro import *
from .meta.stock_meta import *
from .money_flow import *
from .trading import *

from .quotes import *
from .factors import *
from .meta import *
from .valuation import *
from .trade_day import *
from zvt.domain.business import *
from zvt.domain.meta import *
from zvt.domain.fundamental import *
from zvt.domain.misc import *
from zvt.domain.quotes import *
from zvt.domain.factors import *


def init_schema():
Expand Down
5 changes: 5 additions & 0 deletions zvt/domain/fundamental/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
from zvt.domain.fundamental.dividend_financing import *
from zvt.domain.fundamental.finance import *
from zvt.domain.fundamental.trading import *
from zvt.domain.fundamental.valuation import *
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from sqlalchemy import Column, String, DateTime, Float
from sqlalchemy.ext.declarative import declarative_base

from zvdata.contract import register_schema, register_api
from zvdata import Mixin
from zvdata.contract import register_schema, register_api

DividendFinancingBase = declarative_base()

Expand Down Expand Up @@ -74,3 +74,5 @@ class RightsIssueDetail(DividendFinancingBase, Mixin):


register_schema(providers=['eastmoney'], db_name='dividend_financing', schema_base=DividendFinancingBase)

__all__ = ['DividendFinancing', 'DividendDetail', 'SpoDetail', 'RightsIssueDetail']
4 changes: 3 additions & 1 deletion zvt/domain/finance.py → zvt/domain/fundamental/finance.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from sqlalchemy import Column, String, DateTime, Float, Integer
from sqlalchemy.ext.declarative import declarative_base

from zvdata.contract import register_schema, register_api
from zvdata import Mixin
from zvdata.contract import register_schema, register_api

FinanceBase = declarative_base()

Expand Down Expand Up @@ -965,3 +965,5 @@ def important_cols(cls):


register_schema(providers=['eastmoney'], db_name='finance', schema_base=FinanceBase)

__all__ = ['FinanceFactor', 'BalanceSheet', 'IncomeStatement', 'CashFlowStatement']
4 changes: 3 additions & 1 deletion zvt/domain/trading.py → zvt/domain/fundamental/trading.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from sqlalchemy import Column, String, Float
from sqlalchemy.ext.declarative import declarative_base

from zvdata.contract import register_schema, register_api
from zvdata import Mixin
from zvdata.contract import register_schema, register_api

TradingBase = declarative_base()

Expand Down Expand Up @@ -152,3 +152,5 @@ class DragonAndTiger(TradingBase, Mixin):


register_schema(providers=['eastmoney'], db_name='trading', schema_base=TradingBase)

__all__ = ['ManagerTrading', 'HolderTrading', 'MarginTrading', 'BigDealTrading', 'DragonAndTiger']
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,5 @@ class EtfValuation(ValuationBase, Mixin):


register_schema(providers=['joinquant'], db_name='valuation', schema_base=ValuationBase)

__all__ = ['StockValuation', 'EtfValuation']
4 changes: 2 additions & 2 deletions zvt/domain/meta/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-
from .coin_meta import *
from .stock_meta import *
from zvt.domain.meta.coin_meta import *
from zvt.domain.meta.stock_meta import *
4 changes: 3 additions & 1 deletion zvt/domain/meta/coin_meta.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# 数字货币
from sqlalchemy.ext.declarative import declarative_base

from zvdata.contract import register_schema, register_entity
from zvdata import EntityMixin
from zvdata.contract import register_schema, register_entity

CoinMetaBase = declarative_base()

Expand All @@ -13,3 +13,5 @@ class Coin(CoinMetaBase, EntityMixin):


register_schema(providers=['ccxt'], db_name='coin_meta', schema_base=CoinMetaBase)

__all__ = ['Coin']
2 changes: 2 additions & 0 deletions zvt/domain/meta/stock_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,5 @@ class StockDetail(StockMetaBase, EntityMixin):

register_schema(providers=['eastmoney', 'exchange', 'sina', 'joinquant'], db_name='stock_meta',
schema_base=StockMetaBase)

__all__ = ['Stock', 'Index', 'Block', 'Etf', 'IndexStock', 'BlockStock', 'EtfStock', 'StockDetail']
4 changes: 4 additions & 0 deletions zvt/domain/misc/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
from zvt.domain.misc.holder import *
from zvt.domain.misc.money_flow import *
from zvt.domain.misc.overall import *
4 changes: 3 additions & 1 deletion zvt/domain/holder.py → zvt/domain/misc/holder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from sqlalchemy import Column, String, DateTime, Float
from sqlalchemy.ext.declarative import declarative_base

from zvdata.contract import register_schema, register_api
from zvdata import Mixin
from zvdata.contract import register_schema, register_api

HolderBase = declarative_base()

Expand Down Expand Up @@ -79,3 +79,5 @@ class InstitutionalInvestorHolder(HolderBase, Mixin):


register_schema(providers=['eastmoney'], db_name='holder', schema_base=HolderBase)

__all__ = ['TopTenTradableHolder', 'TopTenHolder', 'InstitutionalInvestorHolder']
6 changes: 4 additions & 2 deletions zvt/domain/money_flow.py → zvt/domain/misc/money_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

# 板块资金流向
@register_api(provider='sina')
class IndexMoneyFlow(MoneyFlowBase, Mixin):
__tablename__ = 'index_money_flow'
class BlockMoneyFlow(MoneyFlowBase, Mixin):
__tablename__ = 'block_money_flow'

code = Column(String(length=32))
name = Column(String(length=32))
Expand Down Expand Up @@ -80,3 +80,5 @@ class StockMoneyFlow(MoneyFlowBase, Mixin):


register_schema(providers=['sina'], db_name='money_flow', schema_base=MoneyFlowBase)

__all__ = ['BlockMoneyFlow', 'StockMoneyFlow']
14 changes: 8 additions & 6 deletions zvt/domain/macro.py → zvt/domain/misc/overall.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
from sqlalchemy import Column, String, Float
from sqlalchemy.ext.declarative import declarative_base

from zvdata.contract import register_schema, register_api
from zvdata import Mixin
from zvdata.contract import register_schema, register_api

MacroBase = declarative_base()
OverallBase = declarative_base()


# 市场整体估值
@register_api(provider='joinquant')
class StockSummary(MacroBase, Mixin):
class StockSummary(OverallBase, Mixin):
__tablename__ = 'stock_summary'

provider = Column(String(length=32))
Expand All @@ -28,7 +28,7 @@ class StockSummary(MacroBase, Mixin):

# 融资融券概况
@register_api(provider='joinquant')
class MarginTradingSummary(MacroBase, Mixin):
class MarginTradingSummary(OverallBase, Mixin):
__tablename__ = 'margin_trading_summary'
provider = Column(String(length=32))
code = Column(String(length=32))
Expand All @@ -50,7 +50,7 @@ class MarginTradingSummary(MacroBase, Mixin):

# 北向/南向成交概况
@register_api(provider='joinquant')
class CrossMarketSummary(MacroBase, Mixin):
class CrossMarketSummary(OverallBase, Mixin):
__tablename__ = 'cross_market_summary'
provider = Column(String(length=32))
code = Column(String(length=32))
Expand All @@ -64,4 +64,6 @@ class CrossMarketSummary(MacroBase, Mixin):
quota_daily_balance = Column(Float)


register_schema(providers=['exchange', 'joinquant'], db_name='macro', schema_base=MacroBase)
register_schema(providers=['exchange', 'joinquant'], db_name='overall', schema_base=OverallBase)

__all__ = ['StockSummary', 'MarginTradingSummary', 'CrossMarketSummary']
42 changes: 23 additions & 19 deletions zvt/domain/quotes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,26 @@ class TickCommon(Mixin):
order_type = Column(String(length=32))


from zvt.domain.quotes.coin.coin_tick_kdata import *
from zvt.domain.quotes.coin.coin_1m_kdata import *
from zvt.domain.quotes.coin.coin_1h_kdata import *
from zvt.domain.quotes.coin.coin_1d_kdata import *
from zvt.domain.quotes.coin.coin_1wk_kdata import *
from zvt.domain.quotes.coin.coin_1mon_kdata import *

from zvt.domain.quotes.index.index_1d_kdata import *
from zvt.domain.quotes.index.index_1wk_kdata import *
from zvt.domain.quotes.index.index_1mon_kdata import *

from zvt.domain.quotes.stock.stock_1m_kdata import *
from zvt.domain.quotes.stock.stock_5m_kdata import *
from zvt.domain.quotes.stock.stock_15m_kdata import *
from zvt.domain.quotes.stock.stock_30m_kdata import *
from zvt.domain.quotes.stock.stock_1h_kdata import *
from zvt.domain.quotes.stock.stock_1d_kdata import *
from zvt.domain.quotes.stock.stock_1wk_kdata import *
from zvt.domain.quotes.stock.stock_1mon_kdata import *
class BlockKdataCommon(KdataCommon):
pass


class CoinKdataCommon(KdataCommon):
pass


class CoinTickCommon(TickCommon):
pass


class StockKdataCommon(KdataCommon):
# 涨跌幅
change_pct = Column(Float)
# 换手率
turnover_rate = Column(Float)


from zvt.domain.quotes.block import *
from zvt.domain.quotes.coin import *
from zvt.domain.quotes.stock import *
from zvt.domain.quotes.trade_day import *
5 changes: 5 additions & 0 deletions zvt/domain/quotes/block/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# this file is generated by gen_quote_domain function, dont't change it
from zvt.domain.quotes.block.block_1d_kdata import *
from zvt.domain.quotes.block.block_1wk_kdata import *
from zvt.domain.quotes.block.block_1mon_kdata import *
17 changes: 17 additions & 0 deletions zvt/domain/quotes/block/block_1d_kdata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
# this file is generated by gen_quote_domain function, dont't change it
from sqlalchemy.ext.declarative import declarative_base

from zvdata.contract import register_schema
from zvt.domain.quotes import BlockKdataCommon

KdataBase = declarative_base()


class Block1dKdata(KdataBase, BlockKdataCommon):
__tablename__ = 'block_1d_kdata'


register_schema(providers=['eastmoney'], db_name='block_1d_kdata', schema_base=KdataBase)

__all__ = ['Block1dKdata']
17 changes: 17 additions & 0 deletions zvt/domain/quotes/block/block_1mon_kdata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
# this file is generated by gen_quote_domain function, dont't change it
from sqlalchemy.ext.declarative import declarative_base

from zvdata.contract import register_schema
from zvt.domain.quotes import BlockKdataCommon

KdataBase = declarative_base()


class Block1monKdata(KdataBase, BlockKdataCommon):
__tablename__ = 'block_1mon_kdata'


register_schema(providers=['eastmoney'], db_name='block_1mon_kdata', schema_base=KdataBase)

__all__ = ['Block1monKdata']
17 changes: 17 additions & 0 deletions zvt/domain/quotes/block/block_1wk_kdata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
# this file is generated by gen_quote_domain function, dont't change it
from sqlalchemy.ext.declarative import declarative_base

from zvdata.contract import register_schema
from zvt.domain.quotes import BlockKdataCommon

KdataBase = declarative_base()


class Block1wkKdata(KdataBase, BlockKdataCommon):
__tablename__ = 'block_1wk_kdata'


register_schema(providers=['eastmoney'], db_name='block_1wk_kdata', schema_base=KdataBase)

__all__ = ['Block1wkKdata']
20 changes: 11 additions & 9 deletions zvt/domain/quotes/coin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# -*- coding: utf-8 -*-
from zvt.domain.quotes import KdataCommon, TickCommon


class CoinKdataCommon(KdataCommon):
pass


class CoinTickCommon(TickCommon):
pass
# this file is generated by gen_quote_domain function, dont't change it
from zvt.domain.quotes.coin.coin_tick_kdata import *
from zvt.domain.quotes.coin.coin_1m_kdata import *
from zvt.domain.quotes.coin.coin_5m_kdata import *
from zvt.domain.quotes.coin.coin_15m_kdata import *
from zvt.domain.quotes.coin.coin_30m_kdata import *
from zvt.domain.quotes.coin.coin_1h_kdata import *
from zvt.domain.quotes.coin.coin_4h_kdata import *
from zvt.domain.quotes.coin.coin_1d_kdata import *
from zvt.domain.quotes.coin.coin_1wk_kdata import *
from zvt.domain.quotes.coin.coin_1mon_kdata import *
11 changes: 7 additions & 4 deletions zvt/domain/quotes/coin/coin_1d_kdata.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# -*- coding: utf-8 -*-
# this file is generated by gen_quote_domain function, dont't change it
from sqlalchemy.ext.declarative import declarative_base

from zvdata.contract import register_schema
from zvt.domain.quotes.coin import CoinKdataCommon
from zvt.domain.quotes import CoinKdataCommon

Coin1dKdataBase = declarative_base()
KdataBase = declarative_base()


class Coin1dKdata(Coin1dKdataBase, CoinKdataCommon):
class Coin1dKdata(KdataBase, CoinKdataCommon):
__tablename__ = 'coin_1d_kdata'


register_schema(providers=['ccxt'], db_name='coin_1d_kdata', schema_base=Coin1dKdataBase)
register_schema(providers=['ccxt'], db_name='coin_1d_kdata', schema_base=KdataBase)

__all__ = ['Coin1dKdata']
Loading

0 comments on commit 7840587

Please sign in to comment.