Skip to content

Commit

Permalink
fixed
Browse files Browse the repository at this point in the history
v-2.5.4
market index bug
  • Loading branch information
1nchaos committed Jul 31, 2024
1 parent f33751a commit 816bbae
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion adata/__version__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

VERSION = (2, 5, 3)
VERSION = (2, 5, 4)
PRERELEASE = None # alpha, beta or rc
REVISION = None

Expand Down
4 changes: 3 additions & 1 deletion adata/stock/info/stock_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ def __index_constituent_baidu(self, index_code=None):
result_df = pd.DataFrame(data=data).rename(columns={'code': 'stock_code', 'name': 'short_name'})
result_df['index_code'] = index_code
data.clear()
return result_df[self.__INDEX_CONSTITUENT_COLUMN]
result_df = result_df[self.__INDEX_CONSTITUENT_COLUMN]
result_df = result_df.drop_duplicates()
return result_df

def __index_constituent_sina(self, index_code=None, wait_time=None):
"""
Expand Down
2 changes: 2 additions & 0 deletions adata/stock/market/index_market/market_index_east.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ def get_market_index_current(self, index_code: str = '000001'):
result_df['change_pct'] = result_df['change'] / pre_close * 100
result_df = result_df.round(2)
result_df['trade_time'] = datetime.datetime.now()
result_df[['open', 'high', 'low', 'price', 'change']] = \
result_df[['open', 'high', 'low', 'price', 'change']].astype(float) / 100
return result_df


Expand Down
14 changes: 7 additions & 7 deletions adata/stock/market/stock_market/stock_market_east.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"""

import pandas as pd
from adata.common.exception.handler import handler_null

from adata.common.exception.handler import handler_null
from adata.common.utils import requests
from adata.common.utils.date_utils import get_cur_time
from adata.stock.market.stock_market.stock_market_template import StockMarketTemplate
Expand Down Expand Up @@ -39,7 +39,7 @@ def get_market(self, stock_code: str = '000001', start_date='1990-01-01', end_da
se_cid = 1 if stock_code.startswith('6') else 0
start_date = start_date.replace('-', '') if start_date else '19900101'
end_date = end_date.replace('-', '') if end_date else get_cur_time("%Y%m%d")
k_type = f"10{k_type}" if k_type < 5 else k_type
k_type = f"10{k_type}" if int(k_type) < 5 else k_type
params = {"fields1": "f1,f2,f3,f4,f5,f6",
"fields2": "f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61,f116",
"ut": "7eea3edcaed734bea9cbfc24409ed989",
Expand All @@ -64,16 +64,16 @@ def get_market(self, stock_code: str = '000001', start_date='1990-01-01', end_da
'', "change_pct", "change", "turnover_ratio"])
# 4.清洗数据
df['pre_close'] = df['close'].astype(float) - df['change'].astype(float)
df['pre_close'] = df['pre_close'].round(2)
df['trade_time'] = pd.to_datetime(df['trade_date']).dt.strftime('%Y-%m-%d %H:%M:%S')
df['trade_date'] = pd.to_datetime(df['trade_date']).dt.strftime('%Y-%m-%d')
df['stock_code'] = stock_code
numeric_columns = ['open', 'close', 'volume', 'high', 'low', 'amount', 'change', 'change_pct',
'turnover_ratio', 'pre_close']
df[numeric_columns] = df[numeric_columns].apply(pd.to_numeric)
df.reset_index(inplace=True, drop=True)
return df[
['trade_time', "trade_date", "open", "close", "high", "low", "volume", "amount", "change_pct", "change",
"turnover_ratio", "pre_close"]]
return df[['stock_code', 'trade_time', "trade_date", "open", "close", "high", "low", "volume", "amount",
"change_pct", "change", "turnover_ratio", "pre_close"]]

@handler_null
def get_market_min(self, stock_code: str = '000001'):
Expand Down Expand Up @@ -114,12 +114,12 @@ def get_market_min(self, stock_code: str = '000001'):
df[numeric_columns] = df[numeric_columns].apply(pd.to_numeric)

df['change'] = df['price'] - pre_close
df['change_pct'] = df['change'] / pre_close*100
df['change_pct'] = df['change'] / pre_close * 100
df['change_pct'] = df['change_pct'].round(2)
df.reset_index(drop=True, inplace=True)
return df[self._MARKET_MIN_COLUMNS]


if __name__ == '__main__':
print(StockMarketEast().get_market(stock_code='600020', k_type=1, adjust_type=1))
print(StockMarketEast().get_market_min(stock_code='600020'))
# print(StockMarketEast().get_market_min(stock_code='600020'))

0 comments on commit 816bbae

Please sign in to comment.