# 7.6. Sức mua/bán

### 7.6.1. Cơ bản

```python
username_dnse = 'REPLACE_WITH_YOUR_DNSE_USERNAME'
password_dnse = 'REPLACE_WITH_YOUR_DNSE_PASSWORD'

client_order = client.FiinQuantConnector(
    broker='DNSE',
    username=username_dnse,
    password=password_dnse,
    smart_otp=True
).login()

orderbook = client_order.get_orderbook(
    account_id='0001009212',
    loan_id='13720'
)
trade_cap = orderbook.get_trading_power(ticker='SSI', price=41200)
print(trade_cap.summary())
```

Mẫu kết quả trả ra là một dictionary chứa các thông tin sau:

<pre class="language-json"><code class="lang-json"><strong>{
</strong>    'investor_id': '0001006289',
    'account_id': '0001009212',
    'custody_code': '064C500006',
    'available_power': 4884924031998,
    'buying_power': 4884924031998,
    'selling_power': 4884924024532,
    'max_buy_quantity': 135560840,
    'max_sell_quantity': 1000,
    'price': 36000.0,
    'error': None,
    'status_code': 200
}
</code></pre>

Dữ liệu có các thuộc tính:

| Tên thuộc tính      | Kiểu dữ liệu  | Mô tả                                                                            |
| ------------------- | ------------- | -------------------------------------------------------------------------------- |
| investor\_id        | str           | Mã định danh của nhà đầu tư (Investor ID).                                       |
| account\_id         | str           | Mã tài khoản giao dịch của nhà đầu tư.                                           |
| custody\_code       | str           | Mã lưu ký (Custody code) của tài khoản.                                          |
| available\_power    | float         | Tổng sức mua/bán khả dụng hiện tại (available trading power).                    |
| buying\_power       | float         | Sức mua còn lại có thể sử dụng cho giao dịch mua.                                |
| selling\_power      | float         | Sức bán còn lại có thể sử dụng cho giao dịch bán.                                |
| max\_buy\_quantity  | int           | Số lượng tối đa có thể mua tại mức giá hiện tại.                                 |
| max\_sell\_quantity | int           | Số lượng tối đa có thể bán tại mức giá hiện tại.                                 |
| price               | float         | Mức giá tham chiếu hoặc giá khớp hiện tại được sử dụng để tính toán sức mua/bán. |
| error               | str hoặc None | Thông tin lỗi (nếu có) khi lấy dữ liệu sức mua/bán.                              |
| status\_code        | int           | Mã code, nếu thành công là 200                                                   |

### 7.6.2. Phái sinh

```python
username_dnse = 'REPLACE_WITH_YOUR_DNSE_USERNAME'
password_dnse = 'REPLACE_WITH_YOUR_DNSE_PASSWORD'

client_order = client.FiinQuantConnector(
    broker='DNSE',
    username=username_dnse,
    password=password_dnse,
    smart_otp=True
).login()

orderbook_der = client_order.get_derivative_orderbook(
    account_id='0001009212',
    loan_id='2278'
)

derivative_cap = orderbook_der.get_trading_power(ticker='41I1FB000', price=1975)
print(derivative_cap.summary())
```

Mẫu kết quả trả ra là một dictionary chứa các thông tin sau:

```json
{
    'investor_id': '0001006289',
    'account_id': '0001009212',
    'custody_code': '064C500006',
    'available_power': 3573140495626,
    'buying_power': 3573214662334,
    'selling_power': 3573140495626,
    'max_buy_quantity': 99608,
    'max_sell_quantity': 99542,
    'price': 1940.0,
    'error': None,
    'status_code': 200
}
```

Dữ liệu có các thuộc tính:

| Tên thuộc tính      | Kiểu dữ liệu  | Mô tả                                                                            |
| ------------------- | ------------- | -------------------------------------------------------------------------------- |
| investor\_id        | str           | Mã định danh của nhà đầu tư (Investor ID).                                       |
| account\_id         | str           | Mã tài khoản giao dịch của nhà đầu tư.                                           |
| custody\_code       | str           | Mã lưu ký (Custody code) của tài khoản.                                          |
| available\_power    | float         | Tổng sức mua/bán khả dụng hiện tại (available trading power).                    |
| buying\_power       | float         | Sức mua còn lại có thể sử dụng cho giao dịch mua.                                |
| selling\_power      | float         | Sức bán còn lại có thể sử dụng cho giao dịch bán.                                |
| max\_buy\_quantity  | int           | Số lượng tối đa có thể mua tại mức giá hiện tại.                                 |
| max\_sell\_quantity | int           | Số lượng tối đa có thể bán tại mức giá hiện tại.                                 |
| price               | float         | Mức giá tham chiếu hoặc giá khớp hiện tại được sử dụng để tính toán sức mua/bán. |
| error               | str hoặc None | Thông tin lỗi (nếu có) khi lấy dữ liệu sức mua/bán.                              |
| status\_code        | int           | Mã code, nếu thành công là 200                                                   |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.fiinquant.vn/ham-va-cong-thuc/7.-ham-dat-lenh/7.6.-suc-mua-ban.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
