-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1)realtime reader/factor/selector/trader preview 2)dash ui 3)domain u…
…i composer 4)core logic tests * the docs and data would come soon Former-commit-id: c8ed9a4
- Loading branch information
Showing
51 changed files
with
3,245 additions
and
858 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# -*- coding: utf-8 -*- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from ..context import init_context | ||
|
||
init_context() | ||
|
||
from zvt.api import fundamental | ||
from zvt.domain import get_db_session, StoreCategory, Provider, SPODetail, RightsIssueDetail, DividendFinancing | ||
from zvt.utils.time_utils import to_pd_timestamp | ||
|
||
session = get_db_session(provider='eastmoney', | ||
store_category=StoreCategory.dividend_financing) # type: sqlalchemy.orm.Session | ||
|
||
|
||
# 增发详情 | ||
def test_000778_spo_detial(): | ||
result = fundamental.get_spo_detail(session=session, provider=Provider.EASTMONEY, return_type='domain', | ||
codes=['000778'], end_timestamp='2018-09-30', | ||
order=SPODetail.timestamp.desc()) | ||
assert len(result) == 4 | ||
latest: SPODetail = result[0] | ||
assert latest.timestamp == to_pd_timestamp('2017-04-01') | ||
assert latest.spo_issues == 347600000 | ||
assert latest.spo_price == 5.15 | ||
assert latest.spo_raising_fund == 1766000000 | ||
|
||
|
||
# 配股详情 | ||
def test_000778_rights_issue_detail(): | ||
result = fundamental.get_rights_issue_detail(session=session, provider=Provider.EASTMONEY, return_type='domain', | ||
codes=['000778'], end_timestamp='2018-09-30', | ||
order=RightsIssueDetail.timestamp.desc()) | ||
assert len(result) == 2 | ||
latest: RightsIssueDetail = result[0] | ||
assert latest.timestamp == to_pd_timestamp('2001-09-10') | ||
assert latest.rights_issues == 43570000 | ||
assert latest.rights_raising_fund == 492300000 | ||
assert latest.rights_issue_price == 11.3 | ||
|
||
|
||
# 分红融资 | ||
def test_000778_dividend_financing(): | ||
result = fundamental.get_dividend_financing(session=session, provider=Provider.EASTMONEY, return_type='domain', | ||
codes=['000778'], end_timestamp='2018-09-30', | ||
order=DividendFinancing.timestamp.desc()) | ||
assert len(result) == 22 | ||
latest: DividendFinancing = result[1] | ||
assert latest.timestamp == to_pd_timestamp('2017') | ||
assert latest.dividend_money == 598632026.4 | ||
assert latest.spo_issues == 347572815.0 | ||
assert latest.rights_issues == 0 | ||
assert latest.ipo_issues == 0 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from ..context import init_context | ||
|
||
init_context() | ||
|
||
from typing import List | ||
|
||
from zvt.api import fundamental | ||
from zvt.domain import get_db_session, StoreCategory, Provider, TopTenHolder, TopTenTradableHolder | ||
|
||
session = get_db_session(provider='eastmoney', store_category=StoreCategory.holder) # type: sqlalchemy.orm.Session | ||
|
||
|
||
# 十大股东 | ||
def test_000778_top_ten_holder(): | ||
result: List[TopTenHolder] = fundamental.get_top_ten_holder(session=session, provider=Provider.EASTMONEY, | ||
return_type='domain', | ||
codes=['000778'], end_timestamp='2018-09-30', | ||
start_timestamp='2018-09-30', | ||
order=TopTenHolder.shareholding_ratio.desc()) | ||
assert len(result) == 10 | ||
assert result[0].holder_name == '新兴际华集团有限公司' | ||
assert result[0].shareholding_numbers == 1595000000 | ||
assert result[0].shareholding_ratio == 0.3996 | ||
assert result[0].change == 32080000 | ||
assert result[0].change_ratio == 0.0205 | ||
|
||
|
||
def test_000778_top_ten_tradable_holder(): | ||
result: List[TopTenHolder] = fundamental.get_top_ten_tradable_holder(session=session, provider=Provider.EASTMONEY, | ||
return_type='domain', | ||
codes=['000778'], end_timestamp='2018-09-30', | ||
start_timestamp='2018-09-30', | ||
order=TopTenTradableHolder.shareholding_ratio.desc()) | ||
assert len(result) == 10 | ||
assert result[0].holder_name == '新兴际华集团有限公司' | ||
assert result[0].shareholding_numbers == 1525000000 | ||
assert result[0].shareholding_ratio == 0.389 | ||
assert result[0].change == 38560000 | ||
assert result[0].change_ratio == 0.0259 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from ..context import init_context | ||
|
||
init_context() | ||
|
||
from zvt.api import technical | ||
from zvt.domain import get_db_session, StoreCategory, TradingLevel | ||
|
||
day_k_session = get_db_session(provider='joinquant', | ||
store_category=StoreCategory.stock_1d_kdata) # type: sqlalchemy.orm.Session | ||
|
||
day_1h_session = get_db_session(provider='joinquant', | ||
store_category=StoreCategory.stock_1h_kdata) # type: sqlalchemy.orm.Session | ||
|
||
|
||
def test_jq_603220_kdata(): | ||
df = technical.get_kdata(security_id='stock_sh_603220', session=day_k_session, level=TradingLevel.LEVEL_1DAY, | ||
provider='joinquant') | ||
print(df) | ||
df = technical.get_kdata(security_id='stock_sh_603220', session=day_1h_session, level=TradingLevel.LEVEL_1HOUR, | ||
provider='joinquant') | ||
print(df) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
# -*- coding: utf-8 -*- | ||
from ..context import init_context | ||
|
||
init_context() | ||
|
||
from zvt.api.rules import coin_finished_timestamp, iterate_timestamps, is_open_time, is_close_time, \ | ||
is_in_finished_timestamps | ||
from zvt.domain import TradingLevel, SecurityType | ||
from zvt.utils.time_utils import is_same_time | ||
|
||
|
||
def test_is_open_close_time(): | ||
timestamps = iterate_timestamps(security_type=SecurityType.coin, exchange='binance', | ||
level=TradingLevel.LEVEL_1MIN, start_timestamp='2019-05-01', | ||
end_timestamp='2019-05-01') | ||
assert is_open_time(security_type=SecurityType.coin, exchange='binance', timestamp=timestamps[0]) | ||
assert is_close_time(security_type=SecurityType.coin, exchange='binance', timestamp=timestamps[-1]) | ||
|
||
timestamps = iterate_timestamps(security_type=SecurityType.coin, exchange='binance', | ||
level=TradingLevel.LEVEL_5MIN, start_timestamp='2019-05-01', | ||
end_timestamp='2019-05-01') | ||
assert is_open_time(security_type=SecurityType.coin, exchange='binance', timestamp=timestamps[0]) | ||
assert is_close_time(security_type=SecurityType.coin, exchange='binance', timestamp=timestamps[-1]) | ||
|
||
timestamps = iterate_timestamps(security_type=SecurityType.coin, exchange='binance', | ||
level=TradingLevel.LEVEL_5MIN, start_timestamp='2019-05-01', | ||
end_timestamp='2019-05-02') | ||
open = [] | ||
close = [] | ||
for timestamp in timestamps: | ||
if is_open_time(security_type=SecurityType.coin, exchange='binance', timestamp=timestamp): | ||
open.append(timestamp) | ||
if is_close_time(security_type=SecurityType.coin, exchange='binance', timestamp=timestamp): | ||
close.append(timestamp) | ||
assert len(open) == 3 | ||
assert len(close) == 3 | ||
|
||
|
||
def test_iterate_coin_timestamps(): | ||
timestamps = iterate_timestamps(security_type=SecurityType.coin, exchange='binance', | ||
level=TradingLevel.LEVEL_1HOUR, start_timestamp='2019-05-01', | ||
end_timestamp='2019-05-02') | ||
assert is_same_time(timestamps[0], '2019-05-01 00:00:00') | ||
assert is_same_time(timestamps[-1], '2019-05-03 00:00:00') | ||
|
||
timestamps = iterate_timestamps(security_type=SecurityType.coin, exchange='binance', | ||
level=TradingLevel.LEVEL_5MIN, start_timestamp='2019-05-01', | ||
end_timestamp='2019-05-02') | ||
assert is_same_time(timestamps[0], '2019-05-01 00:00:00') | ||
assert is_same_time(timestamps[-1], '2019-05-03 00:00:00') | ||
|
||
|
||
def test_iterate_stock_timestamps(): | ||
timestamps = iterate_timestamps(security_type=SecurityType.stock, exchange='sh', | ||
level=TradingLevel.LEVEL_1HOUR, start_timestamp='2019-05-01', | ||
end_timestamp='2019-05-02') | ||
assert is_same_time(timestamps[0], '2019-05-01 09:30:00') | ||
assert is_same_time(timestamps[-1], '2019-05-02 15:00:00') | ||
|
||
timestamps = iterate_timestamps(security_type=SecurityType.stock, exchange='sh', | ||
level=TradingLevel.LEVEL_5MIN, start_timestamp='2019-05-01', | ||
end_timestamp='2019-05-02') | ||
assert is_same_time(timestamps[0], '2019-05-01 09:30:00') | ||
assert is_same_time(timestamps[-1], '2019-05-02 15:00:00') | ||
|
||
timestamps = iterate_timestamps(security_type=SecurityType.stock, exchange='sh', | ||
level=TradingLevel.LEVEL_1HOUR, start_timestamp='2019-05-01', | ||
end_timestamp='2019-05-02', contain_all_timestamp=False) | ||
assert is_same_time(timestamps[0], '2019-05-01 10:30:00') | ||
assert is_same_time(timestamps[-1], '2019-05-02 15:00:00') | ||
|
||
timestamps = iterate_timestamps(security_type=SecurityType.stock, exchange='sh', | ||
level=TradingLevel.LEVEL_5MIN, start_timestamp='2019-05-01', | ||
end_timestamp='2019-05-02', contain_all_timestamp=False) | ||
assert is_same_time(timestamps[0], '2019-05-01 09:35:00') | ||
assert is_same_time(timestamps[-1], '2019-05-02 15:00:00') | ||
|
||
|
||
def test_coin_finished_timestamp(): | ||
assert coin_finished_timestamp('1999-01-01 00:00:00', level=TradingLevel.LEVEL_1MIN) | ||
assert coin_finished_timestamp('1999-01-01 00:00:00', level=TradingLevel.LEVEL_5MIN) | ||
assert coin_finished_timestamp('1999-01-01 00:00:00', level=TradingLevel.LEVEL_15MIN) | ||
assert coin_finished_timestamp('1999-01-01 00:00:00', level=TradingLevel.LEVEL_30MIN) | ||
assert coin_finished_timestamp('1999-01-01 00:00:00', level=TradingLevel.LEVEL_1HOUR) | ||
assert coin_finished_timestamp('1999-01-01 00:00:00', level=TradingLevel.LEVEL_1DAY) | ||
|
||
assert coin_finished_timestamp('1999-01-01 00:01:00', level=TradingLevel.LEVEL_1MIN) | ||
assert not coin_finished_timestamp('1999-01-01 00:01:00', level=TradingLevel.LEVEL_5MIN) | ||
assert not coin_finished_timestamp('1999-01-01 00:01:00', level=TradingLevel.LEVEL_15MIN) | ||
assert not coin_finished_timestamp('1999-01-01 00:01:00', level=TradingLevel.LEVEL_30MIN) | ||
assert not coin_finished_timestamp('1999-01-01 00:01:00', level=TradingLevel.LEVEL_1HOUR) | ||
assert not coin_finished_timestamp('1999-01-01 00:01:00', level=TradingLevel.LEVEL_1DAY) | ||
|
||
assert coin_finished_timestamp('1999-01-01 00:05:00', level=TradingLevel.LEVEL_1MIN) | ||
assert coin_finished_timestamp('1999-01-01 00:05:00', level=TradingLevel.LEVEL_5MIN) | ||
assert not coin_finished_timestamp('1999-01-01 00:05:00', level=TradingLevel.LEVEL_15MIN) | ||
assert not coin_finished_timestamp('1999-01-01 00:05:00', level=TradingLevel.LEVEL_30MIN) | ||
assert not coin_finished_timestamp('1999-01-01 00:05:00', level=TradingLevel.LEVEL_1HOUR) | ||
assert not coin_finished_timestamp('1999-01-01 00:05:00', level=TradingLevel.LEVEL_1DAY) | ||
|
||
assert coin_finished_timestamp('1999-01-01 00:15:00', level=TradingLevel.LEVEL_1MIN) | ||
assert coin_finished_timestamp('1999-01-01 00:15:00', level=TradingLevel.LEVEL_5MIN) | ||
assert coin_finished_timestamp('1999-01-01 00:15:00', level=TradingLevel.LEVEL_15MIN) | ||
assert not coin_finished_timestamp('1999-01-01 00:15:00', level=TradingLevel.LEVEL_30MIN) | ||
assert not coin_finished_timestamp('1999-01-01 00:15:00', level=TradingLevel.LEVEL_1HOUR) | ||
assert not coin_finished_timestamp('1999-01-01 00:15:00', level=TradingLevel.LEVEL_1DAY) | ||
|
||
assert coin_finished_timestamp('1999-01-01 00:30:00', level=TradingLevel.LEVEL_1MIN) | ||
assert coin_finished_timestamp('1999-01-01 00:30:00', level=TradingLevel.LEVEL_5MIN) | ||
assert coin_finished_timestamp('1999-01-01 00:30:00', level=TradingLevel.LEVEL_15MIN) | ||
assert coin_finished_timestamp('1999-01-01 00:30:00', level=TradingLevel.LEVEL_30MIN) | ||
assert not coin_finished_timestamp('1999-01-01 00:30:00', level=TradingLevel.LEVEL_1HOUR) | ||
assert not coin_finished_timestamp('1999-01-01 00:30:00', level=TradingLevel.LEVEL_1DAY) | ||
|
||
assert coin_finished_timestamp('1999-01-01 00:45:00', level=TradingLevel.LEVEL_1MIN) | ||
assert coin_finished_timestamp('1999-01-01 00:45:00', level=TradingLevel.LEVEL_5MIN) | ||
assert coin_finished_timestamp('1999-01-01 00:45:00', level=TradingLevel.LEVEL_15MIN) | ||
assert not coin_finished_timestamp('1999-01-01 00:45:00', level=TradingLevel.LEVEL_30MIN) | ||
assert not coin_finished_timestamp('1999-01-01 00:45:00', level=TradingLevel.LEVEL_1HOUR) | ||
assert not coin_finished_timestamp('1999-01-01 00:45:00', level=TradingLevel.LEVEL_1DAY) | ||
|
||
|
||
def test_is_in_finished_timestamps(): | ||
assert is_in_finished_timestamps(security_type=SecurityType.stock, exchange='sh', timestamp='1999-01-01', | ||
level=TradingLevel.LEVEL_1DAY) | ||
assert is_in_finished_timestamps(security_type=SecurityType.stock, exchange='sh', timestamp='1999-01-01 15:00', | ||
level=TradingLevel.LEVEL_1DAY) | ||
assert not is_in_finished_timestamps(security_type=SecurityType.stock, exchange='sh', timestamp='1999-01-01 14:00', | ||
level=TradingLevel.LEVEL_1DAY) | ||
|
||
assert is_in_finished_timestamps(security_type=SecurityType.stock, exchange='sh', timestamp='1999-01-01 09:31', | ||
level=TradingLevel.LEVEL_1MIN) | ||
assert not is_in_finished_timestamps(security_type=SecurityType.stock, exchange='sh', timestamp='1999-01-01 09:30', | ||
level=TradingLevel.LEVEL_1MIN) | ||
|
||
assert not is_in_finished_timestamps(security_type=SecurityType.stock, exchange='sh', timestamp='1999-01-01 08:30', | ||
level=TradingLevel.LEVEL_1MIN) | ||
|
||
assert is_in_finished_timestamps(security_type=SecurityType.stock, exchange='sh', timestamp='1999-01-01 11:30', | ||
level=TradingLevel.LEVEL_1MIN) | ||
assert is_in_finished_timestamps(security_type=SecurityType.stock, exchange='sh', timestamp='1999-01-01 11:30', | ||
level=TradingLevel.LEVEL_5MIN) | ||
assert is_in_finished_timestamps(security_type=SecurityType.stock, exchange='sh', timestamp='1999-01-01 11:30', | ||
level=TradingLevel.LEVEL_15MIN) | ||
assert is_in_finished_timestamps(security_type=SecurityType.stock, exchange='sh', timestamp='1999-01-01 11:30', | ||
level=TradingLevel.LEVEL_30MIN) | ||
assert is_in_finished_timestamps(security_type=SecurityType.stock, exchange='sh', timestamp='1999-01-01 11:30', | ||
level=TradingLevel.LEVEL_1HOUR) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from ..context import init_context | ||
|
||
init_context() | ||
|
||
from typing import List | ||
|
||
from zvt.api import fundamental | ||
from zvt.domain import get_db_session, StoreCategory, Provider, HolderTrading, ManagerTrading | ||
|
||
session = get_db_session(provider='eastmoney', store_category=StoreCategory.trading) # type: sqlalchemy.orm.Session | ||
|
||
|
||
# 股东交易 | ||
def test_000778_holder_trading(): | ||
result: List[HolderTrading] = fundamental.get_holder_trading(session=session, provider=Provider.EASTMONEY, | ||
return_type='domain', | ||
codes=['000778'], | ||
end_timestamp='2018-09-30', | ||
start_timestamp='2018-09-30', | ||
order=HolderTrading.holding_pct.desc()) | ||
assert len(result) == 6 | ||
assert result[0].holder_name == '新兴际华集团有限公司' | ||
assert result[0].change_pct == 0.0205 | ||
assert result[0].volume == 32080000 | ||
assert result[0].holding_pct == 0.3996 | ||
|
||
|
||
# 高管交易 | ||
def test_000778_manager_trading(): | ||
result: List[ManagerTrading] = fundamental.get_manager_trading(session=session, provider=Provider.EASTMONEY, | ||
return_type='domain', | ||
codes=['000778'], | ||
end_timestamp='2018-09-30', | ||
start_timestamp='2017-09-30', | ||
order=ManagerTrading.holding.desc()) | ||
assert len(result) == 1 | ||
assert result[0].trading_person == '巩国平' | ||
assert result[0].volume == 8400 | ||
assert result[0].price == None | ||
assert result[0].holding == 18700 | ||
assert result[0].trading_way == '增持' | ||
assert result[0].manager_position == '职工监事' | ||
assert result[0].manager == '巩国平' | ||
assert result[0].relationship_with_manager == '本人' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
# -*- coding: utf-8 -*- | ||
# -*- coding: utf-8 -*-\ | ||
|
||
|
||
def init_context(): | ||
import os | ||
import sys | ||
|
||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) | ||
from zvt import settings | ||
settings.DATA_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'datasample')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# -*- coding: utf-8 -*- |
Oops, something went wrong.