> For the complete documentation index, see [llms.txt](https://docs.infoway.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.infoway.io/en-docs/sdk-and-tools/exchange-toolkit.md).

# Exchange Toolkit

### Overview

Reference implementations for exchange operators, providing production-grade examples in Python and Java covering data gateways, caching services, orderbook aggregation, and data warehousing.

| Item   | Details                                                                                         |
| ------ | ----------------------------------------------------------------------------------------------- |
| Python | 3.10+                                                                                           |
| Java   | 17+                                                                                             |
| GitHub | [infoway-api/infoway-exchange-toolkit](https://github.com/infoway-api/infoway-exchange-toolkit) |

### Installation

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

### Python Examples

#### Multi-Market WebSocket Gateway

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

Unified multi-market real-time data gateway:

* Simultaneous connections to stock, crypto, and common market WebSockets
* Unified trade data aggregation
* Runtime statistics (trades/sec, uptime, per-market counts)
* Signal handling with graceful shutdown

#### Plate Data Service

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

Cached sector data query service:

* In-memory cache with automatic background refresh
* Thread-safe (RLock)
* Configurable TTL
* Supports industry, concept, and constituent queries

#### Orderbook Aggregator

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

Multi-symbol orderbook aggregation and analysis:

* Aggregates bid/ask data across multiple symbols
* Calculates spread, mid-price, book imbalance, total volume
* Cross-symbol analysis (widest/tightest spread, most liquid, highest imbalance)
* Supports stock, crypto, and common market types

#### K-line Data Warehouse

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

SQLite-based local K-line data warehouse:

* SQLite storage with `(symbol, timestamp)` primary key
* Incremental sync (only fetches newer data)
* Batch sync with rate-limit protection
* Date-range queries

### Java Examples

#### WebSocket Gateway

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

Java multi-market WebSocket gateway for stock and crypto real-time data.

#### Market Data Service

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

REST market data query service built on the Infoway Java SDK.
