# 交易 COM API Methods

## Connect

Connect TCore。若TCore未启动，则会先启动TCore，再进行Connect 。

{% tabs %}
{% tab title="Request" %}

```csharp
Connect([in] BSTR HostAddress, [in] BSTR SystemName, [in] BSTR AppID, [out,retval] LONG* plRet);
```

| **Parameters** |        |            |
| -------------- | ------ | ---------- |
| HostAddress    | string | TCore位址    |
| SystemName     | string | TCore系统名称  |
| AppID          | string | 连线TCore ID |
| {% endtab %}   |        |            |

{% tab title="Return" %}

* 0 : CONNECT\_RETURN\_FAIL
* 1 : CONNECT\_RETURN\_CONNECTING
* 2 : CONNECT\_RETURN\_CONNECTED
  {% endtab %}

{% tab title="Description" %}
叫Connect后，由event OnCommandMsg推送连线状态。
{% endtab %}
{% endtabs %}

## **Disconnect**

Disconnect TCore。

{% tabs %}
{% tab title="Request" %}

```cpp
Disconnect();
```

{% endtab %}
{% endtabs %}

## **GetAccountData**

取得帐户相关资料。

{% tabs %}
{% tab title="Request" %}

```csharp
GetAccountData([in] LONG Type, [in] LONG Index, [in] BSTR AcctMask, [in] IDispatch* AccountDataItem, [out,retval] LONG* lpRet);
```

