### Install easyquotation Source: https://github.com/shidenggui/easyquotation/blob/master/README.md Installs the easyquotation library using pip. This is the first step to using the library for fetching stock data. ```python pip install easyquotation ``` -------------------------------- ### Get Hong Kong Stock Daily K-line Data Source: https://github.com/shidenggui/easyquotation/blob/master/README.md Fetches daily K-line data for Hong Kong stocks. This example shows how to initialize the library for K-line data and retrieve data for multiple stocks. ```python import easyquotation quotation = easyquotation.use("daykline") data = quotation.real(['00001','00700']) print(data) ``` -------------------------------- ### Import and Use easyquotation Source: https://github.com/shidenggui/easyquotation/blob/master/README.md Demonstrates how to import the easyquotation library and initialize it to use data from Sina. This is the basic setup for fetching stock quotes. ```python import easyquotation quotation = easyquotation.use('sina') ``` -------------------------------- ### Get Tencent Hong Kong Real-time Quotes Source: https://github.com/shidenggui/easyquotation/blob/master/README.md Retrieves real-time stock quotes for Hong Kong stocks from Tencent. This example demonstrates initializing the library for HK quotes and fetching data for multiple stocks. ```python import easyquotation quotation = easyquotation.use("hkquote") data = quotation.real(['00001','00700']) print(data) ``` -------------------------------- ### GET /real Source: https://github.com/shidenggui/easyquotation/blob/master/README.md Retrieves real-time data for one or more specific stocks. ```APIDOC ## GET /real ### Description Queries real-time information for a single stock or a list of stock codes. ### Method GET ### Parameters #### Query Parameters - **codes** (string/list) - Required - The stock code or list of stock codes to query. - **prefix** (boolean) - Optional - Required if querying indices and stocks simultaneously. ### Response #### Success Response (200) - **data** (object) - Real-time market data for the requested stocks. #### Response Example { "000001": { "name": "平安银行", "price": 10.50 } } ``` -------------------------------- ### GET /market_snapshot Source: https://context7.com/shidenggui/easyquotation/llms.txt Retrieves a real-time snapshot of the entire A-share market. ```APIDOC ## GET /market_snapshot ### Description Fetches a full market snapshot of all A-share stocks. ### Method GET ### Endpoint quotation.market_snapshot(prefix=False) ### Parameters #### Query Parameters - **prefix** (boolean) - Optional - If True, includes market prefix (sh/sz/bj) in keys. ### Response #### Success Response (200) - **data** (dict) - A dictionary where keys are stock codes and values are objects containing price, volume, and bid/ask data. ### Response Example { "000001": { "name": "平安银行", "now": 10.52, "date": "2024-01-15", "time": "15:00:00" } } ``` -------------------------------- ### Get Index and Stock Data Simultaneously (Sina) Source: https://github.com/shidenggui/easyquotation/blob/master/README.md Retrieves real-time data for both indices and stocks. When fetching data for the same code as both an index and a stock, `prefix` must be set to `True`. ```python # prefix must be True when getting indices and stocks with the same code quotation.real(['sh000001', 'sz000001'], prefix=True) ``` -------------------------------- ### Get Multiple Stocks Real-time Data (Sina) Source: https://github.com/shidenggui/easyquotation/blob/master/README.md Fetches real-time data for multiple stocks simultaneously by providing a list of stock codes. Market prefixes can also be used. ```python quotation.real(['000001', '162411']) ``` -------------------------------- ### Get Market Snapshot (Sina) Source: https://github.com/shidenggui/easyquotation/blob/master/README.md Retrieves a snapshot of all stock market data from Sina. The `prefix` argument determines if market prefixes (like 'sh' or 'sz') are included in the stock codes. ```python # prefix specifies whether to include market prefixes like sz/sh/bj quotation.market_snapshot(prefix=True) ``` -------------------------------- ### Get Single Stock Real-time Data (Sina) Source: https://github.com/shidenggui/easyquotation/blob/master/README.md Fetches real-time data for a single stock using its code. The code can optionally include the market prefix. ```python quotation.real('162411') # Supports directly specifying prefixes, e.g., 'sh000001' ``` -------------------------------- ### GET /market_snapshot Source: https://github.com/shidenggui/easyquotation/blob/master/README.md Retrieves a snapshot of all stock market data from the selected provider. ```APIDOC ## GET /market_snapshot ### Description Fetches the current market snapshot for all stocks available from the configured provider. ### Method GET ### Parameters #### Query Parameters - **prefix** (boolean) - Optional - If true, includes the market prefix (sz/sh/bj) in the stock codes. ### Response #### Success Response (200) - **data** (object) - A dictionary where keys are stock codes and values are objects containing price, volume, and other market metrics. #### Response Example { "sh000159": { "name": "国际实业", "now": 8.88, "open": 8.99, "high": 9.15, "low": 8.83, "date": "2016-02-19", "time": "14:30:00" } } ``` -------------------------------- ### Get Bank of China Exchange Rates Source: https://context7.com/shidenggui/easyquotation/llms.txt Retrieves current USD exchange rates from the Bank of China source. ```python import easyquotation quotation = easyquotation.use('boc') # 获取美元汇率 usd_rate = quotation.get_exchange_rate('usa') print(f"美元卖出价: {usd_rate['sell']}") print(f"美元买入价: {usd_rate['buy']}") ``` -------------------------------- ### Initialization - use() Source: https://context7.com/shidenggui/easyquotation/llms.txt Initializes the data source provider. Supported sources include sina, tencent (or qq), jsl, daykline, hkquote, and boc. ```APIDOC ## Initialization ### Description Selects and initializes the行情 (market data) source provider. ### Method Python Function Call ### Endpoint easyquotation.use(source) ### Parameters #### Path Parameters - **source** (string) - Required - The data source identifier ('sina', 'tencent', 'qq', 'jsl', 'daykline', 'hkquote', 'boc') ### Response - **quotation_object** (object) - An instance of the requested data source provider. ``` -------------------------------- ### Initialize Data Sources with use Source: https://context7.com/shidenggui/easyquotation/llms.txt The use function is the entry point for initializing different data sources such as Sina, Tencent, or JSL. It returns a quotation object configured for the selected provider. ```python import easyquotation # 选择新浪行情源 quotation_sina = easyquotation.use('sina') # 选择腾讯行情源('tencent' 或 'qq' 均可) quotation_tencent = easyquotation.use('tencent') # 或 quotation_qq = easyquotation.use('qq') # 选择集思录数据源 quotation_jsl = easyquotation.use('jsl') # 选择港股日K线数据源 quotation_daykline = easyquotation.use('daykline') # 选择港股实时行情数据源 quotation_hkquote = easyquotation.use('hkquote') # 选择中行汇率数据源 quotation_boc = easyquotation.use('boc') ``` -------------------------------- ### Use JSL (jisilu.cn) Data Source Source: https://github.com/shidenggui/easyquotation/blob/master/README.md Initializes the easyquotation library to fetch data from JSL (jisilu.cn). It also shows how to optionally set a cookie for enhanced data access. ```python quotation = easyquotation.use('jsl') # Set cookie (optional) # If not set, access to certain data may be limited quotation.set_cookie('Cookie from browser for jisilu') ``` -------------------------------- ### Fetch Market Snapshots Source: https://context7.com/shidenggui/easyquotation/llms.txt Use market_snapshot to retrieve real-time data for the entire A-share market. The prefix parameter allows toggling between raw codes and codes with market identifiers (sh/sz/bj). ```python import easyquotation quotation = easyquotation.use('sina') # 获取全市场行情(股票代码不带市场前缀) all_stocks = quotation.market_snapshot(prefix=False) print(all_stocks['000001']) # 获取全市场行情(股票代码带市场前缀) all_stocks_with_prefix = quotation.market_snapshot(prefix=True) print(all_stocks_with_prefix['sz000001']) # 平安银行 print(all_stocks_with_prefix['sh000001']) # 上证指数 ``` -------------------------------- ### Retrieve Real-time Stock Data Source: https://context7.com/shidenggui/easyquotation/llms.txt The real method fetches live data for specific stocks or lists of stocks. It supports both single and batch requests, with optional market prefix handling. ```python import easyquotation quotation = easyquotation.use('sina') # 获取单只股票行情 single_stock = quotation.real('000001') # 获取多只股票行情 multiple_stocks = quotation.real(['000001', '600519', '000858']) for code, data in multiple_stocks.items(): print(f"{code}: {data['name']} 现价: {data['now']}") # 同时获取指数和股票 index_and_stock = quotation.real(['sh000001', 'sz000001'], prefix=True) ``` -------------------------------- ### Fetch QDII and Convertible Bond Data Source: https://context7.com/shidenggui/easyquotation/llms.txt Retrieves specialized financial instruments like QDII funds and convertible bonds from JSL, with optional volume filtering. ```python import easyquotation quotation = easyquotation.use('jsl') # 获取 QDII 数据 qdii_active = quotation.qdii(min_volume=100) # 获取可转债数据 cb_active = quotation.cb(min_volume=1000) ``` -------------------------------- ### 集思录 QDII 数据 - qdii Source: https://context7.com/shidenggui/easyquotation/llms.txt Retrieves QDII fund data from Jishulv, with filtering options for minimum trading volume. ```APIDOC ## 集思录 QDII 数据 - qdii ### Description `qdii` 方法用于获取集思录的 QDII 基金数据,支持按最小成交量筛选。 ### Method GET (Implicitly through library function) ### Endpoint Not directly exposed as an endpoint, accessed via `easyquotation.use('jsl').qdii()` ### Parameters #### Query Parameters - **min_volume** (int) - Optional - Minimum trading volume in CNY millions. - **cookie** (str) - Optional - Jishulv cookie for authenticated access. ### Request Example ```python import easyquotation quotation = easyquotation.use('jsl') # Get all QDII fund data qdii_data = quotation.qdii() # Get QDII funds with minimum trading volume of 100 million CNY qdii_active = quotation.qdii(min_volume=100) ``` ### Response #### Success Response (200) Returns a dictionary where keys are fund IDs and values are dictionaries containing QDII fund data. - **fund_id** (str) - The unique identifier for the QDII fund. - **data** (dict) - Dictionary containing various data points for the fund (specific fields may vary). #### Response Example ```json { "164701": { "fund_nm": "易方达亚洲精选", "price": 1.2345, "increase_rt": 0.50, "volume": 150.0, "fund_nm_en": "E Fund Asia Select", "currency": "USD", "nav_dt": "2024-01-15", "fund_nav": 1.2300 }, ... } ``` ``` -------------------------------- ### Query ETF Index Data from JSL Source: https://context7.com/shidenggui/easyquotation/llms.txt Retrieves index ETF data from JSL, supporting filtering by index ID, volume, and discount/premium rates for arbitrage strategies. ```python import easyquotation quotation = easyquotation.use('jsl') # 筛选适合折价套利的 ETF(最高溢价率 -0.5%) discount_etf = quotation.etfindex( min_volume=1000, max_discount='-0.5%' ) print(f"折价套利机会: {len(discount_etf)} 只") ``` -------------------------------- ### Fetch Hong Kong Stock Market Data Source: https://context7.com/shidenggui/easyquotation/llms.txt The hkquote source provides specialized real-time data for Hong Kong stocks, including 52-week highs/lows and lot sizes. ```python import easyquotation quotation = easyquotation.use('hkquote') # 获取港股实时行情 hk_stocks = quotation.real(['00700', '00001', '09988']) for code, data in hk_stocks.items(): print(f"港股: {data['name']} ({code})") print(f" 现价: {data['price']} HKD") print(f" 52周最高: {data['year_high']}") ``` -------------------------------- ### get_stock_codes - 获取内置股票代码表 Source: https://context7.com/shidenggui/easyquotation/llms.txt Retrieves the internal stock code list used by easyquotation. ```APIDOC ## get_stock_codes - 获取内置股票代码表 ### Description `get_stock_codes` 函数用于获取 easyquotation 内置的股票代码列表。 ### Method Internal library function ### Endpoint N/A ### Parameters #### Query Parameters - **realtime** (bool) - Optional - If True, fetches the latest list from the server and updates the local cache. Defaults to False. ### Request Example ```python import easyquotation # Get the locally cached stock code list stock_codes = easyquotation.get_stock_codes() print(f"Local stock codes count: {len(stock_codes)}") # Get the real-time stock code list (also updates local cache) realtime_codes = easyquotation.get_stock_codes(realtime=True) print(f"Real-time stock codes count: {len(realtime_codes)}") ``` ### Response #### Success Response (200) Returns a list of stock codes. - **[stock_code]** (str) - A stock code. #### Response Example ```json [ "000001", "600000", "000002", ... ] ``` ``` -------------------------------- ### Retrieve Hong Kong Stock Daily K-line Data Source: https://context7.com/shidenggui/easyquotation/llms.txt Fetches historical daily K-line data for Hong Kong stocks, including open, close, high, low prices, and volume. The data is retrieved using the 'daykline' source. ```python import easyquotation quotation = easyquotation.use('daykline') # 获取港股日K线数据(默认返回最近1500个交易日) kline_data = quotation.real(['00700', '00001']) for code, klines in kline_data.items(): print(f"港股日K线: {code}") for kline in klines[-5:]: date, open_price, close_price, high, low, volume = kline print(f" {date}: 开{open_price} 收{close_price} 高{high} 低{low} 量{volume}") ``` -------------------------------- ### Access Detailed Tencent Market Data Source: https://context7.com/shidenggui/easyquotation/llms.txt The Tencent data source provides extended financial metrics including PE ratio, PB ratio, market capitalization, and limit prices. ```python import easyquotation quotation = easyquotation.use('tencent') # 获取股票详细行情 stock_data = quotation.real(['000001', '600519']) for code, data in stock_data.items(): print(f"股票: {data['name']} ({code})") print(f" 现价: {data['now']}") print(f" 市盈率(动态): {data['PE']}") print(f" 总市值: {data['总市值']} 亿") ``` -------------------------------- ### 集思录可转债数据 - cb Source: https://context7.com/shidenggui/easyquotation/llms.txt Retrieves convertible bond data from Jishulv, with filtering options for minimum trading volume. ```APIDOC ## 集思录可转债数据 - cb ### Description `cb` 方法用于获取集思录的可转债数据,支持按最小成交量筛选。 ### Method GET (Implicitly through library function) ### Endpoint Not directly exposed as an endpoint, accessed via `easyquotation.use('jsl').cb()` ### Parameters #### Query Parameters - **min_volume** (int) - Optional - Minimum trading volume in CNY millions. - **cookie** (str) - Optional - Jishulv cookie for authenticated access. ### Request Example ```python import easyquotation quotation = easyquotation.use('jsl') # Optional: Set cookie # quotation.set_cookie('your_jishulv_cookie') # Get all convertible bond data cb_data = quotation.cb() # Get convertible bonds with minimum trading volume of 1000 million CNY cb_active = quotation.cb(min_volume=1000) ``` ### Response #### Success Response (200) Returns a dictionary where keys are bond IDs and values are dictionaries containing convertible bond data. - **bond_id** (str) - The unique identifier for the convertible bond. - **data** (dict) - Dictionary containing various data points for the bond (specific fields may vary). #### Response Example ```json { "113035": { "bond_nm": "海澜转债", "price": 120.50, "increase_rt": 1.20, "volume": 1500.0, "convert_price": 10.0, "stock_code": "600398", "stock_nm": "海澜之家", "up_limit": 130.0, "down_limit": 100.0, "last_dt": "2024-01-16" }, ... } ``` ``` -------------------------------- ### 集思录 ETF 指数数据 - etfindex Source: https://context7.com/shidenggui/easyquotation/llms.txt Retrieves ETF index data from Jishulv, supporting filtering by index code, volume, and premium rate. ```APIDOC ## 集思录 ETF 指数数据 - etfindex ### Description `etfindex` 方法用于从集思录获取指数 ETF 数据,支持按指数代码、成交量、溢价率进行筛选,适用于 ETF 套利策略。 ### Method GET (Implicitly through library function) ### Endpoint Not directly exposed as an endpoint, accessed via `easyquotation.use('jsl').etfindex()` ### Parameters #### Query Parameters - **index_id** (str) - Optional - Filter by index code (e.g., '000016' for SSE 50). - **min_volume** (int) - Optional - Minimum trading volume in CNY millions. - **max_discount** (str or float) - Optional - Maximum discount rate (e.g., '-0.5%', '-0.005', -0.005). Negative values indicate discount. - **min_discount** (str or float) - Optional - Minimum discount rate (e.g., '0.5%', '0.005', 0.005). Positive values indicate premium. - **cookie** (str) - Optional - Jishulv cookie for authenticated access. ### Request Example ```python import easyquotation quotation = easyquotation.use('jsl') # Optional: Set cookie # quotation.set_cookie('your_jishulv_cookie') # Get all ETF index data all_etf = quotation.etfindex() # Get ETF data for SSE 50 etf_50 = quotation.etfindex(index_id='000016') # Filter for ETFs with discount up to 0.5% and volume > 1000 million CNY discount_etf = quotation.etfindex(min_volume=1000, max_discount='-0.5%') # Filter for ETFs with premium of at least 0.5% and volume > 1000 million CNY premium_etf = quotation.etfindex(min_volume=1000, min_discount='0.5%') ``` ### Response #### Success Response (200) Returns a dictionary where keys are fund IDs and values are dictionaries containing ETF data. - **fund_id** (str) - The unique identifier for the ETF fund. - **fund_nm** (str) - Name of the fund. - **price** (float) - Current price. - **increase_rt** (float) - Percentage increase. - **volume** (float) - Trading volume in CNY millions. - **index_nm** (str) - Name of the tracked index. - **pe** (float) - Price-to-earnings ratio of the index. - **pb** (float) - Price-to-book ratio of the index. - **estimate_value** (float) - Estimated value. - **fund_nav** (float) - Net asset value of the fund. - **nav_dt** (str) - Date of the net asset value. - **discount_rt** (float) - Discount rate (premium if positive, discount if negative). - **unit_total** (float) - Fund scale in CNY billions. #### Response Example ```json { "510050": { "fund_nm": "华夏上证50ETF", "price": 3.50, "increase_rt": 0.80, "volume": 5000.0, "index_nm": "上证50", "pe": 15.0, "pb": 1.8, "estimate_value": 3.49, "fund_nav": 3.51, "nav_dt": "2024-01-16", "discount_rt": -0.0057, "unit_total": 80.5 }, ... } ``` ``` -------------------------------- ### 港股日K线 - daykline Source: https://context7.com/shidenggui/easyquotation/llms.txt Fetches historical daily K-line data for Hong Kong stocks, including date, open, close, high, low, and volume. ```APIDOC ## 港股日K线 - daykline ### Description `daykline` 数据源用于获取港股的历史日K线数据,包含日期、开盘价、收盘价、最高价、最低价、成交量等信息。 ### Method GET (Implicitly through library function) ### Endpoint Not directly exposed as an endpoint, accessed via `easyquotation.use('daykline').real()` ### Parameters #### Query Parameters - **codes** (list of str) - Required - List of Hong Kong stock codes (e.g., ['00700', '00001']) - **quotation_source** (str) - Optional - Specifies the data source, defaults to 'daykline' ### Request Example ```python import easyquotation quotation = easyquotation.use('daykline') kline_data = quotation.real(['00700', '00001']) ``` ### Response #### Success Response (200) Returns a dictionary where keys are stock codes and values are lists of daily K-line data. - **[stock_code]** (list of lists) - Each inner list contains: [date, open_price, close_price, high, low, volume] #### Response Example ```json { "00700": [ ["2024-01-10", "295.00", "298.40", "301.00", "293.20", "15678900.00"], ["2024-01-11", "298.80", "296.20", "300.40", "294.60", "12345600.00"], ... ], "00001": [ ["2024-01-10", "1.50", "1.52", "1.53", "1.49", "5000000.00"], ... ] } ``` ``` -------------------------------- ### update_stock_codes - 更新内置股票代码表 Source: https://context7.com/shidenggui/easyquotation/llms.txt Updates the internal stock code list for easyquotation to include the latest listed stocks. ```APIDOC ## update_stock_codes - 更新内置股票代码表 ### Description `update_stock_codes` 函数用于更新 easyquotation 内置的全市场股票代码列表,确保获取最新上市的股票数据。 ### Method Internal library function ### Endpoint N/A ### Parameters None ### Request Example ```python import easyquotation # Update the internal stock code list new_codes = easyquotation.update_stock_codes() print(f"Updated {len(new_codes)} stock codes.") ``` ### Response #### Success Response (200) Returns a list of updated stock codes. - **[stock_code]** (str) - A stock code that was updated or added. #### Response Example ```json [ "000001", "600000", ... ] ``` ``` -------------------------------- ### Query Index ETF Data Source: https://github.com/shidenggui/easyquotation/blob/master/README.md Retrieves detailed market information for index ETFs. The function accepts optional filters for index ID, minimum volume, and discount rate ranges, returning a dictionary of fund data keyed by the fund ID. ```python quotation.etfindex(index_id="", min_volume=0, max_discount=None, min_discount=None) ``` -------------------------------- ### Update Built-in Stock Codes Source: https://github.com/shidenggui/easyquotation/blob/master/README.md Updates the internal list of all stock codes used by the library. This ensures you have the latest available stock information. ```python easyquotation.update_stock_codes() ``` -------------------------------- ### Manage Stock Code Cache Source: https://context7.com/shidenggui/easyquotation/llms.txt Functions to update and retrieve the internal stock code list, ensuring market data requests use the most current symbols. ```python import easyquotation # 更新内置股票代码表 new_codes = easyquotation.update_stock_codes() # 获取本地缓存的股票代码列表 stock_codes = easyquotation.get_stock_codes() # 获取实时最新的股票代码列表 realtime_codes = easyquotation.get_stock_codes(realtime=True) ``` -------------------------------- ### 中行汇率 - get_exchange_rate Source: https://context7.com/shidenggui/easyquotation/llms.txt Fetches USD exchange rate information from the Bank of China. ```APIDOC ## 中行汇率 - get_exchange_rate ### Description `get_exchange_rate` 方法用于获取中国银行的美元汇率信息。 ### Method GET (Implicitly through library function) ### Endpoint Not directly exposed as an endpoint, accessed via `easyquotation.use('boc').get_exchange_rate()` ### Parameters #### Query Parameters - **currency_code** (str) - Required - The currency code for which to fetch the exchange rate (e.g., 'usa' for USD). ### Request Example ```python import easyquotation quotation = easyquotation.use('boc') # Get USD exchange rate usd_rate = quotation.get_exchange_rate('usa') ``` ### Response #### Success Response (200) Returns a dictionary containing the buy and sell rates for the specified currency. - **sell** (float) - The selling rate. - **buy** (float) - The buying rate. #### Response Example ```json { "sell": 7.2465, "buy": 7.2143 } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.