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


---

# 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/en-docs/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.
