### Start AKTools HTTP Server via CLI Source: https://context7.com/akfamily/aktools/llms.txt Launches the AKTools HTTP server using the command-line interface. Supports customization of host, port, and automatic browser launching. Requires Python and AKTools to be installed. ```bash # Basic usage - starts server on default 127.0.0.1:8080 python -m aktools # Custom host and port python -m aktools --host 0.0.0.0 --port 9000 # With auto browser launch python -m aktools --auto # Check version python -m aktools --version # Short form options python -m aktools -H 0.0.0.0 -P 9000 -A ``` -------------------------------- ### Run AKTools HTTP API Source: https://github.com/akfamily/aktools/blob/main/docs/index.md Start the AKTools HTTP API service using a simple Python command. This allows access to AKShare functionalities via HTTP requests. ```bash python -m aktools ``` -------------------------------- ### Install AKTools using pip Source: https://github.com/akfamily/aktools/blob/main/docs/index.md Install the AKTools package using pip. Ensure AKTools version is greater than 0.0.86. This command installs the package and its dependencies. ```bash pip install aktools # AKTools's version should great than 0.0.86 ---> 100% Successfully installed aktools ``` -------------------------------- ### Public API - Stock Data (Rust Client) Source: https://context7.com/akfamily/aktools/llms.txt Shows how to retrieve financial data from AKTools using Rust with the `reqwest` blocking client. This example fetches stock data by constructing the URL and query parameters. ```APIDOC ## GET /api/public/stock_zh_a_hist (Rust Example) ### Description Retrieves Chinese A-share stock historical data using Rust's `reqwest` blocking client. Demonstrates setting up the client, defining parameters, and sending a GET request. ### Method GET ### Endpoint `/api/public/stock_zh_a_hist` ### Parameters #### Query Parameters - **symbol** (string) - Required - The stock symbol (e.g., `000001`). - **period** (string) - Optional - The data period (e.g., `daily`). - **start_date** (string) - Optional - The start date in `YYYYMMDD` format. - **end_date** (string) - Optional - The end date in `YYYYMMDD` format. - **adjust** (string) - Optional - The adjustment type. ### Request Example ```rust use reqwest::blocking; use serde_json::Value; use std::collections::HashMap; const URL: &str = "http://127.0.0.1:8080/api/public"; fn get_data( endpoint: &str, symbol: &str, period: &str, start_date: &str, end_date: &str, adjust: &str, ) -> Result<(), Box> { let params = HashMap::from([ ("symbol", symbol), ("period", period), ("start_date", start_date), ("end_date", end_date), ("adjust", adjust), ]); let client = blocking::Client::new(); let full_url = format!("{}/{}", URL, endpoint); let resp = client.get(full_url).query(¶ms).send()?; if resp.status().is_success() { let stock_data_list: Value = resp.json()?; println!("{:#?}", stock_data_list); } else { eprintln!("Request failed with status: {}", resp.status()); } Ok(()) } fn main() { if let Err(e) = get_data("stock_zh_a_hist", "000001", "daily", "20240125", "20240127", "") { eprintln!("Error occurred: {}", e); } } ``` ### Response #### Success Response (200) - **Value**: A JSON Value representing the stock data, typically an array of objects. #### Response Example ```json Array [ Object { "开盘": Number(9.33), "收盘": Number(9.5), "最高": Number(9.54), "最低": Number(9.27), "成交量": Number(2162514), "成交额": Number(2037648413.07) } ] ``` ``` -------------------------------- ### Public API - Stock Data (R Language) Source: https://context7.com/akfamily/aktools/llms.txt Demonstrates how to access AKTools financial data API from R using the `RCurl` and `jsonlite` packages. This example fetches stock data with specified parameters. ```APIDOC ## GET /api/public/stock_zh_a_hist (R Example) ### Description Accesses AKTools financial data API from R using `RCurl` and `jsonlite`. This example fetches Chinese A-share historical stock data with specified parameters like symbol, period, and date range. ### Method GET ### Endpoint `/api/public/stock_zh_a_hist` ### Parameters #### Query Parameters - **symbol** (string) - Required - The stock symbol (e.g., `000001`). - **period** (string) - Optional - The data period (e.g., `daily`). - **start_date** (string) - Optional - The start date in `YYYYMMDD` format. - **end_date** (string) - Optional - The end date in `YYYYMMDD` format. - **adjust** (string) - Optional - The adjustment type (e.g., `hfq`). ### Request Example ```r library(RCurl) library(jsonlite) options(warn = -1) temp_df <- getForm( uri = 'http://127.0.0.1:8080/api/public/stock_zh_a_hist', symbol = '000001', period = 'daily', start_date = '20211109', end_date = '20211209', adjust = 'hfq', .encoding = "utf-8" ) # To parse the JSON response into an R data frame: # stock_data <- fromJSON(temp_df) # print(stock_data) ``` ### Response #### Success Response (200) - **String**: A JSON string representing the stock data, which can be parsed into an R data frame. ``` -------------------------------- ### Typer CLI for AKTools Server Source: https://context7.com/akfamily/aktools/llms.txt A command-line interface application built with Typer to start the AKTools server. It allows configuration of host, port, and auto-opening the browser. The script uses subprocess to run the uvicorn server with specified parameters. Dependencies include 'typer' and 'uvicorn'. ```python import typer from pathlib import Path from subprocess import run app = typer.Typer() @app.command() def main( host: str = typer.Option("127.0.0.1", "--host", "-H", help="Set host address"), port: int = typer.Option(8080, "--port", "-P", min=0, max=65535, help="Set port"), auto: bool = typer.Option(False, "--auto", "-A", help="Auto open browser"), ): app_dir = Path(__file__).parent order_str = f"python -m uvicorn main:app --host {host} --port {port} --app-dir {app_dir}" typer.echo(f"Visit: http://{host}:{port}/version for version info") typer.echo(f"Homepage: http://{host}:{port}/") typer.echo(f"API Docs: http://{host}:{port}/docs") if auto: typer.launch(f"http://{host}:{port}/") run(order_str, shell=True) # Usage from command line: # python -m aktools --host 0.0.0.0 --port 9000 --auto ``` -------------------------------- ### Fetch Stock Data using R Source: https://github.com/akfamily/aktools/blob/main/docs/index.md Example of fetching historical stock data (B-shares) using R. It utilizes the RCurl and jsonlite packages to make an HTTP request to the AKTools API and parse the JSON response. ```r library(RCurl) # 必须先安装该包 library(jsonlite) # 必须先安装该包 options (warn = -1) # 该行有助于在无参数请求时去除 warning 信息 temp_df <- getForm( uri = 'http://127.0.0.1:8080/api/public/stock_zh_b_daily', # 此处 http://127.0.0.1:8080 需要替换为您定义的地址和端口 symbol = '000001', period = 'daily', start_date = '20211109', end_date = '20211209', adjust = 'hfq', .encoding = "utf-8" ) inner_df <- fromJSON(temp_df) inner_df ``` -------------------------------- ### Public API - Stock Data (Python Requests) Source: https://context7.com/akfamily/aktools/llms.txt Demonstrates how to fetch Chinese A-share stock historical data using Python's `requests` library by making a GET request to the public API endpoint. ```APIDOC ## GET /api/public/stock_zh_a_hist (Python Example) ### Description Fetches Chinese A-share stock historical data using Python's `requests` library. This example shows how to set query parameters and handle the JSON response. ### Method GET ### Endpoint `/api/public/stock_zh_a_hist` ### Parameters #### Query Parameters - **symbol** (string) - Required - The stock symbol (e.g., `000001`). - **period** (string) - Optional - The data period (e.g., `daily`). - **start_date** (string) - Optional - The start date in `YYYYMMDD` format. - **end_date** (string) - Optional - The end date in `YYYYMMDD` format. - **adjust** (string) - Optional - The adjustment type. ### Request Example ```python import requests import json url = "http://127.0.0.1:8080/api/public/stock_zh_a_hist" params = { "symbol": "000001", "period": "daily", "start_date": "20240125", "end_date": "20240127", "adjust": "" } response = requests.get(url, params=params) if response.status_code == 200: data = response.json() print(json.dumps(data, indent=2, ensure_ascii=False)) else: print(f"Error: {response.status_code}") print(response.json()) ``` ### Response #### Success Response (200) - **Array of Objects**: Contains stock data for the specified period. #### Response Example ```json [ { "日期": "2024-01-25T00:00:00.000", "开盘": 9.33, "收盘": 9.5, "最高": 9.54, "最低": 9.27, "成交量": 2162514, "成交额": 2037648413.07, "振幅": 2.89, "涨跌幅": 1.82, "涨跌额": 0.17, "换手率": 1.11 } ] ``` ``` -------------------------------- ### Fetch Stock Data using MATLAB Source: https://github.com/akfamily/aktools/blob/main/README.md This MATLAB script fetches historical stock data for a given symbol and date range. It utilizes the `weboptions` function to set content type and character encoding, and `webread` to make the API request. The output is a table containing stock data, with a note to manually adjust field names for compatibility. ```matlab api = 'http://127.0.0.1:8080/api/public/'; url = [api 'stock_zh_a_hist']; options = weboptions('ContentType','json', 'CharacterEncoding', 'utf-8'); data = webread(url, options, symbol = '000001', period = 'daily', start_date = '20211109', end_date = '20211209', adjust = 'hfq'); data % 由于 MATLAB 无法显示中文字段名,请自行修改为英文字段,参考链接:https://iso2mesh.sourceforge.net/cgi-bin/index.cgi?jsonlab/Doc/Examples ``` -------------------------------- ### Upgrade AKTools using pip Source: https://github.com/akfamily/aktools/blob/main/docs/index.md Upgrade AKTools to the latest version using pip. This command ensures you have the most recent features and bug fixes. Specify the index URL for PyPI. ```bash pip install aktools --upgrade -i https://pypi.org/simple # AKTools's version should great than 0.0.86 ---> 100% Successfully upgraded aktools ``` -------------------------------- ### Fetch Stock Data using Public API Endpoint Source: https://context7.com/akfamily/aktools/llms.txt Retrieves historical Chinese A-share stock data via the public API endpoint. Requires an HTTP client like curl or a programming language with HTTP capabilities. The endpoint supports parameters for symbol, period, date range, and adjustment. ```bash # Get Chinese A-share stock historical data with curl curl "http://127.0.0.1:8080/api/public/stock_zh_a_hist?symbol=600000&period=daily&start_date=20240101&end_date=20240131&adjust=qfq" # Get stock data without parameters (uses defaults) curl "http://127.0.0.1:8080/api/public/stock_zh_a_hist" # Response format (JSON array of objects): # [ # { # "日期": "2024-01-02T00:00:00.000", # "开盘": 9.5, # "收盘": 9.62, # "最高": 9.67, # "最低": 9.44, # "成交量": 2272287, # "成交额": 2172799799.01, # "振幅": 2.42, # "涨跌幅": 1.26, # "涨跌额": 0.12, # "换手率": 1.17 # } # ] ``` ```python import requests import json # Define API endpoint url = "http://127.0.0.1:8080/api/public/stock_zh_a_hist" # Set query parameters params = { "symbol": "000001", "period": "daily", "start_date": "20240125", "end_date": "20240127", "adjust": "" } # Make GET request response = requests.get(url, params=params) # Check if request was successful if response.status_code == 200: data = response.json() print(json.dumps(data, indent=2, ensure_ascii=False)) else: print(f"Error: {response.status_code}") print(response.json()) # Expected output: # [ # { # "日期": "2024-01-25T00:00:00.000", # "开盘": 9.33, # "收盘": 9.5, # "最高": 9.54, # "最低": 9.27, # "成交量": 2162514, # "成交额": 2037648413.07, # "振幅": 2.89, # "涨跌幅": 1.82, # "涨跌额": 0.17, # "换手率": 1.11 # } # ] ``` ```rust use reqwest::blocking; use serde_json::Value; use std::collections::HashMap; const URL: &str = "http://127.0.0.1:8080/api/public"; fn get_data( endpoint: &str, symbol: &str, period: &str, start_date: &str, end_date: &str, adjust: &str, ) -> Result<(), Box> { let params = HashMap::from([ ("symbol", symbol), ("period", period), ("start_date", start_date), ("end_date", end_date), ("adjust", adjust), ]); let client = blocking::Client::new(); let full_url = format!("{}/{}", URL, endpoint); let resp = client.get(full_url).query(¶ms).send()?; if resp.status().is_success() { let stock_data_list: Value = resp.json()?; println!("{:#?}", stock_data_list); } else { eprintln!("Request failed with status: {}", resp.status()); } Ok(()) } fn main() { if let Err(e) = get_data("stock_zh_a_hist", "000001", "daily", "20240125", "20240127", "") { eprintln!("Error occurred: {}", e); } } // Output: // Array [ // Object { // "开盘": Number(9.33), // "收盘": Number(9.5), // "最高": Number(9.54), // "最低": Number(9.27), // "成交量": Number(2162514), // "成交额": Number(2037648413.07) // } // ] ``` ```r library(RCurl) library(jsonlite) options(warn = -1) # Fetch stock data with parameters temp_df <- getForm( uri = 'http://127.0.0.1:8080/api/public/stock_zh_a_hist', symbol = '000001', period = 'daily', start_date = '20211109', end_date = '20211209', adjust = 'hfq', .encoding = "utf-8" ) ``` -------------------------------- ### Public API - Stock Data (curl) Source: https://context7.com/akfamily/aktools/llms.txt Fetches Chinese A-share stock historical data using the public API endpoint with curl. Parameters like symbol, period, date range, and adjustment type can be specified. ```APIDOC ## GET /api/public/stock_zh_a_hist ### Description Fetches Chinese A-share stock historical data. Allows specifying symbol, period, start and end dates, and adjustment type. ### Method GET ### Endpoint `/api/public/stock_zh_a_hist` ### Parameters #### Query Parameters - **symbol** (string) - Required - The stock symbol (e.g., `600000`). - **period** (string) - Optional - The data period (e.g., `daily`, `weekly`, `monthly`). Defaults to `daily`. - **start_date** (string) - Optional - The start date in `YYYYMMDD` format. - **end_date** (string) - Optional - The end date in `YYYYMMDD` format. - **adjust** (string) - Optional - The adjustment type (e.g., `qfq`, `hfq`). Defaults to no adjustment. ### Request Example ```bash curl "http://127.0.0.1:8080/api/public/stock_zh_a_hist?symbol=600000&period=daily&start_date=20240101&end_date=20240131&adjust=qfq" ``` ### Response #### Success Response (200) - **Array of Objects**: Each object represents a day's stock data with fields like `日期`, `开盘`, `收盘`, `最高`, `最低`, `成交量`, `成交额`, `振幅`, `涨跌幅`, `涨跌额`, `换手率`. #### Response Example ```json [ { "日期": "2024-01-02T00:00:00.000", "开盘": 9.5, "收盘": 9.62, "最高": 9.67, "最低": 9.44, "成交量": 2272287, "成交额": 2172799799.01, "振幅": 2.42, "涨跌幅": 1.26, "涨跌额": 0.12, "换手率": 1.17 } ] ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.