o
    ib                     @   s   d Z ddlmZ ddlmZ ddlZddlmZmZ dededefd	d
Z	dedeeffddZ
dedefddZdedefddZdS )u9   
# 作 者：84028
# 时 间：2024/2/28 21:09
# tsdpsdk
    )datetime)AnyN)TsTick	TsTickIdx_type_codereturnc                 C   sJ   | t jjkr| dS | t jjkr| dS | t jjkr!| dS td)Nz.BJz.SHz.SZu?   未知类型，请联系管理员添加对应数据的解析！)tgw
MarketTypekNEEQkSSEkSZSE	Exception)r   r    r   P/opt/alphahud/venv/lib/python3.10/site-packages/tushare/subs/tgw_subs/convert.pyget_ts_code   s   


r   c                 C   sb   |  dd\} }| }|dkrtjj| fS |dkr tjj| fS |dkr*tjj| fS td| )N.   BJSHSZuA   未知类型，请联系管理员添加对应数据的解析！--)splitupperr	   r
   r   r   r   r   )r   _extr   r   r   get_tgw_type_and_code   s   r   tgw_datac                 C   s   t t| d| ddtt| ddd d| dd | d	d | d
d | dd | dd | dd | dd | dd d}|S )u  
    index_demo = {
        'market_type': 101,
        'security_code': '000300',
        'orig_time': 20240227133145220, # 交易所行情数据时间
        'trading_phase_code': '',
        'pre_close_index': 3453358500,
        'open_index': 3440051600,
        'high_index': 3483385500,
        'low_index': 3437442200,
        'last_index': 3474362400,
        'close_index': 0,
        'total_volume_trade': 8934304600,
        'total_value_trade': 15930131603140000,
        'variety_category': 5
    }
    market_typesecurity_codeN	orig_time%Y%m%d%H%M%S
last_index@B pre_close_index
open_index
high_index	low_indexclose_indextotal_volume_traded   total_value_tradei )ts_codename
trade_time
last_pricepre_close_price
open_price
high_price	low_priceclose_pricevolumeamount)r   r   getr   strptimestr)r   itemr   r   r   convert_tick_index+   s   r:   c                 C   s:  i }t ddD ]>}| d| d |d| < | d| d |d| < | d	| d |d	| < | d
| d |d
| < qtdt| d| ddtt| ddd d| dd | dd | dd | dd | dd | dd | dd | dd | dd|}|S )u  
    tick_demo = {
        'market_type': 101,
        'security_code': '600000',
        'variety_category': 1,
        'orig_time': 20240227133145832,             # 交易所行情数据时间
        'trading_phase_code': 'T111',
        'pre_close_price': 7100000,
        'open_price': 7070000,
        'high_price': 7150000,
        'low_price': 7060000,
        'last_price': 7110000,
        'close_price': 0,
        'total_volume_trade': 1621371900,
        'total_value_trade': 11528767100000,
        'bid_price1': 7110000,
        'bid_price2': 7100000,
        'bid_price3': 7090000,
        'bid_price4': 7080000,
        'bid_price5': 7070000,
        'bid_price6': 0,
        'bid_price7': 0,
        'bid_price8': 0,
        'bid_price9': 0,
        'bid_price10': 0,
        'bid_volume1': 20000,
        'bid_volume2': 26810000,
        'bid_volume3': 38450000,
        'bid_volume4': 33100000,
        'bid_volume5': 35720000,
        'bid_volume6': 0,
        'bid_volume7': 0,
        'bid_volume8': 0,
        'bid_volume9': 0,
        'bid_volume10': 0,
        'offer_price1': 7120000,
        'offer_price2': 7130000,
        'offer_price3': 7140000,
        'offer_price4': 7150000,
        'offer_price5': 7160000,
        'offer_price6': 0,
        'offer_price7': 0,
        'offer_price8': 0,
        'offer_price9': 0,
        'offer_price10': 0,
        'offer_volume1': 25400000,
        'offer_volume2': 28180000,
        'offer_volume3': 24750000,
        'offer_volume4': 63481800,
        'offer_volume5': 15723900,
        'offer_volume6': 0,
        'offer_volume7': 0,
        'offer_volume8': 0,
        'offer_volume9': 0,
        'offer_volume10': 0,
        'num_trades': 12339,
        'IOPV': 0,
        'high_limited': 7810000,
        'low_limited': 6390000
    }
    r      offer_pricer"   	ask_priceoffer_volumer)   
ask_volume	bid_price
bid_volumer   r   Nr   r   r    r/   r.   r0   r1   r2   r3   r(   r*   
num_trades)r+   r,   r-   r/   r.   r0   r1   r2   r3   r4   r5   countr   )ranger6   r   r   r   r7   r8   )r   extrair9   r   r   r   convert_tick_stockM   s.   > rG   )__doc__r   typingr   r	   tushare.subs.model.tickr   r   r8   r   r   dictr:   rG   r   r   r   r   <module>   s    "