# 交易所工具箱

### 概述

面向交易所运营人员的参考实现集合，提供 Python 和 Java 两种语言的生产级示例，覆盖数据网关、缓存服务、盘口聚合和数据仓库等场景。

| 项目        | 说明                                                                                              |
| --------- | ----------------------------------------------------------------------------------------------- |
| Python 版本 | 3.10+                                                                                           |
| Java 版本   | 17+                                                                                             |
| GitHub    | [infoway-api/infoway-exchange-toolkit](https://github.com/infoway-api/infoway-exchange-toolkit) |

### 安装

```bash
git clone https://github.com/infoway-api/infoway-exchange-toolkit.git
cd infoway-exchange-toolkit
pip install -r requirements.txt  # Python 示例
```

### Python 示例

#### 多市场 WebSocket 网关

```bash
python examples/market_data_gateway/gateway.py
```

统一的多市场实时数据网关：

* 同时连接股票、加密货币、通用市场 WebSocket
* 统一的成交数据聚合处理
* 运行时统计（每秒成交笔数、运行时长、各市场分别统计）
* 信号处理，支持优雅关闭

#### 板块数据服务

```bash
python examples/plate_data_service/service.py
```

带缓存的板块数据查询服务：

* 内存缓存 + 后台自动刷新
* 线程安全（RLock）
* 可配置 TTL
* 支持行业、概念、成分股查询

#### 盘口聚合器

```bash
python examples/orderbook_aggregator/aggregator.py
```

多标的盘口数据聚合与分析：

* 聚合多个标的的买卖盘口
* 计算买卖价差、中间价、盘口不平衡度、总量
* 跨标的分析（最宽/最窄价差、最活跃标的、最大不平衡度）
* 支持股票、加密货币、通用三种市场类型

#### K线数据仓库

```bash
python examples/kline_data_warehouse/warehouse.py
```

基于 SQLite 的K线数据本地仓库：

* SQLite 存储，`(symbol, timestamp)` 主键
* 增量同步（仅获取新数据）
* 批量同步 + 频率限制保护
* 按日期范围查询

### Java 示例

#### WebSocket 网关

```bash
cd java-examples
mvn compile exec:java -Dexec.mainClass="WebSocketGateway"
```

Java 版多市场 WebSocket 网关，支持股票和加密货币实时数据接入。

#### 行情数据服务

```bash
cd java-examples
mvn compile exec:java -Dexec.mainClass="MarketDataService"
```

基于 Infoway Java SDK 的 REST 行情数据查询服务。


---

# 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.infoway.io/sdk-and-tools/exchange-toolkit.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.
