> For the complete documentation index, see [llms.txt](https://docs.fiinquant.vn/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.fiinquant.vn/ham-va-cong-thuc/7.-ham-dat-lenh/7.6.-suc-mua-ban.md).

# 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                                                   |
