The J-Quants API Client is a Rust implementation designed to provide seamless access to various J-Quants API endpoints. It facilitates efficient data retrieval and manipulation through asynchronous processing, ensuring fast and reliable communication.
J-Quants is a financial data platform provided by JPX Market Innovation & Research, Inc. (JPXI).
It offers access to a wide range of financial data through its API, enabling developers, analysts, and investors to integrate and analyze financial information effectively.
To use the J-Quants API, you must register for an account. A Free plan is available, allowing users to access the API without any cost. You can register for an account below.
For an in-depth understanding of the data provided, service usage, and API specifications, please refer to the following resources:
- Asynchronous Processing: Ensures fast and efficient data communication.
- Comprehensive API Support: Access to authentication, data retrieval, and more.
- Pagination Handling: Easily manage paginated data responses.
- Error Handling: Robust error management for reliable operations.
- Plan-Specific, Type-Safe Clients: Provides clients tailored to each subscription plan, allowing for type-safe usage specific to individual plans.
- Automatic ID Token Refresh: Automatically handles the renewal of ID tokens, ensuring uninterrupted API access without manual intervention.
- Secure Authentication Management: Does not store email addresses and passwords in memory; they are immediately discarded after use to ensure security.
- Rust: Ensure you have Rust installed.
- Tokio: Asynchronous runtime used by the client.
Ensure Rust is installed on your system. Then, add the jquants-api-client
to your Cargo.toml
:
[dependencies]
jquants-api-client = "0.1.0"
The J-Quants API Client currently supports the following APIs:
API Endpoint | Description | Status |
---|---|---|
/token/auth_user |
Refresh Token | Implemented |
/token/auth_refresh |
ID Token | Implemented |
API Endpoint | Description | Status |
---|---|---|
/listed/info |
Listed Issue Information | Implemented |
/prices/daily_quotes |
Stock Prices (OHLC) | Implemented |
/fins/statements |
Financial Data | Implemented |
/fins/announcement |
Earnings Calendar | Implemented |
/markets/trading_calendar |
Trading Calendar | Implemented |
/markets/trades_spec |
Trading by Type of Investors | Implemented |
/indices/topix |
TOPIX Prices (OHLC) | Implemented |
/indices |
Indices (OHLC) | Implemented |
/option/index_option |
Index Option Prices (OHLC) | Implemented |
/derivatives/futures |
Futures (OHLC) | Implemented |
/derivatives/options |
Options (OHLC) | Implemented |
/markets/weekly_margin_interest |
Margin Trading Outstandings | Implemented |
/markets/short_selling |
Short Sale Value and Ratio by Sector | Implemented |
/markets/breakdown |
Breakdown Trading Data | Implemented |
/prices/prices_am |
Morning Session Stock Prices (OHLC) | Implemented |
/fins/dividend |
Cash Dividend Data | Implemented |
/fins/fs_details |
Financial Statement Data (BS/PL) | Implemented |
Below are examples of how to use the J-Quants API client.
This example demonstrates a basic fetch operation to retrieve listed issue information.
use jquants_api_client::{
JQuantsFreePlanClient, ListedIssueInfoApi,
};
use tokio;
#[tokio::main]
async fn main() {
// Replace with your actual refresh token.
// Ensure you keep your refresh token secure and do not expose it in public repositories.
let refresh_token = "YOUR_REFRESH_TOKEN";
// Initialize the client with the refresh token
let client = JQuantsFreePlanClient::new_from_refresh_token(refresh_token);
// Make the API call to get listed issue information for code "2789"
match client.get_listed_issue_info().code("2789").send().await {
Ok(info) => println!("Listed Information: {:?}", info),
Err(e) => eprintln!("Error: {:?}", e),
}
}
This example demonstrates how to handle paginated responses when retrieving daily stock prices.
use futures::stream::StreamExt;
use jquants_api_client::{
JQuantsFreePlanClient, DailyStockPricesApi, Paginatable,
};
use tokio;
#[tokio::main]
async fn main() {
// Replace with your actual refresh token.
// Ensure you keep your refresh token secure and do not expose it in public repositories.
let refresh_token = "YOUR_REFRESH_TOKEN";
// Initialize the client with the refresh token
let client = JQuantsFreePlanClient::new_from_refresh_token(refresh_token);
// Create a stream to fetch paginated daily stock prices
let mut stream = client
.get_daily_stock_prices()
.code("27890")
.date("2024-08-01")
.fetch_pages_stream();
// Iterate through each page in the stream
while let Some(response) = stream.next().await {
match response {
Ok(daily_stock_prices_response) => {
println!("{daily_stock_prices_response:?}");
}
Err(e) => {
eprintln!("Error: {e}");
}
}
}
}
For more detailed examples, please refer to the examples directory in the repository.
Note: For security reasons, never commit or expose your refresh tokens or any other sensitive information in your code repositories.
Run unit tests using the following command:
cargo test
To run specific tests or see detailed output, you can use:
cargo test -- --nocapture
Contributions are welcome! To ensure a smooth process, please follow these guidelines:
- Fork the Repository: Click the "Fork" button at the top of this page to create your own fork.
- Clone Your Fork:
git clone https://github.com/your-username/jquants-api-client-rust.git cd jquants-api-client-rust
- Create a Branch:
git checkout -b feature/your-feature-name
- Make Your Changes: Implement your feature or fix.
- Run Tests: Ensure all tests pass.
cargo test
- Commit Your Changes:
git commit -m "Add feature: your feature description"
- Push to Your Fork:
git push origin feature/your-feature-name
- Create a Pull Request: Go to the original repository and create a pull request from your fork.
Note: Never commit or expose your refresh tokens or any other sensitive information in your code repositories.
If you encounter any bugs or have feature suggestions, please open an issue on the Issues page.
Comprehensive documentation is available here.
For API reference, visit the API Specifications (English), API Specifications (Japanese).
We value your feedback! If you have any suggestions or encounter issues, please open an issue or reach out directly.
This project is licensed under the MIT License.