polyedge 0.0.0-stage → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +172 -2
- package/dist/index.cjs +643 -0
- package/dist/index.d.cts +1094 -0
- package/dist/index.d.ts +1094 -0
- package/dist/index.js +611 -0
- package/package.json +58 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 PolyEdge Labs (https://polyedge.dev)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,173 @@
|
|
|
1
|
-
#
|
|
1
|
+
# PolyEdge TypeScript / Node.js SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/polyedge)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://polyedge.dev/docs)
|
|
6
|
+
[](https://github.com/PolyEdgeDev/polyedge-stream-benchmark)
|
|
7
|
+
|
|
8
|
+
Official TypeScript/Node.js SDK for **[PolyEdge](https://polyedge.dev)** — **Ultra-Low-Latency Polymarket Mempool Trade Streaming & Real-Time On-Chain Analytics API.**
|
|
9
|
+
|
|
10
|
+
> Engineered for Polymarket copy-trading bots, professional traders, and prediction market builders. Capture pending trades pre-block and track smart money with institutional-grade on-chain analytics.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Key Features
|
|
15
|
+
|
|
16
|
+
- **4 First-Class Namespaces**: Aligned 1:1 with OpenAPI 3.1:
|
|
17
|
+
- `client.streams`: Real-time SSE trade streaming, sessions & filter management.
|
|
18
|
+
- `client.analytics`: Polymarket CTFExchange trade attribution, trader leaderboards, market settlement audit.
|
|
19
|
+
- `client.account`: Account profile, API key rotation, request telemetry, and ledger.
|
|
20
|
+
- `client.subscription`: Plan catalog, subscription quotes, and promo codes.
|
|
21
|
+
- **Enterprise-Grade SSE Streaming Engine**:
|
|
22
|
+
- **45s Keep-Alive Watchdog**: Terminates silent TCP half-open connections and auto-heals.
|
|
23
|
+
- **Auto-Resumption with `Last-Event-ID`**: Atomically tracks event IDs and replays buffered trades on reconnection.
|
|
24
|
+
- **Jittered Exponential Backoff**: Prevents thundering herds during network hiccups.
|
|
25
|
+
- **Dual Consumption**: Event listeners (`stream.on('tx', ...)`) and Async Iterators (`for await (const tx of stream)`).
|
|
26
|
+
- **Pre-Block Polymarket Trade Streaming**: Peered with 100+ Polygon nodes to capture pending Polymarket trades pre-block. The World's Fastest — [verify yourself](https://github.com/PolyEdgeDev/polyedge-stream-benchmark).
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm install polyedge
|
|
34
|
+
# or
|
|
35
|
+
pnpm add polyedge
|
|
36
|
+
# or
|
|
37
|
+
yarn add polyedge
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## Quick Start
|
|
43
|
+
|
|
44
|
+
### 1. Initialize Client
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { PolyEdgeClient } from "polyedge";
|
|
48
|
+
|
|
49
|
+
const client = new PolyEdgeClient({
|
|
50
|
+
apiKey: process.env.POLYEDGE_API_KEY!,
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### 2. Real-Time Mempool Trade Stream (SSE)
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
// Connect to an active stream
|
|
58
|
+
const stream = client.streams.connect("your_stream_id", {
|
|
59
|
+
heartbeatTimeoutMs: 45_000, // 45s watchdog timer (server heartbeats every 30s)
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Event Listener Pattern
|
|
63
|
+
stream.on("tx", (tx, eventId) => {
|
|
64
|
+
console.log(`⚡ [Trade #${eventId}] Tx: ${tx.tx_hash.slice(0, 18)}...`);
|
|
65
|
+
console.log(` Market: "${tx.market?.question}"`);
|
|
66
|
+
console.log(` Taker: ${tx.taker?.outcome} (${tx.taker?.side}) | Shares: ${tx.taker?.shares}`);
|
|
67
|
+
console.log(` Matched Makers: ${tx.makers?.length || 0} orders`);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
stream.on("heartbeat", () => {
|
|
71
|
+
console.log("💓 Server heartbeat received");
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
stream.on("reconnect", (attempt, delayMs) => {
|
|
75
|
+
console.warn(`Reconnecting in ${delayMs}ms (attempt #${attempt})...`);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
stream.on("error", (err) => {
|
|
79
|
+
console.error("Stream error:", err.message);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// Or Async Iterator Pattern:
|
|
83
|
+
// for await (const tx of stream) {
|
|
84
|
+
// console.log("Trade:", tx.tx_hash, tx.market?.question);
|
|
85
|
+
// }
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### 3. Analytics: Leaderboard & Trader Dossier
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
// Query top profitable traders
|
|
92
|
+
const leaderboard = await client.analytics.getLeaderboard({ limit: 5 });
|
|
93
|
+
console.log(`Total active traders tracked: ${leaderboard.total_count}`);
|
|
94
|
+
|
|
95
|
+
leaderboard.traders?.forEach((t, i) => {
|
|
96
|
+
const pnlUsd = ((t.total_pnl || 0) / 1e6).toFixed(2);
|
|
97
|
+
console.log(`#${i + 1} ${t.profile?.address} (${t.profile?.name || "Anon"}) - Realized PnL: $${pnlUsd}`);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// Inspect deep trader profile
|
|
101
|
+
const dossier = await client.analytics.getTrader("0x51698a47f840a242abc2ca0351371c7ffac41842");
|
|
102
|
+
console.log(`Trader ${dossier.profile?.name} - Taker Tier: ${dossier.taker_tier_name}`);
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### 4. Account Profile & Telemetry
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
// Account info
|
|
109
|
+
const profile = await client.account.getProfile();
|
|
110
|
+
console.log(`Email: ${profile.email}, Tier: ${profile.tier}, Status: ${profile.status}`);
|
|
111
|
+
|
|
112
|
+
// Usage telemetry
|
|
113
|
+
const telemetry = await client.account.getTelemetry();
|
|
114
|
+
console.log(`Today's requests: ${telemetry.total_requests}`);
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## Complete API Service Reference (28 Methods)
|
|
120
|
+
|
|
121
|
+
### 1. Streams Service (`client.streams`)
|
|
122
|
+
|
|
123
|
+
| Method | HTTP | Description |
|
|
124
|
+
| :--- | :--- | :--- |
|
|
125
|
+
| `connect(streamId, options)` | `GET /streams/{id}` (SSE) | Connect to ultra-low-latency real-time SSE mempool trade stream |
|
|
126
|
+
| `list()` | `GET /streams` | List all configured data streams |
|
|
127
|
+
| `create(req)` | `POST /streams` | Provision a new targeted filter stream (tags, addresses, series) |
|
|
128
|
+
| `get(id)` | `GET /streams/{id}` | Get stream metadata and configuration by ID |
|
|
129
|
+
| `updateMetadata(id, req)` | `PUT /streams/{id}/meta` | Update stream name and description |
|
|
130
|
+
| `updateSubscription(id, req)` | `PUT /streams/{id}/subscription` | Hot-reload market filters (addresses, tags, series) on active stream |
|
|
131
|
+
| `delete(id)` | `DELETE /streams/{id}` | Delete stream by ID |
|
|
132
|
+
| `getActiveSessions()` | `GET /sessions` | List all active live SSE connections across streams |
|
|
133
|
+
| `disconnectSession(connId)` | `DELETE /sessions/{id}` | Disconnect one of your active SSE connections by `conn_id` |
|
|
134
|
+
| `getSessionHistory(params)` | `GET /sessions/history` | Query historical SSE connection logs and durations |
|
|
135
|
+
|
|
136
|
+
### 2. Analytics Service (`client.analytics`)
|
|
137
|
+
|
|
138
|
+
| Method | HTTP | Description |
|
|
139
|
+
| :--- | :--- | :--- |
|
|
140
|
+
| `getLeaderboard(params)` | `GET /v2/analytics/leaderboard` | Top profitable traders ranked by realized PnL, volume, and ROI |
|
|
141
|
+
| `getTrader(address)` | `GET /v2/traders/{address}` | Comprehensive trader intelligence profile, taker tier, and top tags |
|
|
142
|
+
| `getTraderHourlyStats(address)` | `GET /v2/traders/{address}/hourly_stats` | 24-hour hourly trading PnL and volume breakdown |
|
|
143
|
+
| `getTraderMarkets(address, params)` | `GET /v2/traders/{address}/markets` | Historical market positions and settled outcomes by trader |
|
|
144
|
+
| `getTraderMarketOrders(addr, marketId, params)` | `GET /v2/traders/{address}/markets/{id}/orders` | Order fill details for a specific trader in a specific market |
|
|
145
|
+
| `getMarket(id)` | `GET /v2/markets/{id}` | Prediction market detail, top 20 earners, and volume attribution |
|
|
146
|
+
| `getDeposits(params)` | `GET /v2/analytics/deposits` | 60-day aggregated trader deposit summaries (>= 100 pUSD) |
|
|
147
|
+
|
|
148
|
+
### 3. Account Service (`client.account`)
|
|
149
|
+
|
|
150
|
+
| Method | HTTP | Description |
|
|
151
|
+
| :--- | :--- | :--- |
|
|
152
|
+
| `getProfile()` | `GET /v2/user/me` | Current user profile, active tier, and deposit balance |
|
|
153
|
+
| `listKeys()` | `GET /v2/user/keys` | List all active API keys and statuses |
|
|
154
|
+
| `createKey(req)` | `POST /v2/user/keys` | Generate a new API key with custom name |
|
|
155
|
+
| `updateKey(key, req)` | `PATCH /v2/user/keys/{key}` | Enable, disable, or rename an API key |
|
|
156
|
+
| `deleteKey(key)` | `DELETE /v2/user/keys/{key}` | Revoke and delete an API key |
|
|
157
|
+
| `getLedger(params)` | `GET /v2/user/ledger` | Balance ledger transaction records |
|
|
158
|
+
| `getTelemetry()` | `GET /v2/user/telemetry` | Daily request count and per-endpoint usage telemetry |
|
|
159
|
+
|
|
160
|
+
### 4. Subscription Service (`client.subscription`)
|
|
161
|
+
|
|
162
|
+
| Method | HTTP | Description |
|
|
163
|
+
| :--- | :--- | :--- |
|
|
164
|
+
| `listTiers()` | `GET /v2/tiers` | Public tier catalog, feature allowances, and pricing specifications |
|
|
165
|
+
| `getQuote(req)` | `POST /v2/user/subscribe/quote` | Calculate quote for plan upgrade or billing cycle change |
|
|
166
|
+
| `subscribe(req)` | `POST /v2/user/subscribe` | Purchase or upgrade tier subscription |
|
|
167
|
+
| `validatePromoCode(req)` | `POST /v2/user/promo-codes/validate` | Validate promotional discount code |
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## License
|
|
172
|
+
|
|
173
|
+
[MIT](LICENSE) © 2026 [PolyEdge Labs](https://polyedge.dev)
|