Skip to main content

OpenBB extension for Tushare

Project description

How to Use Tushare as a Data Source for OpenBB

OpenBB, as an open-source financial data platform, is dedicated to providing free and transparent financial data interfaces for investors, analysts, and developers. For a detailed introduction to OpenBB and its usage, please refer to Introduction to OpenBB and How to Use It to Aid Financial Data Analysis of China A-share and Hong Kong Stocks.

Although OpenBB supports multi-source data interfaces, the acquisition of financial data in China (including Hong Kong) mainly relies on Yahoo Finance. As a free basic data source, it can meet basic needs, but its coverage depth for the Chinese and Hong Kong markets is still insufficient. More importantly, mainland Chinese users need to use a VPN to access this service, creating significant usage barriers.

To enhance service capabilities in Greater China, OpenBB urgently needs to improve the implementation of localized financial data sources. The mainstream paid solutions include Wind, Eastmoney Choice, and 同花顺 iFind (mainly for institutional clients), while the free solutions focus on the open-source tool Tushare or AKShare as the core solutions. Tushare has become one of the most comprehensive, up-to-date, and developer-friendly financial data libraries in the domestic Python ecosystem.

The openbb_tushare project, as a data source extension for OpenBB, enables seamless integration of Tushare data into the OpenBB platform. Below is a detailed usage guide:

💻 Environment Setup and Installation Process

As developers, we primarily interact with the platform through the OpenBB Platform CLI. To integrate the Tushare data source, follow these steps to configure the development environment:

  1. Create a Python Virtual Environment

    You can use venv, uv, or poetry to create a virtual environment. Here, we use venv (built into Python):

    # Create a virtual environment  
    python3 -m venv .venv  
    
    # Activate the virtual environment (Linux/Mac)  
    source .venv/bin/activate  
    
    # For Windows  
    .venv\Scripts\activate  
    
  2. Install OpenBB Platform CLI

    Install the core OpenBB CLI via pip. Users in mainland China can configure a mirror for faster installation:

    # (Optional) Set a domestic mirror for pip  
    # For Linux/Mac  
    export PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple 
    
    # Install OpenBB CLI
    pip install openbb-cli
    
  3. Install openbb_tushare

    Next, install the openbb_tushare extenstion to use the Tushare data source:

    # Install the Tushare data source extension  
    pip install openbb_tushare  
    
    # Rebuild OpenBB resources to activate the plugin  
    python -c "import openbb; openbb.build()"  
    

🚀 Using the Tushare Data Source

Case 1: Query A-Share Company News (Vanke as an Example)

Jupyter Notebook

from openbb import obb
messages = obb.news.company("000002", provider="tushare")
for result in messages.results:
    print(f"{result.title}")

Output:

开源证券发布万科A研报,公司信息更新报告:销售均价有所提升,股东持续借款提供支持
万科A出售2086万股库存股,金额1.36亿元
万科A:已完成所有A股库存股出售 所得资金4.79亿元
...

Using OpenBB CLI

openbb
2025 Jun 26, 03:11 (🦋) /news/ $ company --symbol 000002 --provider akshare

After entering the command, the results will be displayed in a WebView, as shown below:

openbb04

Case 2: Obtain Historical Stock Prices of Hong Kong Stocks (Hong Kong Telecom as an Example)

Using OpenBB CLI:

2025 Jun 26, 03:28 (🦋) /equity/price/ $ historical --symbol 06823 --provider tushare

Results in WebView:openbb05

Jupyter Notebook

from openbb import obb
prices = obb.equity.price.historical(symbol='06823', start_date="2025-06-01", end_date="2025-06-10", provider="tushare")
prices.results[0].date, prices.results[0].open, prices.results[0].close, prices.results[0].high, prices.results[0].low, prices.results[0].volume

Output:

(datetime.date(2025, 6, 2), 11.28, 11.3, 11.3, 11.14, 10308375)

🌟 openbb_tushare Project Ecosystem

The openbb_tushare project is currently in an active development phase, and contributions from the open-source community are welcome:

Code Repositories

Ways to Contribute

  1. Submit Issues to report data needs or bugs.

  2. Contribute PRs to optimize data source interfaces.

  3. Improve documentation to help more users.

Through the integration of Tushare and OpenBB, users in China can more conveniently access real-time and historical data for markets such as A-Shares and Hong Kong Stocks, providing strong data support for quantitative analysis and investment research.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openbb_tushare-0.2.5.tar.gz (31.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openbb_tushare-0.2.5-py3-none-any.whl (47.4 kB view details)

Uploaded Python 3

File details

Details for the file openbb_tushare-0.2.5.tar.gz.

File metadata

  • Download URL: openbb_tushare-0.2.5.tar.gz
  • Upload date:
  • Size: 31.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.10 Windows/11

File hashes

Hashes for openbb_tushare-0.2.5.tar.gz
Algorithm Hash digest
SHA256 dbe2402fc63afafc787293406806f2547603775c7ce4cba27103ebd904115018
MD5 22fe8adcacba6c469f05c07bd82a478e
BLAKE2b-256 bdfbceb4cb80499db1ebfbe9475b75183e71dae6387c59657e3f99bbc777adfc

See more details on using hashes here.

File details

Details for the file openbb_tushare-0.2.5-py3-none-any.whl.

File metadata

  • Download URL: openbb_tushare-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 47.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.10 Windows/11

File hashes

Hashes for openbb_tushare-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 af08e3fc5fccdb76f0a9303160ba32fe26dbaed3b71d68c00a221f4512399a29
MD5 0a3c34e471c376437ae7507839da5a58
BLAKE2b-256 8ddb304912ba5739a47207df2281bf83dcf7f579938cc4a43ef219331636e6f7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page