metascalp 1.1.0__tar.gz
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.
- metascalp-1.1.0/PKG-INFO +233 -0
- metascalp-1.1.0/README.md +214 -0
- metascalp-1.1.0/metascalp/__init__.py +4 -0
- metascalp-1.1.0/metascalp/client.py +317 -0
- metascalp-1.1.0/metascalp/socket.py +457 -0
- metascalp-1.1.0/metascalp.egg-info/PKG-INFO +233 -0
- metascalp-1.1.0/metascalp.egg-info/SOURCES.txt +10 -0
- metascalp-1.1.0/metascalp.egg-info/dependency_links.txt +1 -0
- metascalp-1.1.0/metascalp.egg-info/requires.txt +2 -0
- metascalp-1.1.0/metascalp.egg-info/top_level.txt +1 -0
- metascalp-1.1.0/pyproject.toml +31 -0
- metascalp-1.1.0/setup.cfg +4 -0
metascalp-1.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: metascalp
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Summary: Official SDK for MetaScalp API — trade, stream order book and trades via REST and WebSocket
|
|
5
|
+
Author: MetaScalp
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://metascalp.io
|
|
8
|
+
Project-URL: Repository, https://github.com/MetaScalp/metascalp-sdk
|
|
9
|
+
Keywords: metascalp,trading,api,websocket,orderbook,crypto,market-data
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Topic :: Office/Business :: Financial :: Investment
|
|
15
|
+
Requires-Python: >=3.8
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
Requires-Dist: aiohttp>=3.8
|
|
18
|
+
Requires-Dist: websockets>=11.0
|
|
19
|
+
|
|
20
|
+
# MetaScalp SDK
|
|
21
|
+
|
|
22
|
+
Official SDK for [MetaScalp](https://metascalp.io) API — connect your trading bots and scripts to the MetaScalp terminal via REST and WebSocket.
|
|
23
|
+
|
|
24
|
+
MetaScalp exposes a local API that lets you query exchange data, execute trades, and stream real-time market data (trades, order book, mark/index price, funding) and account updates (orders, positions, balances) — plus manage signal levels, plain levels, chart annotations, the notification feed and the terminal UI itself, and stream the MetaBroker analytics feeds (density map, large trades, liquidations).
|
|
25
|
+
|
|
26
|
+
## Available SDKs
|
|
27
|
+
|
|
28
|
+
| Language | Directory | Install |
|
|
29
|
+
|----------|-----------|---------|
|
|
30
|
+
| **JavaScript / TypeScript** | [`js/`](./js) | `npm install metascalp` |
|
|
31
|
+
| **Python** | [`python/`](./python) | `pip install metascalp` |
|
|
32
|
+
| **C# / .NET** | [`dotnet/`](./dotnet) | `dotnet add package MetaScalp.Sdk` |
|
|
33
|
+
|
|
34
|
+
## Quick Start
|
|
35
|
+
|
|
36
|
+
### JavaScript / TypeScript
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import { MetaScalpClient, MetaScalpSocket } from 'metascalp';
|
|
40
|
+
|
|
41
|
+
// REST — discover MetaScalp and query data
|
|
42
|
+
const client = await MetaScalpClient.discover();
|
|
43
|
+
const { connections } = await client.getConnections();
|
|
44
|
+
const conn = connections[0];
|
|
45
|
+
|
|
46
|
+
// Place a limit buy order
|
|
47
|
+
await client.placeOrder(conn.id, {
|
|
48
|
+
ticker: 'BTCUSDT',
|
|
49
|
+
side: 1,
|
|
50
|
+
price: 65000,
|
|
51
|
+
size: 0.01,
|
|
52
|
+
type: 0
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// WebSocket — stream real-time updates
|
|
56
|
+
const socket = await MetaScalpSocket.discover();
|
|
57
|
+
|
|
58
|
+
// Connection-level: orders, positions, balances for ALL tickers on this connection
|
|
59
|
+
socket.subscribe(conn.id);
|
|
60
|
+
socket.on('order_update', (data) => console.log('Order:', data));
|
|
61
|
+
socket.on('position_update', (data) => console.log('Position:', data));
|
|
62
|
+
socket.on('balance_update', (data) => console.log('Balance:', data));
|
|
63
|
+
|
|
64
|
+
// Market data: trades and order book for a SPECIFIC ticker (independent from subscribe)
|
|
65
|
+
socket.subscribeTrades(conn.id, 'BTCUSDT');
|
|
66
|
+
socket.on('trade_update', (data) => console.log('Trade:', data));
|
|
67
|
+
|
|
68
|
+
socket.subscribeOrderBook(conn.id, 'BTCUSDT');
|
|
69
|
+
socket.on('orderbook_snapshot', (data) => console.log('OB Snapshot:', data));
|
|
70
|
+
socket.on('orderbook_update', (data) => console.log('OB Update:', data));
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Python
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
import asyncio
|
|
77
|
+
from metascalp import MetaScalpClient, MetaScalpSocket
|
|
78
|
+
|
|
79
|
+
async def main():
|
|
80
|
+
# REST
|
|
81
|
+
client = await MetaScalpClient.discover()
|
|
82
|
+
connections = await client.get_connections()
|
|
83
|
+
conn = connections['connections'][0]
|
|
84
|
+
|
|
85
|
+
# Place order
|
|
86
|
+
await client.place_order(conn['id'], ticker='BTCUSDT', side=1, price=65000, size=0.01)
|
|
87
|
+
|
|
88
|
+
# WebSocket
|
|
89
|
+
socket = await MetaScalpSocket.discover()
|
|
90
|
+
|
|
91
|
+
# Connection-level events (from subscribe) — all tickers
|
|
92
|
+
@socket.on('order_update')
|
|
93
|
+
def on_order(data):
|
|
94
|
+
print(f"Order: {data['ticker']} {data['side']} {data['status']}")
|
|
95
|
+
|
|
96
|
+
@socket.on('balance_update')
|
|
97
|
+
def on_balance(data):
|
|
98
|
+
print(f"Balance: {data}")
|
|
99
|
+
|
|
100
|
+
# Market data events (from subscribe_trades / subscribe_order_book) — specific ticker
|
|
101
|
+
@socket.on('trade_update')
|
|
102
|
+
def on_trade(data):
|
|
103
|
+
print(f"Trade: {data}")
|
|
104
|
+
|
|
105
|
+
@socket.on('orderbook_snapshot')
|
|
106
|
+
def on_snapshot(data):
|
|
107
|
+
print(f"Snapshot: {len(data['asks'])} asks, {len(data['bids'])} bids")
|
|
108
|
+
|
|
109
|
+
# Connection-level: orders, positions, balances for ALL tickers
|
|
110
|
+
socket.subscribe(conn['id'])
|
|
111
|
+
|
|
112
|
+
# Market data: trades and order book for a SPECIFIC ticker (independent from subscribe)
|
|
113
|
+
socket.subscribe_trades(conn['id'], 'BTCUSDT')
|
|
114
|
+
socket.subscribe_order_book(conn['id'], 'BTCUSDT')
|
|
115
|
+
|
|
116
|
+
await socket.listen_forever()
|
|
117
|
+
|
|
118
|
+
asyncio.run(main())
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### C# / .NET
|
|
122
|
+
|
|
123
|
+
```csharp
|
|
124
|
+
using MetaScalp.Sdk;
|
|
125
|
+
|
|
126
|
+
// REST
|
|
127
|
+
var client = await MetaScalpClient.DiscoverAsync();
|
|
128
|
+
var connections = await client.GetConnectionsAsync();
|
|
129
|
+
var conn = connections.First();
|
|
130
|
+
|
|
131
|
+
await client.PlaceOrderAsync(conn.Id, new PlaceOrderRequest
|
|
132
|
+
{
|
|
133
|
+
Ticker = "BTCUSDT",
|
|
134
|
+
Side = 1,
|
|
135
|
+
Price = 65000m,
|
|
136
|
+
Size = 0.01m,
|
|
137
|
+
Type = 0
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
// WebSocket
|
|
141
|
+
var socket = await MetaScalpSocket.DiscoverAsync();
|
|
142
|
+
|
|
143
|
+
// Connection-level events (from Subscribe) — all tickers
|
|
144
|
+
socket.OnOrderUpdate += (data) => Console.WriteLine($"Order: {data.Ticker} {data.Side} {data.Status}");
|
|
145
|
+
socket.OnBalanceUpdate += (data) => Console.WriteLine($"Balance updated");
|
|
146
|
+
|
|
147
|
+
// Market data events (from SubscribeTrades / SubscribeOrderBook) — specific ticker
|
|
148
|
+
socket.OnTradeUpdate += (data) => Console.WriteLine($"Trade: {data.Ticker} {data.Trades.Count} trades");
|
|
149
|
+
socket.OnOrderBookSnapshot += (data) => Console.WriteLine($"OB: {data.Asks.Count} asks, {data.Bids.Count} bids");
|
|
150
|
+
|
|
151
|
+
// Connection-level: orders, positions, balances for ALL tickers
|
|
152
|
+
socket.Subscribe(conn.Id);
|
|
153
|
+
|
|
154
|
+
// Market data: trades and order book for a SPECIFIC ticker (independent from Subscribe)
|
|
155
|
+
socket.SubscribeTrades(conn.Id, "BTCUSDT");
|
|
156
|
+
socket.SubscribeOrderBook(conn.Id, "BTCUSDT");
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## API Overview
|
|
160
|
+
|
|
161
|
+
Full reference with request/response shapes: [MetaScalp API docs](https://metascalp.github.io/metascalp-sdk/) ([markdown](./docs/MetaScalp-Api.md)).
|
|
162
|
+
|
|
163
|
+
### REST Endpoints
|
|
164
|
+
|
|
165
|
+
| Method | Endpoint | Description |
|
|
166
|
+
|--------|----------|-------------|
|
|
167
|
+
| `GET` | `/ping` | Discover running MetaScalp instance |
|
|
168
|
+
| `GET` | `/api/connections` | List active exchange connections |
|
|
169
|
+
| `GET` | `/api/connections/{id}` | Get single connection details |
|
|
170
|
+
| `GET` | `/api/connections/{id}/tickers` | List available tickers (`?Refresh=true` re-fetches from the exchange) |
|
|
171
|
+
| `GET` | `/api/connections/{id}/orders?Ticker=X` | Get open orders |
|
|
172
|
+
| `GET` | `/api/connections/{id}/positions` | Get open positions |
|
|
173
|
+
| `GET` | `/api/connections/{id}/balance` | Get account balances |
|
|
174
|
+
| `GET` | `/api/connections/{id}/orderbook-snapshot?Ticker=X` | One-shot fresh order book snapshot from the exchange REST endpoint |
|
|
175
|
+
| `GET` | `/api/connections/{id}/cluster-snapshot?Ticker=X&TimeFrame=M5` | Cluster (volume profile) snapshot; `Columns=1..100` fills more history than the default 10 columns |
|
|
176
|
+
| `POST` | `/api/connections/{id}/orders` | Place an order |
|
|
177
|
+
| `POST` | `/api/connections/{id}/orders/cancel` | Cancel an order |
|
|
178
|
+
| `POST` | `/api/connections/{id}/orders/cancel-all` | Cancel all orders for a ticker |
|
|
179
|
+
| `GET/POST/PUT/DELETE` | `/api/connections/{id}/signal-levels[/{slId}]` | Full signal-level CRUD (+ `DELETE /api/signal-levels/triggered`) |
|
|
180
|
+
| `GET/POST/PUT/DELETE` | `/api/connections/{id}/user-levels[/{ulId}]` | Full user (plain) level CRUD |
|
|
181
|
+
| `GET/PUT/POST/DELETE` | `/api/connections/{id}/annotations[/{type}[/{index}]]` | Chart annotations: read all three lists, replace a list, append one, delete by index, clear all |
|
|
182
|
+
| `GET/PUT` | `/api/connections/{id}/orderbook-settings?Ticker=X` | Read / partially update order book settings |
|
|
183
|
+
| `POST` | `/api/notifications` | Inject a custom row into the notification feed |
|
|
184
|
+
| `GET` | `/api/ui/state`, `/api/ui/windows/{windowId}` | Read-only inventory of the open UI (windows, tabs, documents) |
|
|
185
|
+
| `PUT` | `/api/ui/documents/{externalId}/link-number`, `.../ticker` | Set a panel's link group / re-point a panel to another market |
|
|
186
|
+
| `POST` | `/api/change-ticker` | Switch ticker in MetaScalp UI |
|
|
187
|
+
| `POST` | `/api/combo` | Open combo layout |
|
|
188
|
+
|
|
189
|
+
### WebSocket Messages
|
|
190
|
+
|
|
191
|
+
**Connection-level** — subscribe by `connectionId`:
|
|
192
|
+
|
|
193
|
+
| Subscribe | Updates received |
|
|
194
|
+
|-----------|-----------------|
|
|
195
|
+
| `subscribe` | `order_update`, `position_update`, `balance_update`, `finres_update` |
|
|
196
|
+
|
|
197
|
+
**Market data** — subscribe by `connectionId` + `ticker`:
|
|
198
|
+
|
|
199
|
+
| Subscribe | Updates received |
|
|
200
|
+
|-----------|-----------------|
|
|
201
|
+
| `trade_subscribe` | `trade_update` (aggregated ticks carry `highPrice`/`lowPrice`) |
|
|
202
|
+
| `orderbook_subscribe` | `orderbook_snapshot`, `orderbook_update` |
|
|
203
|
+
| `mark_price_subscribe` | `mark_price_update` (futures only) |
|
|
204
|
+
| `index_price_subscribe` | `index_price_update` (futures only) |
|
|
205
|
+
| `funding_subscribe` | `funding_update` (perpetual futures only) |
|
|
206
|
+
| `annotation_subscribe` | one-shot `annotations_snapshot` of the current chart annotations |
|
|
207
|
+
|
|
208
|
+
**App-wide** — no `connectionId` required:
|
|
209
|
+
|
|
210
|
+
| Subscribe | Updates received |
|
|
211
|
+
|-----------|-----------------|
|
|
212
|
+
| `notification_subscribe` | `notification_update` (including custom rows injected via `POST /api/notifications`) |
|
|
213
|
+
| `signal_level_subscribe` | `signal_level_placed/updated/triggered/removed/...` |
|
|
214
|
+
| `user_level_subscribe` | `user_level_placed/updated/removed/...` |
|
|
215
|
+
| `ui_subscribe` | `ui_snapshot`, then `ui_update` on UI changes |
|
|
216
|
+
| `density_map_subscribe` | `density_map_snapshot`, then `density_map_update` — MetaBroker order-book walls, one notification per wall |
|
|
217
|
+
| `large_trades_subscribe` | `large_trades_update` — MetaBroker aggregated large trade prints (append-only, no snapshot) |
|
|
218
|
+
| `liquidations_subscribe` | `liquidations_snapshot`, `liquidations_update`, `liquidations_metadata` — MetaBroker cross-exchange liquidations (no MetaBroker login needed) |
|
|
219
|
+
|
|
220
|
+
> **SDK coverage note.** The js / python / dotnet convenience wrappers currently cover the core surface (connections, orders, positions, balances, market data) plus the MetaBroker analytics streams (density map, large trades, liquidations). The newer families (levels, annotations, notifications, UI) are available through the same clients as plain REST calls / raw WS messages until dedicated wrappers ship.
|
|
221
|
+
|
|
222
|
+
> **Mass-subscribe optimization.** `orderbook_subscribe` accepts an optional `fetchSnapshot` field (default `true`). Pass `false` to skip the exchange REST snapshot fetch when subscribing — useful when subscribing to 100+ tickers at once without hitting exchange REST rate limits. Seed state separately via `GET /api/connections/{id}/orderbook-snapshot` when you need it. A later subscriber that wants a snapshot triggers a lazy fetch that fans out to all listeners.
|
|
223
|
+
|
|
224
|
+
## Connection Details
|
|
225
|
+
|
|
226
|
+
- **Host:** `127.0.0.1` (localhost only)
|
|
227
|
+
- **Port range:** `17845`–`17855` (first available, shared by HTTP and WebSocket)
|
|
228
|
+
- Both REST and WebSocket run on the same port — no separate socket port
|
|
229
|
+
- All SDKs include auto-discovery that scans the port range
|
|
230
|
+
|
|
231
|
+
## License
|
|
232
|
+
|
|
233
|
+
MIT
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
# MetaScalp SDK
|
|
2
|
+
|
|
3
|
+
Official SDK for [MetaScalp](https://metascalp.io) API — connect your trading bots and scripts to the MetaScalp terminal via REST and WebSocket.
|
|
4
|
+
|
|
5
|
+
MetaScalp exposes a local API that lets you query exchange data, execute trades, and stream real-time market data (trades, order book, mark/index price, funding) and account updates (orders, positions, balances) — plus manage signal levels, plain levels, chart annotations, the notification feed and the terminal UI itself, and stream the MetaBroker analytics feeds (density map, large trades, liquidations).
|
|
6
|
+
|
|
7
|
+
## Available SDKs
|
|
8
|
+
|
|
9
|
+
| Language | Directory | Install |
|
|
10
|
+
|----------|-----------|---------|
|
|
11
|
+
| **JavaScript / TypeScript** | [`js/`](./js) | `npm install metascalp` |
|
|
12
|
+
| **Python** | [`python/`](./python) | `pip install metascalp` |
|
|
13
|
+
| **C# / .NET** | [`dotnet/`](./dotnet) | `dotnet add package MetaScalp.Sdk` |
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
### JavaScript / TypeScript
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { MetaScalpClient, MetaScalpSocket } from 'metascalp';
|
|
21
|
+
|
|
22
|
+
// REST — discover MetaScalp and query data
|
|
23
|
+
const client = await MetaScalpClient.discover();
|
|
24
|
+
const { connections } = await client.getConnections();
|
|
25
|
+
const conn = connections[0];
|
|
26
|
+
|
|
27
|
+
// Place a limit buy order
|
|
28
|
+
await client.placeOrder(conn.id, {
|
|
29
|
+
ticker: 'BTCUSDT',
|
|
30
|
+
side: 1,
|
|
31
|
+
price: 65000,
|
|
32
|
+
size: 0.01,
|
|
33
|
+
type: 0
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// WebSocket — stream real-time updates
|
|
37
|
+
const socket = await MetaScalpSocket.discover();
|
|
38
|
+
|
|
39
|
+
// Connection-level: orders, positions, balances for ALL tickers on this connection
|
|
40
|
+
socket.subscribe(conn.id);
|
|
41
|
+
socket.on('order_update', (data) => console.log('Order:', data));
|
|
42
|
+
socket.on('position_update', (data) => console.log('Position:', data));
|
|
43
|
+
socket.on('balance_update', (data) => console.log('Balance:', data));
|
|
44
|
+
|
|
45
|
+
// Market data: trades and order book for a SPECIFIC ticker (independent from subscribe)
|
|
46
|
+
socket.subscribeTrades(conn.id, 'BTCUSDT');
|
|
47
|
+
socket.on('trade_update', (data) => console.log('Trade:', data));
|
|
48
|
+
|
|
49
|
+
socket.subscribeOrderBook(conn.id, 'BTCUSDT');
|
|
50
|
+
socket.on('orderbook_snapshot', (data) => console.log('OB Snapshot:', data));
|
|
51
|
+
socket.on('orderbook_update', (data) => console.log('OB Update:', data));
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Python
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
import asyncio
|
|
58
|
+
from metascalp import MetaScalpClient, MetaScalpSocket
|
|
59
|
+
|
|
60
|
+
async def main():
|
|
61
|
+
# REST
|
|
62
|
+
client = await MetaScalpClient.discover()
|
|
63
|
+
connections = await client.get_connections()
|
|
64
|
+
conn = connections['connections'][0]
|
|
65
|
+
|
|
66
|
+
# Place order
|
|
67
|
+
await client.place_order(conn['id'], ticker='BTCUSDT', side=1, price=65000, size=0.01)
|
|
68
|
+
|
|
69
|
+
# WebSocket
|
|
70
|
+
socket = await MetaScalpSocket.discover()
|
|
71
|
+
|
|
72
|
+
# Connection-level events (from subscribe) — all tickers
|
|
73
|
+
@socket.on('order_update')
|
|
74
|
+
def on_order(data):
|
|
75
|
+
print(f"Order: {data['ticker']} {data['side']} {data['status']}")
|
|
76
|
+
|
|
77
|
+
@socket.on('balance_update')
|
|
78
|
+
def on_balance(data):
|
|
79
|
+
print(f"Balance: {data}")
|
|
80
|
+
|
|
81
|
+
# Market data events (from subscribe_trades / subscribe_order_book) — specific ticker
|
|
82
|
+
@socket.on('trade_update')
|
|
83
|
+
def on_trade(data):
|
|
84
|
+
print(f"Trade: {data}")
|
|
85
|
+
|
|
86
|
+
@socket.on('orderbook_snapshot')
|
|
87
|
+
def on_snapshot(data):
|
|
88
|
+
print(f"Snapshot: {len(data['asks'])} asks, {len(data['bids'])} bids")
|
|
89
|
+
|
|
90
|
+
# Connection-level: orders, positions, balances for ALL tickers
|
|
91
|
+
socket.subscribe(conn['id'])
|
|
92
|
+
|
|
93
|
+
# Market data: trades and order book for a SPECIFIC ticker (independent from subscribe)
|
|
94
|
+
socket.subscribe_trades(conn['id'], 'BTCUSDT')
|
|
95
|
+
socket.subscribe_order_book(conn['id'], 'BTCUSDT')
|
|
96
|
+
|
|
97
|
+
await socket.listen_forever()
|
|
98
|
+
|
|
99
|
+
asyncio.run(main())
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### C# / .NET
|
|
103
|
+
|
|
104
|
+
```csharp
|
|
105
|
+
using MetaScalp.Sdk;
|
|
106
|
+
|
|
107
|
+
// REST
|
|
108
|
+
var client = await MetaScalpClient.DiscoverAsync();
|
|
109
|
+
var connections = await client.GetConnectionsAsync();
|
|
110
|
+
var conn = connections.First();
|
|
111
|
+
|
|
112
|
+
await client.PlaceOrderAsync(conn.Id, new PlaceOrderRequest
|
|
113
|
+
{
|
|
114
|
+
Ticker = "BTCUSDT",
|
|
115
|
+
Side = 1,
|
|
116
|
+
Price = 65000m,
|
|
117
|
+
Size = 0.01m,
|
|
118
|
+
Type = 0
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// WebSocket
|
|
122
|
+
var socket = await MetaScalpSocket.DiscoverAsync();
|
|
123
|
+
|
|
124
|
+
// Connection-level events (from Subscribe) — all tickers
|
|
125
|
+
socket.OnOrderUpdate += (data) => Console.WriteLine($"Order: {data.Ticker} {data.Side} {data.Status}");
|
|
126
|
+
socket.OnBalanceUpdate += (data) => Console.WriteLine($"Balance updated");
|
|
127
|
+
|
|
128
|
+
// Market data events (from SubscribeTrades / SubscribeOrderBook) — specific ticker
|
|
129
|
+
socket.OnTradeUpdate += (data) => Console.WriteLine($"Trade: {data.Ticker} {data.Trades.Count} trades");
|
|
130
|
+
socket.OnOrderBookSnapshot += (data) => Console.WriteLine($"OB: {data.Asks.Count} asks, {data.Bids.Count} bids");
|
|
131
|
+
|
|
132
|
+
// Connection-level: orders, positions, balances for ALL tickers
|
|
133
|
+
socket.Subscribe(conn.Id);
|
|
134
|
+
|
|
135
|
+
// Market data: trades and order book for a SPECIFIC ticker (independent from Subscribe)
|
|
136
|
+
socket.SubscribeTrades(conn.Id, "BTCUSDT");
|
|
137
|
+
socket.SubscribeOrderBook(conn.Id, "BTCUSDT");
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## API Overview
|
|
141
|
+
|
|
142
|
+
Full reference with request/response shapes: [MetaScalp API docs](https://metascalp.github.io/metascalp-sdk/) ([markdown](./docs/MetaScalp-Api.md)).
|
|
143
|
+
|
|
144
|
+
### REST Endpoints
|
|
145
|
+
|
|
146
|
+
| Method | Endpoint | Description |
|
|
147
|
+
|--------|----------|-------------|
|
|
148
|
+
| `GET` | `/ping` | Discover running MetaScalp instance |
|
|
149
|
+
| `GET` | `/api/connections` | List active exchange connections |
|
|
150
|
+
| `GET` | `/api/connections/{id}` | Get single connection details |
|
|
151
|
+
| `GET` | `/api/connections/{id}/tickers` | List available tickers (`?Refresh=true` re-fetches from the exchange) |
|
|
152
|
+
| `GET` | `/api/connections/{id}/orders?Ticker=X` | Get open orders |
|
|
153
|
+
| `GET` | `/api/connections/{id}/positions` | Get open positions |
|
|
154
|
+
| `GET` | `/api/connections/{id}/balance` | Get account balances |
|
|
155
|
+
| `GET` | `/api/connections/{id}/orderbook-snapshot?Ticker=X` | One-shot fresh order book snapshot from the exchange REST endpoint |
|
|
156
|
+
| `GET` | `/api/connections/{id}/cluster-snapshot?Ticker=X&TimeFrame=M5` | Cluster (volume profile) snapshot; `Columns=1..100` fills more history than the default 10 columns |
|
|
157
|
+
| `POST` | `/api/connections/{id}/orders` | Place an order |
|
|
158
|
+
| `POST` | `/api/connections/{id}/orders/cancel` | Cancel an order |
|
|
159
|
+
| `POST` | `/api/connections/{id}/orders/cancel-all` | Cancel all orders for a ticker |
|
|
160
|
+
| `GET/POST/PUT/DELETE` | `/api/connections/{id}/signal-levels[/{slId}]` | Full signal-level CRUD (+ `DELETE /api/signal-levels/triggered`) |
|
|
161
|
+
| `GET/POST/PUT/DELETE` | `/api/connections/{id}/user-levels[/{ulId}]` | Full user (plain) level CRUD |
|
|
162
|
+
| `GET/PUT/POST/DELETE` | `/api/connections/{id}/annotations[/{type}[/{index}]]` | Chart annotations: read all three lists, replace a list, append one, delete by index, clear all |
|
|
163
|
+
| `GET/PUT` | `/api/connections/{id}/orderbook-settings?Ticker=X` | Read / partially update order book settings |
|
|
164
|
+
| `POST` | `/api/notifications` | Inject a custom row into the notification feed |
|
|
165
|
+
| `GET` | `/api/ui/state`, `/api/ui/windows/{windowId}` | Read-only inventory of the open UI (windows, tabs, documents) |
|
|
166
|
+
| `PUT` | `/api/ui/documents/{externalId}/link-number`, `.../ticker` | Set a panel's link group / re-point a panel to another market |
|
|
167
|
+
| `POST` | `/api/change-ticker` | Switch ticker in MetaScalp UI |
|
|
168
|
+
| `POST` | `/api/combo` | Open combo layout |
|
|
169
|
+
|
|
170
|
+
### WebSocket Messages
|
|
171
|
+
|
|
172
|
+
**Connection-level** — subscribe by `connectionId`:
|
|
173
|
+
|
|
174
|
+
| Subscribe | Updates received |
|
|
175
|
+
|-----------|-----------------|
|
|
176
|
+
| `subscribe` | `order_update`, `position_update`, `balance_update`, `finres_update` |
|
|
177
|
+
|
|
178
|
+
**Market data** — subscribe by `connectionId` + `ticker`:
|
|
179
|
+
|
|
180
|
+
| Subscribe | Updates received |
|
|
181
|
+
|-----------|-----------------|
|
|
182
|
+
| `trade_subscribe` | `trade_update` (aggregated ticks carry `highPrice`/`lowPrice`) |
|
|
183
|
+
| `orderbook_subscribe` | `orderbook_snapshot`, `orderbook_update` |
|
|
184
|
+
| `mark_price_subscribe` | `mark_price_update` (futures only) |
|
|
185
|
+
| `index_price_subscribe` | `index_price_update` (futures only) |
|
|
186
|
+
| `funding_subscribe` | `funding_update` (perpetual futures only) |
|
|
187
|
+
| `annotation_subscribe` | one-shot `annotations_snapshot` of the current chart annotations |
|
|
188
|
+
|
|
189
|
+
**App-wide** — no `connectionId` required:
|
|
190
|
+
|
|
191
|
+
| Subscribe | Updates received |
|
|
192
|
+
|-----------|-----------------|
|
|
193
|
+
| `notification_subscribe` | `notification_update` (including custom rows injected via `POST /api/notifications`) |
|
|
194
|
+
| `signal_level_subscribe` | `signal_level_placed/updated/triggered/removed/...` |
|
|
195
|
+
| `user_level_subscribe` | `user_level_placed/updated/removed/...` |
|
|
196
|
+
| `ui_subscribe` | `ui_snapshot`, then `ui_update` on UI changes |
|
|
197
|
+
| `density_map_subscribe` | `density_map_snapshot`, then `density_map_update` — MetaBroker order-book walls, one notification per wall |
|
|
198
|
+
| `large_trades_subscribe` | `large_trades_update` — MetaBroker aggregated large trade prints (append-only, no snapshot) |
|
|
199
|
+
| `liquidations_subscribe` | `liquidations_snapshot`, `liquidations_update`, `liquidations_metadata` — MetaBroker cross-exchange liquidations (no MetaBroker login needed) |
|
|
200
|
+
|
|
201
|
+
> **SDK coverage note.** The js / python / dotnet convenience wrappers currently cover the core surface (connections, orders, positions, balances, market data) plus the MetaBroker analytics streams (density map, large trades, liquidations). The newer families (levels, annotations, notifications, UI) are available through the same clients as plain REST calls / raw WS messages until dedicated wrappers ship.
|
|
202
|
+
|
|
203
|
+
> **Mass-subscribe optimization.** `orderbook_subscribe` accepts an optional `fetchSnapshot` field (default `true`). Pass `false` to skip the exchange REST snapshot fetch when subscribing — useful when subscribing to 100+ tickers at once without hitting exchange REST rate limits. Seed state separately via `GET /api/connections/{id}/orderbook-snapshot` when you need it. A later subscriber that wants a snapshot triggers a lazy fetch that fans out to all listeners.
|
|
204
|
+
|
|
205
|
+
## Connection Details
|
|
206
|
+
|
|
207
|
+
- **Host:** `127.0.0.1` (localhost only)
|
|
208
|
+
- **Port range:** `17845`–`17855` (first available, shared by HTTP and WebSocket)
|
|
209
|
+
- Both REST and WebSocket run on the same port — no separate socket port
|
|
210
|
+
- All SDKs include auto-discovery that scans the port range
|
|
211
|
+
|
|
212
|
+
## License
|
|
213
|
+
|
|
214
|
+
MIT
|