dnse-sdk-openapi 1.4.6__tar.gz → 2.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/PKG-INFO +16 -1
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/README.md +15 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/dnse/api/client.py +163 -13
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/dnse/api/common.py +1 -1
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/dnse/websocket/client.py +16 -1
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/dnse/websocket/models.py +45 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/dnse_sdk_openapi.egg-info/PKG-INFO +16 -1
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/dnse_sdk_openapi.egg-info/SOURCES.txt +29 -1
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/dnse_sdk_openapi.egg-info/top_level.txt +1 -0
- dnse_sdk_openapi-2.3.0/examples/env_util.py +37 -0
- dnse_sdk_openapi-2.3.0/examples/indicators.py +152 -0
- dnse_sdk_openapi-2.3.0/examples/log_util.py +20 -0
- dnse_sdk_openapi-2.3.0/examples/market_utils.py +14 -0
- dnse_sdk_openapi-2.3.0/examples/otp_email.py +190 -0
- dnse_sdk_openapi-2.3.0/examples/position_manager.py +246 -0
- dnse_sdk_openapi-2.3.0/examples/position_store.py +48 -0
- dnse_sdk_openapi-2.3.0/examples/reference/orders-email-otp.py +146 -0
- dnse_sdk_openapi-2.3.0/examples/reference/orders-smart-otp.py +145 -0
- dnse_sdk_openapi-2.3.0/examples/strategy_base.py +68 -0
- dnse_sdk_openapi-2.3.0/examples/strategy_ichimoku.py +122 -0
- dnse_sdk_openapi-2.3.0/examples/strategy_price_action.py +66 -0
- dnse_sdk_openapi-2.3.0/examples/strategy_scalping.py +118 -0
- dnse_sdk_openapi-2.3.0/examples/token_store.py +114 -0
- dnse_sdk_openapi-2.3.0/examples/use-cases/auto-trader.py +316 -0
- dnse_sdk_openapi-2.3.0/examples/use-cases/market-data.py +51 -0
- dnse_sdk_openapi-2.3.0/examples/use-cases/order-history.py +67 -0
- dnse_sdk_openapi-2.3.0/examples/use-cases/place-a-trade.py +230 -0
- dnse_sdk_openapi-2.3.0/examples/use-cases/portfolio-check.py +51 -0
- dnse_sdk_openapi-2.3.0/marketdata-api/get_expected_price.py +22 -0
- dnse_sdk_openapi-2.3.0/marketdata-api/get_market_index.py +30 -0
- dnse_sdk_openapi-2.3.0/marketdata-api/get_trades_volume_profile.py +28 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/pyproject.toml +1 -1
- dnse_sdk_openapi-1.4.6/marketdata-api/get_trading_session.py → dnse_sdk_openapi-2.3.0/trading-api/get_account_pnl_configs.py +5 -2
- dnse_sdk_openapi-2.3.0/trading-api/get_loans.py +33 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/trading-api/get_order_history.py +1 -1
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/trading-api/get_orders.py +2 -0
- dnse_sdk_openapi-2.3.0/trading-api/get_position_pnl_configs.py +26 -0
- dnse_sdk_openapi-2.3.0/trading-api/patch_account_pnl_configs.py +44 -0
- dnse_sdk_openapi-2.3.0/trading-api/post_order.py +43 -0
- dnse_sdk_openapi-2.3.0/trading-api/post_position_pnl_configs.py +48 -0
- dnse_sdk_openapi-2.3.0/trading-api/reverse_position.py +26 -0
- dnse_sdk_openapi-2.3.0/websocket-marketdata/market_index_influence.py +51 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/websocket-marketdata/ohlc_closed.py +4 -4
- dnse_sdk_openapi-1.4.6/trading-api/post_order.py +0 -38
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/broker-api/get_list_care_by.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/dnse/__init__.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/dnse/api/_version.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/dnse/websocket/_version.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/dnse/websocket/auth.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/dnse/websocket/connection.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/dnse/websocket/encoding.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/dnse/websocket/exceptions.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/dnse/websocket/py.typed +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/dnse_sdk_openapi.egg-info/dependency_links.txt +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/marketdata-api/get_foreign_trading.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/marketdata-api/get_instruments.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/marketdata-api/get_lastest_session.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/marketdata-api/get_latest_quote.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/marketdata-api/get_latest_trade.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/marketdata-api/get_ohlc.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/marketdata-api/get_quotes.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/marketdata-api/get_security_definition.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/marketdata-api/get_trades.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/marketdata-api/get_working_dates.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/setup.cfg +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/trading-api/cancel_order.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/trading-api/close_position.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/trading-api/create_trading_token.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/trading-api/get_accounts.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/trading-api/get_balances.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/trading-api/get_close_price.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/trading-api/get_corporate_action_history.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/trading-api/get_execution_detail.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/trading-api/get_loan_packages.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/trading-api/get_order_detail.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/trading-api/get_position_by_id.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/trading-api/get_positions.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/trading-api/get_ppse.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/trading-api/put_order.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/trading-api/send_email_otp.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/websocket-marketdata/estimated_market_index.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/websocket-marketdata/expected_price.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/websocket-marketdata/foreign_investor.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/websocket-marketdata/market_index.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/websocket-marketdata/ohlc.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/websocket-marketdata/quote.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/websocket-marketdata/sec_def.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/websocket-marketdata/session.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/websocket-marketdata/trade.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/websocket-marketdata/trade_extra.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/websocket-trading/broker_order.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/websocket-trading/broker_position.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/websocket-trading/order.py +0 -0
- {dnse_sdk_openapi-1.4.6 → dnse_sdk_openapi-2.3.0}/websocket-trading/position.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dnse-sdk-openapi
|
|
3
|
-
Version:
|
|
3
|
+
Version: 2.3.0
|
|
4
4
|
Summary: DNSE OpenAPI SDK
|
|
5
5
|
Description-Content-Type: text/markdown
|
|
6
6
|
|
|
@@ -95,7 +95,12 @@ python sdk/python/api/get_accounts.py
|
|
|
95
95
|
| `get_execution_detail.py` | Demonstrates how to retrieve detailed execution information of an order. |
|
|
96
96
|
| `get_positions.py` | Demonstrates how to retrieve current holding positions. |
|
|
97
97
|
| `get_positions_by_id.py` | Demonstrates how to retrieve detailed information of a specific position (by ID). |
|
|
98
|
+
| `get_position_pnl_configs.py` | Demonstrates how to retrieve PnL configs of a derivative position (by ID). |
|
|
99
|
+
| `get_account_pnl_configs.py` | Demonstrates how to retrieve PnL configs of a derivative sub-account. |
|
|
100
|
+
| `post_position_pnl_configs.py` | Demonstrates how to create or update PnL configs of a derivative position (by ID). |
|
|
101
|
+
| `patch_account_pnl_configs.py` | Demonstrates how to update PnL configs of a derivative sub-account. |
|
|
98
102
|
| `close_position.py` | Demonstrates how to close an existing position (by ID). |
|
|
103
|
+
| `reverse_position.py` | Demonstrates how to reverse an existing derivative position (by ID). |
|
|
99
104
|
| `send_email_otp.py` | Demonstrates how to request an OTP sent to your registered email. The OTP is required for generating a trading token. |
|
|
100
105
|
| `create_trading_token.py` | Demonstrates how to generate a Trading Token required for order placement. |
|
|
101
106
|
| `post_order.py` | Demonstrates how to submit a new trading order. |
|
|
@@ -127,3 +132,13 @@ python sdk/python/api/get_accounts.py
|
|
|
127
132
|
| `expected_price.py` | Demonstrates how to receive expected price data during ATO and ATC sessions. |
|
|
128
133
|
| `foreign_investor.py` | Demonstrates how to receive foreign investor trading data. |
|
|
129
134
|
| `market_index.py` | Demonstrates how to receive market index data. |
|
|
135
|
+
|
|
136
|
+
### WebSocket Trading Events
|
|
137
|
+
|
|
138
|
+
Use `TradingClient.subscribe_order_event()` for both ordinary and conditional
|
|
139
|
+
order updates. Conditional orders use the existing
|
|
140
|
+
`order.{marketType}.{encoding}` subscription and are delivered as `Order`
|
|
141
|
+
objects. For conditional orders, `orderCategory`, `stopPrice`,
|
|
142
|
+
`stopOrderPrice`, `conditionOperator`, `durationType`, `durationDateTime`,
|
|
143
|
+
`errorMessage`, and `externalOrderId` are populated when provided; they are
|
|
144
|
+
`None` for ordinary-order payloads.
|
|
@@ -89,7 +89,12 @@ python sdk/python/api/get_accounts.py
|
|
|
89
89
|
| `get_execution_detail.py` | Demonstrates how to retrieve detailed execution information of an order. |
|
|
90
90
|
| `get_positions.py` | Demonstrates how to retrieve current holding positions. |
|
|
91
91
|
| `get_positions_by_id.py` | Demonstrates how to retrieve detailed information of a specific position (by ID). |
|
|
92
|
+
| `get_position_pnl_configs.py` | Demonstrates how to retrieve PnL configs of a derivative position (by ID). |
|
|
93
|
+
| `get_account_pnl_configs.py` | Demonstrates how to retrieve PnL configs of a derivative sub-account. |
|
|
94
|
+
| `post_position_pnl_configs.py` | Demonstrates how to create or update PnL configs of a derivative position (by ID). |
|
|
95
|
+
| `patch_account_pnl_configs.py` | Demonstrates how to update PnL configs of a derivative sub-account. |
|
|
92
96
|
| `close_position.py` | Demonstrates how to close an existing position (by ID). |
|
|
97
|
+
| `reverse_position.py` | Demonstrates how to reverse an existing derivative position (by ID). |
|
|
93
98
|
| `send_email_otp.py` | Demonstrates how to request an OTP sent to your registered email. The OTP is required for generating a trading token. |
|
|
94
99
|
| `create_trading_token.py` | Demonstrates how to generate a Trading Token required for order placement. |
|
|
95
100
|
| `post_order.py` | Demonstrates how to submit a new trading order. |
|
|
@@ -121,3 +126,13 @@ python sdk/python/api/get_accounts.py
|
|
|
121
126
|
| `expected_price.py` | Demonstrates how to receive expected price data during ATO and ATC sessions. |
|
|
122
127
|
| `foreign_investor.py` | Demonstrates how to receive foreign investor trading data. |
|
|
123
128
|
| `market_index.py` | Demonstrates how to receive market index data. |
|
|
129
|
+
|
|
130
|
+
### WebSocket Trading Events
|
|
131
|
+
|
|
132
|
+
Use `TradingClient.subscribe_order_event()` for both ordinary and conditional
|
|
133
|
+
order updates. Conditional orders use the existing
|
|
134
|
+
`order.{marketType}.{encoding}` subscription and are delivered as `Order`
|
|
135
|
+
objects. For conditional orders, `orderCategory`, `stopPrice`,
|
|
136
|
+
`stopOrderPrice`, `conditionOperator`, `durationType`, `durationDateTime`,
|
|
137
|
+
`errorMessage`, and `externalOrderId` are populated when provided; they are
|
|
138
|
+
`None` for ordinary-order payloads.
|
|
@@ -31,7 +31,7 @@ class DNSEClient:
|
|
|
31
31
|
maxsize=10, # Số connections tối đa mỗi pool
|
|
32
32
|
block=False, # Không block khi pool đầy
|
|
33
33
|
timeout=urllib3.Timeout(connect=30.0, read=60.0),
|
|
34
|
-
cert_reqs = 'CERT_NONE', # Không yêu cầu certificate
|
|
34
|
+
# cert_reqs = 'CERT_NONE', # Không yêu cầu certificate
|
|
35
35
|
assert_hostname = False # Không kiểm tra hostname
|
|
36
36
|
)
|
|
37
37
|
|
|
@@ -52,6 +52,41 @@ class DNSEClient:
|
|
|
52
52
|
dry_run=dry_run,
|
|
53
53
|
)
|
|
54
54
|
|
|
55
|
+
def get_loans(
|
|
56
|
+
self,
|
|
57
|
+
account_no,
|
|
58
|
+
market_type,
|
|
59
|
+
disbursement_from=None,
|
|
60
|
+
disbursement_to=None,
|
|
61
|
+
due_date_from=None,
|
|
62
|
+
due_date_to=None,
|
|
63
|
+
position_id=None,
|
|
64
|
+
page_index=None,
|
|
65
|
+
page_size=None,
|
|
66
|
+
dry_run=False,
|
|
67
|
+
):
|
|
68
|
+
query = {"marketType": market_type}
|
|
69
|
+
if disbursement_from is not None:
|
|
70
|
+
query["disbursementFrom"] = disbursement_from
|
|
71
|
+
if disbursement_to is not None:
|
|
72
|
+
query["disbursementTo"] = disbursement_to
|
|
73
|
+
if due_date_from is not None:
|
|
74
|
+
query["dueDateFrom"] = due_date_from
|
|
75
|
+
if due_date_to is not None:
|
|
76
|
+
query["dueDateTo"] = due_date_to
|
|
77
|
+
if position_id is not None:
|
|
78
|
+
query["positionId"] = position_id
|
|
79
|
+
if page_index is not None:
|
|
80
|
+
query["pageIndex"] = page_index
|
|
81
|
+
if page_size is not None:
|
|
82
|
+
query["pageSize"] = page_size
|
|
83
|
+
return self._request(
|
|
84
|
+
"GET",
|
|
85
|
+
f"/accounts/{account_no}/loans",
|
|
86
|
+
query=query,
|
|
87
|
+
dry_run=dry_run,
|
|
88
|
+
)
|
|
89
|
+
|
|
55
90
|
def get_positions(self, account_no, market_type, dry_run=False):
|
|
56
91
|
return self._request(
|
|
57
92
|
"GET",
|
|
@@ -60,18 +95,68 @@ class DNSEClient:
|
|
|
60
95
|
dry_run=dry_run,
|
|
61
96
|
)
|
|
62
97
|
|
|
63
|
-
def get_position_by_id(self, market_type, position_id, dry_run=False):
|
|
98
|
+
def get_position_by_id(self, market_type, position_id, version=None, dry_run=False):
|
|
99
|
+
return self._request(
|
|
100
|
+
"GET",
|
|
101
|
+
f"/positions/{position_id}",
|
|
102
|
+
query={"marketType": market_type},
|
|
103
|
+
version=version,
|
|
104
|
+
dry_run=dry_run,
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
def get_position_pnl_configs(self, market_type, position_id, version=None, dry_run=False):
|
|
64
108
|
return self._request(
|
|
65
109
|
"GET",
|
|
66
|
-
f"/
|
|
110
|
+
f"/positions/{position_id}/pnl-configs",
|
|
67
111
|
query={"marketType": market_type},
|
|
112
|
+
version=version,
|
|
68
113
|
dry_run=dry_run,
|
|
69
114
|
)
|
|
70
115
|
|
|
71
|
-
def
|
|
116
|
+
def get_account_pnl_configs(self, account_no, market_type, version=None, dry_run=False):
|
|
117
|
+
return self._request("GET",
|
|
118
|
+
f"/accounts/{account_no}/pnl-configs",
|
|
119
|
+
query={"marketType": market_type},
|
|
120
|
+
version=version,
|
|
121
|
+
dry_run=dry_run)
|
|
122
|
+
|
|
123
|
+
def patch_account_pnl_configs(self, account_no, market_type, payload, trading_token, version=None, dry_run=False):
|
|
124
|
+
return self._request("PATCH",
|
|
125
|
+
f"/accounts/{account_no}/pnl-configs",
|
|
126
|
+
query={"marketType": market_type},
|
|
127
|
+
body=payload,
|
|
128
|
+
headers={"trading-token": trading_token},
|
|
129
|
+
version=version,
|
|
130
|
+
dry_run=dry_run)
|
|
131
|
+
|
|
132
|
+
def post_position_pnl_configs(self, market_type, position_id, payload, trading_token, version=None, dry_run=False):
|
|
133
|
+
headers = {"trading-token": trading_token}
|
|
134
|
+
return self._request(
|
|
135
|
+
"POST",
|
|
136
|
+
f"/positions/{position_id}/pnl-configs",
|
|
137
|
+
query={"marketType": market_type},
|
|
138
|
+
body=payload,
|
|
139
|
+
headers=headers,
|
|
140
|
+
version=version,
|
|
141
|
+
dry_run=dry_run,
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
def get_orders(
|
|
145
|
+
self,
|
|
146
|
+
account_no,
|
|
147
|
+
market_type,
|
|
148
|
+
order_category=None,
|
|
149
|
+
page_index=None,
|
|
150
|
+
page_size=None,
|
|
151
|
+
dry_run=False,
|
|
152
|
+
):
|
|
72
153
|
query = {"marketType": market_type}
|
|
73
154
|
if order_category:
|
|
74
155
|
query["orderCategory"] = order_category
|
|
156
|
+
if page_index is not None:
|
|
157
|
+
query["pageIndex"] = page_index
|
|
158
|
+
if page_size is not None:
|
|
159
|
+
query["pageSize"] = page_size
|
|
75
160
|
return self._request(
|
|
76
161
|
"GET",
|
|
77
162
|
f"/accounts/{account_no}/orders",
|
|
@@ -210,6 +295,38 @@ class DNSEClient:
|
|
|
210
295
|
dry_run=dry_run,
|
|
211
296
|
)
|
|
212
297
|
|
|
298
|
+
def get_trades_volume_profile(self, symbol, from_date, to_date, board_id=None, dry_run=False):
|
|
299
|
+
query = {"from": from_date, "to": to_date}
|
|
300
|
+
if board_id is not None:
|
|
301
|
+
query["board_id"] = board_id
|
|
302
|
+
return self._request(
|
|
303
|
+
"GET",
|
|
304
|
+
f"/price/{symbol}/trades/volume-profile",
|
|
305
|
+
query=query,
|
|
306
|
+
dry_run=dry_run,
|
|
307
|
+
)
|
|
308
|
+
|
|
309
|
+
def get_expected_price(self, symbol, board_id=None, from_date=None, to_date=None, limit=None, order = None, next_page_token=None, dry_run=False):
|
|
310
|
+
query = {}
|
|
311
|
+
if board_id is not None:
|
|
312
|
+
query["boardId"] = board_id
|
|
313
|
+
if from_date is not None:
|
|
314
|
+
query["from"] = from_date
|
|
315
|
+
if to_date is not None:
|
|
316
|
+
query["to"] = to_date
|
|
317
|
+
if limit is not None:
|
|
318
|
+
query["limit"] = limit
|
|
319
|
+
if order is not None:
|
|
320
|
+
query["order"] = order
|
|
321
|
+
if next_page_token is not None:
|
|
322
|
+
query["nextPageToken"] = next_page_token
|
|
323
|
+
return self._request(
|
|
324
|
+
"GET",
|
|
325
|
+
f"/price/{symbol}/expected-price",
|
|
326
|
+
query=query if query else None,
|
|
327
|
+
dry_run=dry_run,
|
|
328
|
+
)
|
|
329
|
+
|
|
213
330
|
def get_quotes(self, symbol, board_id=None, from_date=None, to_date=None, limit=None, order = None, next_page_token=None, dry_run=False):
|
|
214
331
|
query = {}
|
|
215
332
|
if board_id is not None:
|
|
@@ -252,7 +369,26 @@ class DNSEClient:
|
|
|
252
369
|
dry_run=dry_run,
|
|
253
370
|
)
|
|
254
371
|
|
|
255
|
-
def
|
|
372
|
+
def get_market_index(self, index_name, from_date=None, to_date=None, limit=None, order=None, next_page_token=None, dry_run=False):
|
|
373
|
+
query = {}
|
|
374
|
+
if from_date is not None:
|
|
375
|
+
query["from"] = from_date
|
|
376
|
+
if to_date is not None:
|
|
377
|
+
query["to"] = to_date
|
|
378
|
+
if limit is not None:
|
|
379
|
+
query["limit"] = limit
|
|
380
|
+
if order is not None:
|
|
381
|
+
query["order"] = order
|
|
382
|
+
if next_page_token is not None:
|
|
383
|
+
query["nextPageToken"] = next_page_token
|
|
384
|
+
return self._request(
|
|
385
|
+
"GET",
|
|
386
|
+
f"/price/{index_name}/market-index",
|
|
387
|
+
query=query if query else None,
|
|
388
|
+
dry_run=dry_run,
|
|
389
|
+
)
|
|
390
|
+
|
|
391
|
+
def get_instruments(self, symbol=None, market_id=None, security_group_id=None, index_name=None, limit=None, page=None, version=None, dry_run=False):
|
|
256
392
|
query = {}
|
|
257
393
|
if symbol is not None:
|
|
258
394
|
query["symbol"] = symbol
|
|
@@ -268,8 +404,9 @@ class DNSEClient:
|
|
|
268
404
|
query["page"] = page
|
|
269
405
|
return self._request(
|
|
270
406
|
"GET",
|
|
271
|
-
|
|
407
|
+
"/market/instruments",
|
|
272
408
|
query=query if query else None,
|
|
409
|
+
version=version,
|
|
273
410
|
dry_run=dry_run,
|
|
274
411
|
)
|
|
275
412
|
|
|
@@ -333,17 +470,18 @@ class DNSEClient:
|
|
|
333
470
|
dry_run=dry_run,
|
|
334
471
|
)
|
|
335
472
|
|
|
336
|
-
def post_order(self, market_type, payload, trading_token, order_category="NORMAL", dry_run=False):
|
|
473
|
+
def post_order(self, account_no, market_type, payload, trading_token, order_category="NORMAL", version=None, dry_run=False):
|
|
337
474
|
headers = {"trading-token": trading_token}
|
|
338
475
|
query = {"marketType": market_type}
|
|
339
476
|
if order_category:
|
|
340
477
|
query["orderCategory"] = order_category
|
|
341
478
|
return self._request(
|
|
342
479
|
"POST",
|
|
343
|
-
"/accounts/orders",
|
|
480
|
+
f"/accounts/{account_no}/orders",
|
|
344
481
|
query=query,
|
|
345
482
|
body=payload,
|
|
346
483
|
headers=headers,
|
|
484
|
+
version=version,
|
|
347
485
|
dry_run=dry_run,
|
|
348
486
|
)
|
|
349
487
|
|
|
@@ -406,29 +544,41 @@ class DNSEClient:
|
|
|
406
544
|
dry_run=dry_run,
|
|
407
545
|
)
|
|
408
546
|
|
|
409
|
-
def close_position(self, position_id, market_type, trading_token, dry_run=False):
|
|
547
|
+
def close_position(self, position_id, market_type, trading_token, version=None, dry_run=False):
|
|
410
548
|
headers = {"trading-token": trading_token}
|
|
411
549
|
query = {"marketType": market_type}
|
|
412
550
|
return self._request(
|
|
413
551
|
"POST",
|
|
414
|
-
f"/
|
|
552
|
+
f"/positions/{position_id}/close",
|
|
415
553
|
query=query,
|
|
416
554
|
headers=headers,
|
|
555
|
+
version=version,
|
|
556
|
+
dry_run=dry_run,
|
|
557
|
+
)
|
|
558
|
+
|
|
559
|
+
def reverse_position(self, position_id, trading_token, dry_run=False):
|
|
560
|
+
headers = {"trading-token": trading_token}
|
|
561
|
+
return self._request(
|
|
562
|
+
"POST",
|
|
563
|
+
f"/positions/{position_id}/reverse",
|
|
564
|
+
query={"marketType": "DERIVATIVE"},
|
|
565
|
+
headers=headers,
|
|
566
|
+
version="2026-01-01",
|
|
417
567
|
dry_run=dry_run,
|
|
418
568
|
)
|
|
419
569
|
|
|
420
|
-
def _request(self, method, path, query=None, body=None, headers=None, dry_run=False):
|
|
570
|
+
def _request(self, method, path, query=None, body=None, headers=None, version=None, dry_run=False):
|
|
421
571
|
debug = os.getenv("DEBUG", "").lower() == "true"
|
|
422
572
|
url = self._build_url(path, query)
|
|
423
573
|
date_value, signature_header_value = self._signature_headers(method, path)
|
|
424
574
|
date_header_name = get_date_header_name()
|
|
425
575
|
|
|
426
|
-
# Build headers dict
|
|
576
|
+
# Build headers dict (per-request `version` overrides the client default)
|
|
427
577
|
req_headers = {
|
|
428
578
|
date_header_name: date_value,
|
|
429
579
|
"X-Signature": signature_header_value,
|
|
430
580
|
"x-api-key": self._api_key,
|
|
431
|
-
"version": self._api_version,
|
|
581
|
+
"version": version or self._api_version,
|
|
432
582
|
}
|
|
433
583
|
|
|
434
584
|
if body is not None:
|
|
@@ -25,7 +25,7 @@ from .exceptions import (
|
|
|
25
25
|
ConnectionClosed,
|
|
26
26
|
)
|
|
27
27
|
from .models import Trade, Quote, Ohlc, Order, AccountUpdate, ExpectedPrice, SecurityDefinition, TradeExtra, \
|
|
28
|
-
MarketIndex, ForeignInvestor, Position, EstimatedMarketIndex, Session
|
|
28
|
+
MarketIndex, ForeignInvestor, Position, EstimatedMarketIndex, Session, IndexInfluence
|
|
29
29
|
|
|
30
30
|
logger = logging.getLogger(__name__)
|
|
31
31
|
logger.setLevel(logging.INFO)
|
|
@@ -52,6 +52,7 @@ _MSG_TYPE_MAP = {
|
|
|
52
52
|
"ep": ("position_event", Position, "position"),
|
|
53
53
|
"mi": ("market_index", MarketIndex, None),
|
|
54
54
|
"emi": ("estimated_market_index", EstimatedMarketIndex, "marketIndex"),
|
|
55
|
+
"ii": ("market_index_influence", IndexInfluence, None),
|
|
55
56
|
"a": ("account", AccountUpdate, None),
|
|
56
57
|
"f": ("foreign", ForeignInvestor, None),
|
|
57
58
|
"s": ("session", Session, None),
|
|
@@ -348,6 +349,20 @@ class TradingClient:
|
|
|
348
349
|
if on_estimated_market_index:
|
|
349
350
|
self.on("estimated_market_index", on_estimated_market_index)
|
|
350
351
|
|
|
352
|
+
async def subscribe_market_index_influence(
|
|
353
|
+
self, index_name: str, resolution: int = 1,
|
|
354
|
+
on_market_index_influence: Optional[Callable[[IndexInfluence], None]] = None, encoding="json"
|
|
355
|
+
) -> None:
|
|
356
|
+
channel = f"market_index_influence.{index_name}.{resolution}.json"
|
|
357
|
+
if encoding == "msgpack":
|
|
358
|
+
channel = f"market_index_influence.{index_name}.{resolution}.msgpack"
|
|
359
|
+
# Index name is encoded in the channel; symbols would create an
|
|
360
|
+
# additional server-side suffix and no longer match the publisher.
|
|
361
|
+
await self._subscribe_channel(channel, [])
|
|
362
|
+
|
|
363
|
+
if on_market_index_influence:
|
|
364
|
+
self.on("market_index_influence", on_market_index_influence)
|
|
365
|
+
|
|
351
366
|
async def subscribe_quotes(
|
|
352
367
|
self, symbols: List[str], on_quote: Optional[Callable[[Quote], None]] = None, encoding="json", board_id=None
|
|
353
368
|
) -> None:
|
|
@@ -54,6 +54,7 @@ def parse_timestamp(v: Any, date_only: bool = False) -> Optional[str]:
|
|
|
54
54
|
except Exception:
|
|
55
55
|
return None
|
|
56
56
|
|
|
57
|
+
|
|
57
58
|
@dataclass
|
|
58
59
|
class PriceLevel:
|
|
59
60
|
price: float
|
|
@@ -296,6 +297,50 @@ class EstimatedMarketIndex:
|
|
|
296
297
|
)
|
|
297
298
|
|
|
298
299
|
|
|
300
|
+
@dataclass
|
|
301
|
+
class IndexInfluenceItem:
|
|
302
|
+
time: Optional[str]
|
|
303
|
+
symbol: str
|
|
304
|
+
influence: float
|
|
305
|
+
influenceRatio: float
|
|
306
|
+
proportion: float
|
|
307
|
+
changeRatio: float
|
|
308
|
+
changeValue: float
|
|
309
|
+
price: float
|
|
310
|
+
grossTradeAmount: float
|
|
311
|
+
totalVolumeTraded: float
|
|
312
|
+
|
|
313
|
+
@classmethod
|
|
314
|
+
def from_dict(cls, data: Dict[str, Any]) -> "IndexInfluenceItem":
|
|
315
|
+
return cls(
|
|
316
|
+
time=data.get("time"),
|
|
317
|
+
symbol=data.get("symbol"),
|
|
318
|
+
influence=data.get("influence"),
|
|
319
|
+
influenceRatio=data.get("influenceRatio"),
|
|
320
|
+
proportion=data.get("proportion"),
|
|
321
|
+
changeRatio=data.get("changeRatio"),
|
|
322
|
+
changeValue=data.get("changeValue"),
|
|
323
|
+
price=data.get("price"),
|
|
324
|
+
grossTradeAmount=data.get("grossTradeAmount"),
|
|
325
|
+
totalVolumeTraded=data.get("totalVolumeTraded"),
|
|
326
|
+
)
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
@dataclass
|
|
330
|
+
class IndexInfluence:
|
|
331
|
+
index_name: Optional[str]
|
|
332
|
+
data: List[IndexInfluenceItem]
|
|
333
|
+
receivedAt: Optional[float] = field(default=None, repr=False)
|
|
334
|
+
|
|
335
|
+
@classmethod
|
|
336
|
+
def from_dict(cls, data: Dict[str, Any]) -> "IndexInfluence":
|
|
337
|
+
return cls(
|
|
338
|
+
index_name=data.get("index_name"),
|
|
339
|
+
data=[IndexInfluenceItem.from_dict(item) for item in (data.get("Data") or data.get("data") or [])],
|
|
340
|
+
receivedAt=data.get("_receivedAt"),
|
|
341
|
+
)
|
|
342
|
+
|
|
343
|
+
|
|
299
344
|
@dataclass
|
|
300
345
|
class ExpectedPrice:
|
|
301
346
|
marketId: str
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dnse-sdk-openapi
|
|
3
|
-
Version:
|
|
3
|
+
Version: 2.3.0
|
|
4
4
|
Summary: DNSE OpenAPI SDK
|
|
5
5
|
Description-Content-Type: text/markdown
|
|
6
6
|
|
|
@@ -95,7 +95,12 @@ python sdk/python/api/get_accounts.py
|
|
|
95
95
|
| `get_execution_detail.py` | Demonstrates how to retrieve detailed execution information of an order. |
|
|
96
96
|
| `get_positions.py` | Demonstrates how to retrieve current holding positions. |
|
|
97
97
|
| `get_positions_by_id.py` | Demonstrates how to retrieve detailed information of a specific position (by ID). |
|
|
98
|
+
| `get_position_pnl_configs.py` | Demonstrates how to retrieve PnL configs of a derivative position (by ID). |
|
|
99
|
+
| `get_account_pnl_configs.py` | Demonstrates how to retrieve PnL configs of a derivative sub-account. |
|
|
100
|
+
| `post_position_pnl_configs.py` | Demonstrates how to create or update PnL configs of a derivative position (by ID). |
|
|
101
|
+
| `patch_account_pnl_configs.py` | Demonstrates how to update PnL configs of a derivative sub-account. |
|
|
98
102
|
| `close_position.py` | Demonstrates how to close an existing position (by ID). |
|
|
103
|
+
| `reverse_position.py` | Demonstrates how to reverse an existing derivative position (by ID). |
|
|
99
104
|
| `send_email_otp.py` | Demonstrates how to request an OTP sent to your registered email. The OTP is required for generating a trading token. |
|
|
100
105
|
| `create_trading_token.py` | Demonstrates how to generate a Trading Token required for order placement. |
|
|
101
106
|
| `post_order.py` | Demonstrates how to submit a new trading order. |
|
|
@@ -127,3 +132,13 @@ python sdk/python/api/get_accounts.py
|
|
|
127
132
|
| `expected_price.py` | Demonstrates how to receive expected price data during ATO and ATC sessions. |
|
|
128
133
|
| `foreign_investor.py` | Demonstrates how to receive foreign investor trading data. |
|
|
129
134
|
| `market_index.py` | Demonstrates how to receive market index data. |
|
|
135
|
+
|
|
136
|
+
### WebSocket Trading Events
|
|
137
|
+
|
|
138
|
+
Use `TradingClient.subscribe_order_event()` for both ordinary and conditional
|
|
139
|
+
order updates. Conditional orders use the existing
|
|
140
|
+
`order.{marketType}.{encoding}` subscription and are delivered as `Order`
|
|
141
|
+
objects. For conditional orders, `orderCategory`, `stopPrice`,
|
|
142
|
+
`stopOrderPrice`, `conditionOperator`, `durationType`, `durationDateTime`,
|
|
143
|
+
`errorMessage`, and `externalOrderId` are populated when provided; they are
|
|
144
|
+
`None` for ordinary-order payloads.
|
|
@@ -17,39 +17,67 @@ dnse_sdk_openapi.egg-info/PKG-INFO
|
|
|
17
17
|
dnse_sdk_openapi.egg-info/SOURCES.txt
|
|
18
18
|
dnse_sdk_openapi.egg-info/dependency_links.txt
|
|
19
19
|
dnse_sdk_openapi.egg-info/top_level.txt
|
|
20
|
+
examples/env_util.py
|
|
21
|
+
examples/indicators.py
|
|
22
|
+
examples/log_util.py
|
|
23
|
+
examples/market_utils.py
|
|
24
|
+
examples/otp_email.py
|
|
25
|
+
examples/position_manager.py
|
|
26
|
+
examples/position_store.py
|
|
27
|
+
examples/strategy_base.py
|
|
28
|
+
examples/strategy_ichimoku.py
|
|
29
|
+
examples/strategy_price_action.py
|
|
30
|
+
examples/strategy_scalping.py
|
|
31
|
+
examples/token_store.py
|
|
32
|
+
examples/reference/orders-email-otp.py
|
|
33
|
+
examples/reference/orders-smart-otp.py
|
|
34
|
+
examples/use-cases/auto-trader.py
|
|
35
|
+
examples/use-cases/market-data.py
|
|
36
|
+
examples/use-cases/order-history.py
|
|
37
|
+
examples/use-cases/place-a-trade.py
|
|
38
|
+
examples/use-cases/portfolio-check.py
|
|
39
|
+
marketdata-api/get_expected_price.py
|
|
20
40
|
marketdata-api/get_foreign_trading.py
|
|
21
41
|
marketdata-api/get_instruments.py
|
|
22
42
|
marketdata-api/get_lastest_session.py
|
|
23
43
|
marketdata-api/get_latest_quote.py
|
|
24
44
|
marketdata-api/get_latest_trade.py
|
|
45
|
+
marketdata-api/get_market_index.py
|
|
25
46
|
marketdata-api/get_ohlc.py
|
|
26
47
|
marketdata-api/get_quotes.py
|
|
27
48
|
marketdata-api/get_security_definition.py
|
|
28
49
|
marketdata-api/get_trades.py
|
|
29
|
-
marketdata-api/
|
|
50
|
+
marketdata-api/get_trades_volume_profile.py
|
|
30
51
|
marketdata-api/get_working_dates.py
|
|
31
52
|
trading-api/cancel_order.py
|
|
32
53
|
trading-api/close_position.py
|
|
33
54
|
trading-api/create_trading_token.py
|
|
55
|
+
trading-api/get_account_pnl_configs.py
|
|
34
56
|
trading-api/get_accounts.py
|
|
35
57
|
trading-api/get_balances.py
|
|
36
58
|
trading-api/get_close_price.py
|
|
37
59
|
trading-api/get_corporate_action_history.py
|
|
38
60
|
trading-api/get_execution_detail.py
|
|
39
61
|
trading-api/get_loan_packages.py
|
|
62
|
+
trading-api/get_loans.py
|
|
40
63
|
trading-api/get_order_detail.py
|
|
41
64
|
trading-api/get_order_history.py
|
|
42
65
|
trading-api/get_orders.py
|
|
43
66
|
trading-api/get_position_by_id.py
|
|
67
|
+
trading-api/get_position_pnl_configs.py
|
|
44
68
|
trading-api/get_positions.py
|
|
45
69
|
trading-api/get_ppse.py
|
|
70
|
+
trading-api/patch_account_pnl_configs.py
|
|
46
71
|
trading-api/post_order.py
|
|
72
|
+
trading-api/post_position_pnl_configs.py
|
|
47
73
|
trading-api/put_order.py
|
|
74
|
+
trading-api/reverse_position.py
|
|
48
75
|
trading-api/send_email_otp.py
|
|
49
76
|
websocket-marketdata/estimated_market_index.py
|
|
50
77
|
websocket-marketdata/expected_price.py
|
|
51
78
|
websocket-marketdata/foreign_investor.py
|
|
52
79
|
websocket-marketdata/market_index.py
|
|
80
|
+
websocket-marketdata/market_index_influence.py
|
|
53
81
|
websocket-marketdata/ohlc.py
|
|
54
82
|
websocket-marketdata/ohlc_closed.py
|
|
55
83
|
websocket-marketdata/quote.py
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Shared helpers for loading example configuration from .env files."""
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
from log_util import log
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def load_dotenv():
|
|
9
|
+
"""Load KEY=VALUE lines from nearby .env files into os.environ.
|
|
10
|
+
|
|
11
|
+
Search order:
|
|
12
|
+
- current working directory
|
|
13
|
+
- examples/ (this file's directory)
|
|
14
|
+
- repo python/ root (parent of examples/)
|
|
15
|
+
|
|
16
|
+
Existing environment variables win over .env values.
|
|
17
|
+
"""
|
|
18
|
+
here = os.path.dirname(os.path.abspath(__file__))
|
|
19
|
+
seen = set()
|
|
20
|
+
for directory in (os.getcwd(), here, os.path.dirname(here)):
|
|
21
|
+
path = os.path.join(directory, ".env")
|
|
22
|
+
if path in seen or not os.path.isfile(path):
|
|
23
|
+
continue
|
|
24
|
+
seen.add(path)
|
|
25
|
+
try:
|
|
26
|
+
with open(path, encoding="utf-8") as handle:
|
|
27
|
+
for raw in handle:
|
|
28
|
+
line = raw.strip()
|
|
29
|
+
if not line or line.startswith("#") or "=" not in line:
|
|
30
|
+
continue
|
|
31
|
+
if line.lower().startswith("export "):
|
|
32
|
+
line = line[len("export "):]
|
|
33
|
+
key, _, val = line.partition("=")
|
|
34
|
+
os.environ.setdefault(key.strip(), val.strip().strip('"').strip("'"))
|
|
35
|
+
log(f"Đã nạp .env từ {path}")
|
|
36
|
+
except OSError:
|
|
37
|
+
pass
|