
    fi	                         d Z ddlZddlmZ ddlmZ ddlZddlZddede	fdZ
ddedej        fd
Zedk    r ed          Z ee           dS dS )u   
Date: 2024/1/18 16:25
Desc: 新加坡交易所-衍生品-历史数据-历史结算价格
https://www.sgx.com/zh-hans/research-education/derivatives
https://links.sgx.com/1.0.0/derivatives-daily/5888/FUTURE.zip
    N)BytesIO)StringIO20231108datereturnc                 
   d}dddd| dddd	dd

}t          j        ||          }|                                }t          j        d |d         d         D                       }g d|_        |d         j        d         dz   }|S )u   
    新加坡交易所-日历计算
    https://wap.eastmoney.com/quote/stock/100.STI.html
    :param date: 交易日
    :type date: str
    :return: 日期计算结果
    :rtype: int
    z5https://push2his.eastmoney.com/api/qt/stock/kline/getz100.STI1010100001zf1,f2,f3,f4,f5,f6,f7,f8z7f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61,f62,f63,f64 f057cbcbce2a86e2866ab8877db1d059)
secidkltfqtlmtendisccafields1fields2utforcect)paramsc                 8    g | ]}|                     d           S ),)split).0items     W/usr/local/lib/python3.11/dist-packages/akshare/futures/futures_settlement_price_sgx.py
<listcomp>z+__fetch_ftse_index_futu.<locals>.<listcomp>*   s"    TTTDJJsOOTTT    dataklines)r   -openclosehighlowvolumeamount_r#   r$   r%   r&   r'   r   i  )requestsgetjsonpd	DataFramecolumnsindex)r   urlr   r	data_jsontemp_dfnums          r   __fetch_ftse_index_futur8      s     BC,L0 F 	S(((AIlTT	&8I(8STTTUUG  GO  &/

#c
)CJr    20231107c                    t          |           }d| d}t          j        |          }t          j        t          |j                            5 }|                    |                                d                   5 }|	                                
                                }|                                d                             d          r"t          j        t          |                    }n!t          j        t          |                    }ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   |S )u  
    新加坡交易所-衍生品-历史数据-历史结算价格
    https://www.sgx.com/zh-hans/research-education/derivatives
    :param date: 交易日
    :type date: str
    :return: 所有期货品种的在指定交易日的历史结算价格
    :rtype: pandas.DataFrame
    z.https://links.sgx.com/1.0.0/derivatives-daily/z/FUTURE.zipr   txtN)r8   r,   r-   zipfileZipFiler   contentr$   namelistreaddecodeendswithr/   
read_tabler   read_csv)r   r7   r3   r4   filemy_filer!   data_dfs           r   futures_settlement_price_sgxrH   ?   s|    "$
'
'C
K3
K
K
KCSA	++	,	, 6YYt}}q)** 	6g<<>>((**D}}q!**511 6-77+htnn55	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	66 6 6 6 6 6 6 6 6 6 6 6 6 6 6 Ns7   .D8>BD!D8!D%	%D8(D%	)D88D<?D<__main__20240110)r   )r   )r9   )__doc__r<   ior   r   pandasr/   r,   strintr8   r0   rH   __name__futures_settlement_price_sgx_dfprint r    r   <module>rT      s                      * *# *s * * * *Z s BL    , z&B&B
&S&S&S#	E
)***** r    