Skip to main content

DNSE OpenAPI Python SDK

Official Python SDK for integrating with DNSE OpenAPI.

Table of Contents

Overview

DNSE OpenAPI is an API-first trading platform that enables developers to integrate brokerage, trading, margin, and market data services into their own applications.

The DNSE Python SDK provides a lightweight client for securely interacting with DNSE OpenAPI REST endpoints. It handles request signing, authentication, and communication details, allowing developers to focus on building trading systems, automation strategies, and investment applications.

Installation

Requirements

  • Python 3.8+

Install from PyPI

pip install openapi-sdk

Upgrade:

pip install --upgrade openapi-sdk

Usage

Create a DNSEClient instance with your API credentials:

from dnse import DNSEClient

client = DNSEClient(
    api_key="your_api_key",
    api_secret="your_api_secret",
    base_url="https://openapi.dnse.com.vn",
    api_version="2026-05-07",
)

status, body = client.get_accounts(dry_run=False)
print(status, body)

The SDK sends the API version in the version header. If api_version is omitted, it defaults to 2026-01-01; it can also be set with the DNSE_API_VERSION environment variable.

Dry Run

Set dry_run=True to preview the request without sending it to DNSE servers. No network call will be executed.

client.get_accounts(dry_run=True)

Examples

Run any example from the sdk/python/examples directory:

python sdk/python/api/get_accounts.py

Trading API

Function Description
get_accounts.py Demonstrates how to retrieve all trading sub-accounts managed under the account corresponding to the API Key.
get_balances.py Demonstrates how to retrieve asset balances of a trading sub-account.
get_loan_packages.py Demonstrates how to retrieve available loan package codes. It is necessary for placing an order.
get_ppse.py Demonstrates how to retrieve buying power and selling power before placing an order.
get_orders.py Demonstrates how to retrieve intraday order book.
get_order_detail.py Demonstrates how to retrieve detailed information of a specific order (by ID).
get_order_history.py Demonstrates how to retrieve historical orders.
get_corporate_action_history.py Demonstrates how to retrieve corporate action history.
get_execution_detail.py Demonstrates how to retrieve detailed execution information of an order.
get_positions.py Demonstrates how to retrieve current holding positions.
get_positions_by_id.py Demonstrates how to retrieve detailed information of a specific position (by ID).
get_position_pnl_configs.py Demonstrates how to retrieve PnL configs of a derivative position (by ID).
get_account_pnl_configs.py Demonstrates how to retrieve PnL configs of a derivative sub-account.
post_position_pnl_configs.py Demonstrates how to create or update PnL configs of a derivative position (by ID).
patch_account_pnl_configs.py Demonstrates how to update PnL configs of a derivative sub-account.
close_position.py Demonstrates how to close an existing position (by ID).
reverse_position.py Demonstrates how to reverse an existing derivative position (by ID).
send_email_otp.py Demonstrates how to request an OTP sent to your registered email. The OTP is required for generating a trading token.
create_trading_token.py Demonstrates how to generate a Trading Token required for order placement.
post_order.py Demonstrates how to submit a new trading order.
cancel_order.py Demonstrates how to cancel an existing order.
replace_order.py Demonstrates how to modify an existing order.

Market Data API

Function Description
get_security_definition.py Demonstrates how to retrieve security definition and instrument details.
get_instruments.py Demonstrates how to retrieve the list of available trading instruments and their metadata.
get_trades.py Demonstrates how to retrieve historical trade data for a specific instrument.
get_latest_trade.py Demonstrates how to retrieve the most recent trade for a specific instrument.
get_ohlc.py Demonstrates how to retrieve OHLC (Open, High, Low, Close) data for a given time range.
get_close_price.py Demonstrates how to retrieve the latest closing price of a specific instrument.
get_working_dates.py Demonstrates how to retrieve trading working dates.

WebSocket Market Data

Function Description
sec_def.py Demonstrates how to receive real-time security definition updates.
quote.py Demonstrates how to receive real-time best bid and ask prices.
trade.py Demonstrates how to receive real-time trade (tick) data.
trade_extra.py Demonstrates how to receive real-time trade data with additional aggregated metrics.
ohlc.py Demonstrates how to receive real-time OHLC data.
ohlc_closed.py Demonstrates how to receive completed OHLC candle data.
expected_price.py Demonstrates how to receive expected price data during ATO and ATC sessions.
foreign_investor.py Demonstrates how to receive foreign investor trading data.
market_index.py Demonstrates how to receive market index data.

WebSocket Trading Events

Use TradingClient.subscribe_order_event() for both ordinary and conditional order updates. Conditional orders use the existing order.{marketType}.{encoding} subscription and are delivered as Order objects. For conditional orders, orderCategory, stopPrice, stopOrderPrice, conditionOperator, durationType, durationDateTime, errorMessage, and externalOrderId are populated when provided; they are None for ordinary-order payloads.

Metadata

Release files for dnse-sdk-openapi 2.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dnse-sdk-openapi 2.4.0
File Size Uploaded Provenance Actions
dnse_sdk_openapi-2.4.0.tar.gz 56.0 kB Without provenance Details for dnse_sdk_openapi-2.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dnse-sdk-openapi 2.4.0
File Interpreter ABI Platform Actions
dnse_sdk_openapi-2.4.0-py3-none-any.whl Python 3 none any Details for dnse_sdk_openapi-2.4.0-py3-none-any.whl

Total release size: 153.9 kB

Release files / dnse_sdk_openapi-2.4.0.tar.gz

Download URL dnse_sdk_openapi-2.4.0.tar.gz
Size 56.0 kB
Tags Source
SHA-256 checksum
How to use checksums
99f27f273942b1df591404f0c5543bdc8dfbe84ef76e3cc2b158868bc1bb4e4d
BLAKE2b-256 checksum
How to use checksums
cb01ff2de82e84e5b13231ab7fb4376641523f7d2b50c71a13ca215dbe437bff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.16

Release files / dnse_sdk_openapi-2.4.0-py3-none-any.whl

Download URL dnse_sdk_openapi-2.4.0-py3-none-any.whl
Size 97.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
035e40ab17971070b13ebc03d96cc6ba230a840a29a5303799d1904477156b53
BLAKE2b-256 checksum
How to use checksums
072d0f8c15ae514e9ab39ef891eb6870c97390e3c30b77b407115140fb2ddf6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.16

Security for dnse-sdk-openapi 2.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page