| **Parameters**  | 类型     | 说明                                                                                                                                    |
| --------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------- |
| Type            | long   | <p>1 : 帐号</p><p>5 : 查询 证券/期货/期权权益数</p><p>6 : 查询 证券/期货/期权部位</p><p>7 : 主推 即时 证券/期货/期权部位</p><p>9 : 主推 即时 证券/期货/期权权益数</p><p>31 : 群组帐号</p> |
| Index           | long   | 欲取得第几笔资料。                                                                                                                             |
| AcctMask        | string | <p>欲取得哪个帐号资料，格式为\[BrokerID-Account] ，<br>ex.000-1234567。</p>                                                                          |
| AccountDataItem | object | [资料回传物件](/tcore-api/com-api/trade-object-parameter.md#adiaccount)。                                                                    |
| {% endtab %}    |        |                                                                                                                                       |

{% tab title="Return" %}
回传值 1:成功
{% endtab %}

{% tab title="Description" %}
AccountDataItem资料回传物件，依据Type，需使用对应的物件接收。

* Type=1\
  使用[ADIAccount](/tcore-api/com-api/trade-object-parameter.md#adiaccount)物件
* Type=5\
  使用[ADIMargin](/tcore-api/com-api/trade-object-parameter.md#adimargin)物件
* Type=6\
  使用[ADIPosition](/tcore-api/com-api/trade-object-parameter.md#adiposition)物件
* Type=7\
  使用[ADIPosition](/tcore-api/com-api/trade-object-parameter.md#adiposition)物件
* Type=9\
  使用[ADIMargin](/tcore-api/com-api/trade-object-parameter.md#adimargin)物件
* Type=31\
  使用[ADIAccount](/tcore-api/com-api/trade-object-parameter.md#adiaccount)物件
  {% endtab %}
  {% endtabs %}

## **NewOrder2**

**下一笔新单。**

{% tabs %}
{% tab title="Request" %}

```csharp
NewOrder2([in] LONG SecurityType, [in] IDispatch*NewOrderParameters, [out,retval] LONG* RetVal);
```

| **Parameters**     | 类型     | 说明                                                                    |
| ------------------ | ------ | --------------------------------------------------------------------- |
| SecurityType       | LONG   | <p>8 : TYPE\_STOCK</p><p>9 : TYPE\_FUTURE</p><p>10 : TYPE\_OPTION</p> |
| NewOrderParameters | object | [下单资料物件。](/tcore-api/com-api/trade-object-parameter.md#nopfutopt)     |
| {% endtab %}       |        |                                                                       |

{% tab title="Return" %}
回传值 1:成功

ErrorCode :\
-10 Unknow Error \
-11 买卖别不对 \
-12 复式单商品代码解析错误\
-13 下单帐号, 不可下此交易所商品 \
-14 下单错误, 不支援的价格 或 OrderType 或 TimeInForce \
-15 不支援证券下单 \
-20 连线未建立 \
-22 价格的TickSize错误 \
-23 下单数量超过该商品的上下限 \
-24 下单数量错误 \
-25 价格不能小于和等于0 (市价类型不会去检查)
{% endtab %}

{% tab title="Description" %}
NewOrderParameters下单资料物件，使用说明。

* SecurityType = TYPE\_STOCK\
  使用[NOPStock](/tcore-api/com-api/trade-object-parameter.md#nopstock)物件
* SecurityType = TYPE\_FUTURE or TYPE\_OPTION\
  使用[NOPFutOpt](/tcore-api/com-api/trade-object-parameter.md#nopfutopt)物件
  {% endtab %}
  {% endtabs %}

## **ReplaceOrder**

改单。

{% tabs %}
{% tab title="Request" %}

```csharp
ReplaceOrder([in] IDispatch* ReplaceOrderParameters, [out,retval] LONG* RetVal);
```

| **Parameters**             | 类型     | 说明                                                                                      |
| -------------------------- | ------ | --------------------------------------------------------------------------------------- |
| **ReplaceOrderParameters** | object | 欲改单资料物件 [NOPReplaceOrder](/tcore-api/com-api/trade-object-parameter.md#nopreplaceorder) |
| {% endtab %}               |        |                                                                                         |

{% tab title="Respone" %}
回传值 1:成功

ErrorCode :\
-17 改单错误, 追价单 不可改量改价 \
-18 改单错误, Trailing 不可改量改价 \
-21 改单错误, 不支援spread改价改量 \
-22 价格的TickSize错误 \
-23 下单数量超过该商品的上下限 \
-24 下单数量错误 \
-25 价格栏位无值(市价类型不会去检查)
{% endtab %}
{% endtabs %}

## **CancelOrder**

删单。

{% tabs %}
{% tab title="Request" %}

```csharp
CancelOrder([in] BSTR ReportID, [in] BSTR Key, [out,retval] LONG* RetVal);
```

| **Parameters** | 类型     | 说明                  |
| -------------- | ------ | ------------------- |
| ReportID       | string | 欲删单的ReportID。       |
| Key            | string | 删单的Key，由Apps自行指定使用。 |
| {% endtab %}   |        |                     |

{% tab title="Return" %}
回传值 1:成功

ErrorCode :\
-17 改单错误, 追价单 不可改量改价 \
-18 改单错误, Trailing 不可改量改价
{% endtab %}
{% endtabs %}

## **GetReportData**

取得回报资料。

{% tabs %}
{% tab title="Request" %}

```
GetReportData([in] LONG ReportType, BSTR ReportID, [in] IDispatch* ReportItems, [out,retval] LONG* RetVal);
```

| **Parameters** | 类型     | 说明                                                                                                   |
| -------------- | ------ | ---------------------------------------------------------------------------------------------------- |
| ReportType     | long   | <p>0 : By Report ID</p><p>1 : All Active Orders</p><p>2 : All Filled Orders</p><p>3 : All Orders</p> |
| ReportID       | string | 欲取得该笔回报的ReportID。                                                                                    |
| ReportItems    | object | [回报物件](/tcore-api/com-api/trade-object-parameter.md#rptexecutionreport)。                             |
| {% endtab %}   |        |                                                                                                      |

{% tab title="Return" %}
回传值 1:成功
{% endtab %}

{% tab title="Description" %}
ReportItems回报物件，使用说明。

* ReportID = 0\
  取委回请使用[RPTExecutionReport](/tcore-api/com-api/trade-object-parameter.md#rptexecutionreport)物件，取成回请使用[RPTFilledOrder](/tcore-api/com-api/trade-object-parameter.md#rptfilledorder)物件
* ReportID = 1\
  使用[RPTReports](/tcore-api/com-api/trade-object-parameter.md#rptreports)物件
* ReportID = 2\
  使用[RPTReports](/tcore-api/com-api/trade-object-parameter.md#rptreports)物件
* ReportID = 3\
  使用[RPTReports](/tcore-api/com-api/trade-object-parameter.md#rptreports)物件
  {% endtab %}
  {% endtabs %}

## **GetOrderTypeMatrix**

可取得该帐号对此商品可下单的单&#x522B;**。**

{% tabs %}
{% tab title="Request" %}

```csharp
GetOrderTypeMatrix ([in] BSTR BrokerID, [in] BSTR Account, [in] BSTR SymbolID, [in] LONG Synthetic, [out,retval] BSTR* RetVal);
```

| **Parameters** | 类型     | 说明                                                          |
| -------------- | ------ | ----------------------------------------------------------- |
| BrokerID       | string | <p>BrokerID，若带空白，TCore会<br>依Account找出对应的BrokerID。</p>       |
| Account        | string | 帐号。                                                         |
| SymbolID       | string | 商品代码。                                                       |
| Synthetic      | long   | <p>0 : 上手支援的下单别 <br>1 : TCore支援的本地下单别 <br>6 : 查询是否支援市价单</p> |
| {% endtab %}   |        |                                                             |

{% tab title="Return" %}
回传格式为： \
MARKET:ROD,IOC,FOK；LIMIT:ROD,IOC,FOK；STOP:ROD,IOC,FOK；\
Synthetic = 6时，支援返回TRUE，否则FALSE<br>
{% endtab %}
{% endtabs %}

## **QueryAccountData**

帐务资料查询，触发 OnAccountUpdate 事件

{% tabs %}
{% tab title="Request" %}

```csharp
QueryAccountData([in] LONG lType, [in] BSTR BrokerID, [in] BSTR Account);
```

| **Parameters** | 类型     | 说明                                                |
| -------------- | ------ | ------------------------------------------------- |
| Type           | long   | <p>5 : 查询 证券/期货/期权权益数</p><p>6 : 查询 证券/期货/期权部位</p> |
| BrokerID       | string | 交易商代码                                             |
| Account        | string | 帐号。                                               |
| {% endtab %}   |        |                                                   |
| {% endtabs %}  |        |                                                   |

## **GetInstrumentInfo**

取得商品资讯

{% tabs %}
{% tab title="Request" %}

```csharp
GetInstrumentInfo([in] BSTR Type, [in] BSTR SymbolID, [out,retval] BSTR* bstrRetVal);
```

| **Parameters** | 类型     | 说明                                                                                                                                                                                                                                               |
| -------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Type           | string | <p>1 : 上手分母值 </p><p>2 : 跳动档位 </p><p>3 : 交易时间 </p><p>4 : 显示乘数 </p><p>5 : 显示分母 </p><p>6 : 点值 </p><p>7 : 可下价格旗标 Market,Limit,Stop,StopLimit </p><p>8 : 可下单ROD,IOC,FOK,GTC,GTD </p><p>HotMonth : 热门月 </p><p>HotMonth2 : 热门月2 Instrument : 期权交易代码</p> |
| SymbolID       | string | 商品ID                                                                                                                                                                                                                                             |
| {% endtab %}   |        |                                                                                                                                                                                                                                                  |

{% tab title="Return" %}
回传商品资讯。
{% endtab %}
{% endtabs %}

## **GetExpirationDate**

取得合约到期&#x65E5;**。**

{% tabs %}
{% tab title="Request" %}

```csharp
GetExpirationDate([in] BSTR SymbolID, [out,retval] BSTR* pstrDate);
```

| **Parameters** | 类型     | 说明   |
| -------------- | ------ | ---- |
| SymbolID       | string | 商品ID |
| {% endtab %}   |        |      |
| {% endtabs %}  |        |      |


---

# 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://algomaster.gitbook.io/tcore-api/com-api/tctradewrapperapi-methods.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.
