Skip to content
Permalink
Browse files

add name to money_flow data

  • Loading branch information...
foolcage committed Sep 6, 2019
1 parent 044206f commit fe7a89e5f3e8a7a5c248a856cf8219bedf9f38d3
BIN +7.2 MB (120%) datasample.zip
Binary file not shown.
@@ -16,6 +16,6 @@ def test_basic_get_securities():


def test_get_security_blocks():
hs300 = get_securities_in_blocks(block_names=['HS300_'])
hs300 = get_securities_in_blocks(names=['HS300_'])
assert len(hs300) == 300
assert 'stock_sz_000338' in hs300
@@ -6,13 +6,25 @@
from zvdata.domain import get_db_session
from zvt.accounts.ccxt_account import CCXTAccount
from zvt.api.common import get_kdata_schema
from zvt.domain import StockCategory
from zvt.domain import StockCategory, IndexMoneyFlow
from zvt.domain.stock_meta import Index


def get_indices(provider: str = 'sina',
block_category: Union[str, StockCategory] = 'concept',
return_type: str = 'df') -> object:
"""
get indices/blocks on block_category
:param provider:
:type provider:
:param block_category:
:type block_category:
:param return_type:
:type return_type:
:return:
:rtype:
"""
if type(block_category) == StockCategory:
block_category = block_category.value

@@ -27,17 +39,33 @@ def get_indices(provider: str = 'sina',
get_blocks = get_indices


def get_securities_in_blocks(block_names=['HS300_'], block_category='concept', provider='eastmoney'):
def get_securities_in_blocks(provider='eastmoney',
block_category: Union[str, StockCategory] = 'concept',
names=['HS300_'], codes=None):
session = get_db_session(provider=provider, data_schema=Index)

filters = [Index.category == block_category]

# add name filters
name_filters = None
for block_name in block_names:
if name_filters:
name_filters |= (Index.name == block_name)
else:
name_filters = (Index.name == block_name)
if names:
for block_name in names:
if name_filters:
name_filters |= (Index.name == block_name)
else:
name_filters = (Index.name == block_name)
filters.append(name_filters)

# add code filters
code_filters = None
if codes:
for code in codes:
if code_filters:
code_filters |= (Index.code == code)
else:
code_filters = (Index.code == code)
filters.append(name_filters)

blocks = get_entities(entity_type='index', provider='eastmoney',
filters=filters, return_type='domain', session=session)
securities = []
@@ -82,4 +110,16 @@ def get_current_price(entity_ids=None, entity_type='coin'):


if __name__ == '__main__':
get_entities(provider='linkedin', entity_type='user', limit=10)
money_flow_session = get_db_session(provider='sina', data_schema=IndexMoneyFlow)

entities = get_entities(entity_type='index',
return_type='domain', provider='sina',
# 只抓概念和行业
filters=[Index.category.in_(
[StockCategory.industry.value, StockCategory.concept.value])])

for entity in entities:
sql = 'UPDATE index_money_flow SET name="{}" where code="{}"'.format(
entity.name, entity.code)
money_flow_session.execute(sql)
money_flow_session.commit()
@@ -2,8 +2,8 @@
from sqlalchemy import Column, String, Float
from sqlalchemy.ext.declarative import declarative_base

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

MoneyFlowBase = declarative_base()

@@ -5,14 +5,14 @@
import requests
from jqdatasdk import auth, get_price, logout

from zvdata.recorder import FixedCycleDataRecorder
from zvdata import IntervalLevel
from zvdata.recorder import FixedCycleDataRecorder
from zvdata.utils import utils
from zvdata.utils.time_utils import to_time_str, TIME_FORMAT_DAY1, now_time_str, to_pd_timestamp
from zvt.api.common import generate_kdata_id, to_jq_entity_id
from zvt.api.quote import get_kdata
from zvt.domain import Stock1dKdata, Stock
from zvt.settings import JQ_ACCOUNT, JQ_PASSWD
from zvt.utils import utils
from zvdata.utils.time_utils import to_time_str, TIME_FORMAT_DAY1, now_time_str, to_pd_timestamp


class ChinaStockDayKdataRecorder(FixedCycleDataRecorder):
@@ -3,13 +3,13 @@

import requests

from zvdata import IntervalLevel
from zvdata.domain import get_db_session
from zvdata.recorder import FixedCycleDataRecorder
from zvdata import IntervalLevel
from zvt.api.quote import get_entities
from zvt.domain import IndexMoneyFlow, StockCategory, Index
from zvdata.utils.time_utils import to_pd_timestamp
from zvdata.utils.utils import to_float
from zvt.api.quote import get_entities
from zvt.domain import IndexMoneyFlow, StockCategory, Index


# 实时资金流
@@ -86,6 +86,7 @@ def record(self, entity, start, end, size, timestamps):
result_list = []
for item in json_list:
result_list.append({
'name': entity.name,
'timestamp': to_pd_timestamp(item['opendate']),
'close': to_float(item['avg_price']),
'change_pct': to_float(item['avg_changeratio']),

0 comments on commit fe7a89e

Please sign in to comment.
You can’t perform that action at this time.