# TCore Python API 行情

## quote\_connect

行情连线

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

```python
def quote_connect(self,port):
```

| **Parameters** | 说明                   |
| -------------- | -------------------- |
| port           | 连线port，搜寻 ZMQ log取得。 |
| {% endtab %}   |                      |

{% tab title="Return" %}
回复SessionKey
{% endtab %}
{% endtabs %}

## quote\_logout

行情断线

```python
def quote_logout(self,SessionKey):
```

| **Parameters** | 说明                    |
| -------------- | --------------------- |
| SessionKey     | connect时回传的sessionkey |

## subquote

订阅行情

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

```python
def subquote(self,SessionKey,Param):
```

| **Parameters** | 说明                                                                                                                 |
| -------------- | ------------------------------------------------------------------------------------------------------------------ |
| SessionKey     | connect时回传的sessionkey                                                                                              |
| Param          | [行情订阅参数](https://algomaster.gitbook.io/tcore-api/can-shu-shuo-ming#hang-qing-ding-yue-yu-jie-ding-can-shu)，Json格式。 |
| {% endtab %}   |                                                                                                                    |

{% tab title="Description" %}
订阅成功，行情会从先前创建的[行情callback线程处理函数](https://algomaster.gitbook.io/tcore-api/tcore-python-api-kuai-su-an-zhuang-shuo-ming#jian-li-hang-qing-callback-xian-cheng-chu-li-han-shu)，推送回来。并借由message\["DataType"]判断资料类型，做对应的函数处理。
{% endtab %}

{% tab title="Response" %}
行情回复资料为Json格式，\
message\["DataType"]="REALTIME"   [实时行情](https://algomaster.gitbook.io/tcore-api/can-shu-shuo-ming#shi-shi-hang-qing-hui-fu)\
message\["DataType"]="GREEKS"   [Greeks](https://algomaster.gitbook.io/tcore-api/can-shu-shuo-ming#shi-shi-greeks-hui-fu)
{% endtab %}
{% endtabs %}

## unsubquote

解阅行情

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

```python
def unsubquote(self,SessionKey,Param):
```

| **Parameters** | 说明                                                                                                                 |
| -------------- | ------------------------------------------------------------------------------------------------------------------ |
| SessionKey     | connect时回传的sessionkey                                                                                              |
| Param          | [行情解订参数](https://algomaster.gitbook.io/tcore-api/can-shu-shuo-ming#hang-qing-ding-yue-yu-jie-ding-can-shu)，Json格式。 |
| {% endtab %}   |                                                                                                                    |
| {% endtabs %}  |                                                                                                                    |

## sub\_history

回补历史

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

```python
def sub_history(self,SessionKey,Param):
```

| **Parameters** | 说明                                                                                                                   |
| -------------- | -------------------------------------------------------------------------------------------------------------------- |
| SessionKey     | connect时回传的sessionkey                                                                                                |
| Param          | [回补历史资料参数](https://algomaster.gitbook.io/tcore-api/can-shu-shuo-ming#hang-qing-ding-yue-yu-jie-ding-can-shu)，Json格式。 |
| {% endtab %}   |                                                                                                                      |

{% tab title="Description" %}
订阅成功，行情会从先前创建的[行情callback线程处理函数](https://algomaster.gitbook.io/tcore-api/tcore-python-api-kuai-su-an-zhuang-shuo-ming#jian-li-hang-qing-callback-xian-cheng-chu-li-han-shu)，推送回来。并借由判断资料类型message\["DataType"]，做对应的函数处理。

message\["DataType"]="TICKS"   历史ticks\
message\["DataType"]="1K"   历史1K\
message\["DataType"]="DK"   历史日K
{% endtab %}

{% tab title="Response" %}
[回补历史资料](https://algomaster.gitbook.io/tcore-api/can-shu-shuo-ming#hui-bu-li-shi-zi-liao-hui-fu) 为Json格式。
{% endtab %}
{% endtabs %}

## get\_history

分页取得历史资料

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

```python
def get_history(self,SessionKey,Param):
```

| **Parameters** | 说明                                                                                                                  |
| -------------- | ------------------------------------------------------------------------------------------------------------------- |
| SessionKey     | connect时回传的sessionkey                                                                                               |
| Param          | [分页取得历史资料参数](https://algomaster.gitbook.io/tcore-api/can-shu-shuo-ming#fen-ye-qu-de-li-shi-zi-liao-can-shu)，Json格式。 |
| {% endtab %}   |                                                                                                                     |

{% tab title="Return" %}
[返回分页历史资料](https://algomaster.gitbook.io/tcore-api/can-shu-shuo-ming#gethistory-fen-ye-li-shi-zi-liao-hui-fu)
{% endtab %}

{% tab title="Description" %}
查询需要带入QryIndex(带空则当作0)，每次最多回50笔，拿最后一笔QryIndex资讯继续往下查询，直到回空代表已无资料。
{% endtab %}
{% endtabs %}

## QueryInstrumentInfo

查询合约

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

```python
def QueryInstrumentInfo(self, SessionKey, symbol):
```

| **Parameters** | 说明                    |
| -------------- | --------------------- |
| SessionKey     | connect时回传的sessionkey |
| symbol         | 合约代码                  |
| {% endtab %}   |                       |

{% tab title="Retrun" %}
[返回合约资讯](https://algomaster.gitbook.io/tcore-api/can-shu-shuo-ming#he-yue-zi-xun-hui-fu)
{% endtab %}
{% endtabs %}

## QueryAllInstrumentInfo

查询全部合约

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

```python
def QueryAllInstrumentInfo(self, SessionKey, type):
```

| **Parameters** | 说明                         |
| -------------- | -------------------------- |
| SessionKey     | connect时回传的sessionkey      |
| type           | Future or Options or Stock |
| {% endtab %}   |                            |
| {% endtabs %}  |                            |

## QuotePong

Pong回复以维持连线

```python
def QuotePong(self, SessionKey):
```


---

# 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/python/tcoreapi_mq.py.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.
