MetaScalp API

SDK & Source metascalp.io
Searching...

Connect your scripts and bots to MetaScalp to interact with exchange connections. Use HTTP REST to query data and execute trades, or WebSocket to receive real-time order, position, and balance updates.

HTTP API: Host: 127.0.0.1   Ports: 1784517855   CORS enabled for all origins.

Socket API: Host: 127.0.0.1   Same port as HTTP   Endpoint: ws://127.0.0.1:{port}/

Getting started: 1. Launch MetaScalp. 2. Discover the HTTP port with GET /ping. 3. List connections with GET /api/connections. 4. Use connection IDs for REST or WebSocket operations.   Full documentation

Discovery
GET /ping Discover running instance

Scan ports 1784517855 to find the running MetaScalp instance. Returns the app name and version.

Ticker
POST /api/change-ticker Switch ticker in MetaScalp UI

Changes the current ticker. The active window is always notified. When a named binding is provided, that binding's linked panels are also updated.

Accepts two request formats: a ticker pattern string (e.g. BINANCE:BTCUSDT.p) or explicit fields (exchange + market + ticker).

A binding is a named group of linked panels inside MetaScalp (e.g. a chart, order book, and trade feed showing the same ticker). Bindings are numbered "001""500" and configured by the user in the MetaScalp UI.

Format: EXCHANGE:SYMBOL.suffix — suffix: .p (futures), .m (margin), .o (options), omitted (spot)
Exchange and suffix are optional. Symbol may contain letters, digits, _, /, -, $, :.
Examples: BINANCE:BTCUSDT.p, BYBIT:ETHUSDT, OKX:BTC-USDT.m, HYPERLIQUID:cash:HOODUSDT0.p
Combo
POST /api/combo Open combo layout

Opens a combo layout for the specified ticker in the MetaScalp UI.

Connections
GET /api/connections List active exchange connections

Returns all currently active exchange connections. Use the id from the response to query orders, positions, balances, or to subscribe via WebSocket.

FieldTypeDescription
idintegerConnection ID — use for all exchange operations
namestringUser-defined connection name
exchangestringExchange name
exchangeIdintegerExchange identifier
marketstringMarket display name
marketTypeintegerMarket type enum value
stateinteger0=Disconnected, 1=Connecting, 2=Connected, 3=Reconnecting, 4=Resetting
viewModebooleanRead-only (no trading)
demoModebooleanPaper trading
GET /api/connections/{connectionId} Get single connection

Returns details for a single connection by ID.

Trading Operations
GET /api/connections/{connectionId}/tickers Get available tickers

Returns all available trading pairs on a connection with price/size precision, trading status, and constraints.

GET /api/connections/{connectionId}/orders?Ticker=... Get open orders

Returns open orders for a specific ticker on a connection. The Ticker query parameter is required.

FieldTypeDescription
idintegerExchange order ID
tickerstringTrading pair
clientIdstring?Client-generated order ID
sideinteger0 None, 1 Buy, 2 Sell
pricedecimalOrder price
sizedecimalOrder size
filledSizedecimalFilled amount
filledPricedecimalExecution price (0 if not yet filled)
remainingSizedecimalRemaining amount
statusinteger0 New, 1 Open, 2 Closed
typeinteger0 Limit, 1 Stop, 2 StopLoss, 3 TakeProfit, 4 Market
triggerPricedecimal?Trigger price for stop/conditional orders
createDatestring (ISO)Order creation timestamp
GET /api/connections/{connectionId}/positions Get open positions

Returns all open positions on a connection (futures/margin markets).

GET /api/connections/{connectionId}/balance Get account balance

Returns account balances for all assets on a connection.

POST /api/connections/{connectionId}/orders Place order

Places a new order on the exchange through a connection. Returns an auto-generated clientId for order tracking and executionTimeMs indicating how long the exchange request took (in milliseconds).

FieldTypeRequiredDescription
tickerstringyesTrading pair symbol
sideintegeryes1 Buy, 2 Sell
pricedecimalyes*Order price (*required for non-market orders)
sizedecimalyesOrder size (must be > 0)
typeintegerno0 Limit (default), 1 Stop, 2 StopLoss, 3 TakeProfit, 4 Market
reduceOnlybooleannoClose-only, default false
POST /api/connections/{connectionId}/orders/cancel Cancel order

Cancels an existing order on the exchange.

FieldTypeRequiredDescription
tickerstringyesTrading pair symbol
orderIdintegeryesExchange order ID
typeintegernoOrder type (default 0 Limit)
POST /api/connections/{connectionId}/orders/cancel-all Cancel all orders

Cancels all open orders for a given ticker on the exchange.

FieldTypeRequiredDescription
tickerstringyesTrading pair symbol

Returns cancelledCount: 0 if there are no open orders for that ticker.

Real-time WebSocket
WS ws://127.0.0.1:{port}/ Real-time updates via WebSocket

Connect via WebSocket to receive real-time updates for your exchange connections. Subscribe by connection ID for order, position, balance, and finres events. Subscribe by connection ID + ticker for real-time trade and order book market data.

Connection

The WebSocket server shares the same port as the HTTP API (1784517855). Connect to ws://127.0.0.1:{port}/.

Message format

All messages (inbound and outbound) are JSON with this envelope:

{ "type": "message_type", "data": { ... } }

Inbound messages (client → server)

Connection-level — subscribe by connection ID for order, position, balance, and finres updates:

TypeDataDescription
subscribe{ "connectionId": 123 }Subscribe to updates for a connection. Connection must be active. Idempotent.
unsubscribe{ "connectionId": 123 }Stop receiving updates for a connection. Idempotent.

Market data — subscribe by connection ID + ticker for trade or order book updates:

TypeDataDescription
trade_subscribe{ "connectionId": 123, "ticker": "BTCUSDT" }Subscribe to real-time trade updates for a specific ticker. Idempotent.
trade_unsubscribe{ "connectionId": 123, "ticker": "BTCUSDT" }Stop receiving trade updates for that ticker. Idempotent.
orderbook_subscribe{ "connectionId": 123, "ticker": "BTCUSDT" }Subscribe to order book updates (snapshot + incremental). Idempotent.
orderbook_unsubscribe{ "connectionId": 123, "ticker": "BTCUSDT" }Stop receiving order book updates for that ticker. Idempotent.

Outbound messages (server → client)

Acknowledgements:

TypeWhenData fields
subscribedAfter successful connection subscribeconnectionId
unsubscribedAfter successful connection unsubscribeconnectionId
trade_subscribedAfter successful trade subscribeconnectionId, ticker
trade_unsubscribedAfter successful trade unsubscribeconnectionId, ticker
orderbook_subscribedAfter successful order book subscribeconnectionId, ticker
orderbook_unsubscribedAfter successful order book unsubscribeconnectionId, ticker
errorInvalid message, bad connection ID, or missing tickererror (string)

Connection-level updates:

TypeWhenData fields
order_updateOrder created/changed/filled/cancelledconnectionId, orderId, ticker, side, type, price, filledPrice, size, filledSize, fee, feeCurrency, status, time
position_updatePosition opened/changed/closedconnectionId, positionId, ticker, side, size, avgPrice, avgPriceFix, avgPriceDyn, status
balance_updateAccount balance changedconnectionId, balances[] with coin, total, free, locked
finres_updateFinancial results updatedconnectionId, finreses[] with currency, result, fee, funds, available, blocked

Market data updates:

TypeWhenData fields
trade_updateNew trades for subscribed tickerconnectionId, ticker, trades[] with price, size, side, time
orderbook_snapshotFull order book on subscribeconnectionId, ticker, asks[], bids[], bestAsk, bestBid — each with price, size, type
orderbook_updateIncremental order book changesconnectionId, ticker, updates[] with price, size, type

Lifecycle

EventBehavior
Client connectsSession created. No updates until subscribe.
Subscribe (valid ID)Server responds with subscribed. Order, position, balance, finres updates start flowing.
Subscribe (invalid ID)Server responds with error. No subscription created.
Subscribe (already subscribed)Idempotent — responds with confirmation, no duplicate events.
Trade/orderbook subscribe (valid)Server responds with trade_subscribed / orderbook_subscribed. Market data starts flowing for that ticker.
Trade/orderbook subscribe (invalid)Server responds with error (bad connection ID or missing ticker).
UnsubscribeServer responds with confirmation. Updates stop for that subscription.
Client disconnectsAll subscriptions (connection-level and market data) are cleaned up automatically.
Multiple connectionsA single client can subscribe to multiple connection IDs and multiple tickers simultaneously.

Example payloads

// Subscribe
{ "type": "subscribe", "data": { "connectionId": 1 } }

// Server confirms
{ "type": "subscribed", "data": { "connectionId": 1 } }

// Order update pushed by server
{
  "type": "order_update",
  "data": {
    "connectionId": 1,
    "orderId": 98765,
    "ticker": "BTCUSDT",
    "side": "Buy",
    "type": "Limit",
    "price": 65000.0,
    "filledPrice": 64980.5,
    "size": 0.01,
    "filledSize": 0.0,
    "fee": 0.0013,
    "feeCurrency": "USDT",
    "status": "New",
    "time": "2025-03-24T14:30:00+00:00"
  }
}

// Position update pushed by server
{
  "type": "position_update",
  "data": {
    "connectionId": 1,
    "positionId": 4321,
    "ticker": "ETHUSDT",
    "side": "Buy",
    "size": 1.5,
    "avgPrice": 3200.00,
    "avgPriceFix": 3200.00,
    "avgPriceDyn": 3195.50,
    "status": "Open"
  }
}

// Balance update pushed by server
{
  "type": "balance_update",
  "data": {
    "connectionId": 1,
    "balances": [
      { "coin": "USDT", "total": 10000.0, "free": 8500.0, "locked": 1500.0 },
      { "coin": "BTC", "total": 0.5, "free": 0.5, "locked": 0.0 }
    ]
  }
}

// FinRes update pushed by server
{
  "type": "finres_update",
  "data": {
    "connectionId": 1,
    "finreses": [
      { "currency": "USDT", "result": 250.50, "fee": 12.30, "funds": 10000.0, "available": 8500.0, "blocked": 1500.0 },
      { "currency": "BTC", "result": 0.005, "fee": 0.0001, "funds": 0.5, "available": 0.5, "blocked": 0.0 }
    ]
  }
}

// Subscribe to trades for a specific ticker
{ "type": "trade_subscribe", "data": { "connectionId": 1, "ticker": "BTCUSDT" } }

// Server confirms trade subscription
{ "type": "trade_subscribed", "data": { "connectionId": 1, "ticker": "BTCUSDT" } }

// Trade update pushed by server
{
  "type": "trade_update",
  "data": {
    "connectionId": 1,
    "ticker": "BTCUSDT",
    "trades": [
      { "price": 65123.50, "size": 0.15, "side": "Buy", "time": "2026-03-16T12:00:01.234+00:00" },
      { "price": 65123.00, "size": 0.03, "side": "Sell", "time": "2026-03-16T12:00:01.235+00:00" }
    ]
  }
}

// Subscribe to order book for a specific ticker
{ "type": "orderbook_subscribe", "data": { "connectionId": 1, "ticker": "BTCUSDT" } }

// Server confirms order book subscription
{ "type": "orderbook_subscribed", "data": { "connectionId": 1, "ticker": "BTCUSDT" } }

// Order book snapshot (full state, sent once on subscribe)
{
  "type": "orderbook_snapshot",
  "data": {
    "connectionId": 1,
    "ticker": "BTCUSDT",
    "asks": [
      { "price": 65124.00, "size": 1.20, "type": "Ask" },
      { "price": 65125.00, "size": 0.85, "type": "Ask" }
    ],
    "bids": [
      { "price": 65123.00, "size": 2.50, "type": "Bid" },
      { "price": 65122.00, "size": 1.10, "type": "Bid" }
    ],
    "bestAsk": { "price": 65124.00, "size": 1.20, "type": "BestAsk" },
    "bestBid": { "price": 65123.00, "size": 2.50, "type": "BestBid" }
  }
}

// Order book incremental update
{
  "type": "orderbook_update",
  "data": {
    "connectionId": 1,
    "ticker": "BTCUSDT",
    "updates": [
      { "price": 65124.00, "size": 0.90, "type": "Ask" },
      { "price": 65126.00, "size": 0.50, "type": "Ask" },
      { "price": 65123.00, "size": 2.80, "type": "Bid" }
    ]
  }
}

// Unsubscribe from market data
{ "type": "trade_unsubscribe", "data": { "connectionId": 1, "ticker": "BTCUSDT" } }
{ "type": "orderbook_unsubscribe", "data": { "connectionId": 1, "ticker": "BTCUSDT" } }

// Unsubscribe from connection
{ "type": "unsubscribe", "data": { "connectionId": 1 } }

// Error (invalid connection)
{ "type": "error", "data": { "error": "Connection 999 not found or not active" } }

Disconnected
Waiting for connection...
Subscribe to order book
to see live depth
Subscribe to trades
to see live feed

Reference

Exchange values

ValueExchange
2Binance
3Gate
5KuCoin
6Bybit
7Bitget
8Mexc
10Okx
11BingX
12HTX
13BitMart
14LBank
15HyperLiquid
16UpBit
17AsterDex
18Moex
19Lighter

MarketType values

ValueTypeDescription
0SpotSpot trading
1FuturesGeneric futures
2UsdtFuturesUSDT-margined futures
3CoinFuturesCoin-margined futures
4InverseFuturesInverse futures
5UsdtPerpetualUSDT perpetual swaps
6UsdcPerpetualUSDC perpetual swaps
7MarginMargin (cross/isolated)
8OptionsOptions contracts
9StockStock / equity markets
Unsure which market type to use? Use the ticker pattern approach instead — the .p suffix auto-resolves to the right futures type. For explicit fields, 2 (UsdtFutures) is the most common choice for perpetual futures.
When the requested market is not Spot and no exact match is found, MetaScalp falls back to any non-Spot connection on the same exchange.

Error responses

Errors return HTTP 400 or 404 with a JSON body.

EndpointConditionHTTPError message
/api/change-tickerMissing fields400Invalid request body. Provide 'tickerPattern' or 'exchange'+'market'+'ticker'.
/api/change-tickerInvalid pattern400Invalid ticker pattern: '{pattern}'
/api/change-tickerBinding not found400Binding '{name}' not found. Available: {list}
/api/change-tickerNo connection400No connection found for exchange ... and market ...
/api/change-tickerTicker not on connection400Ticker '{ticker}' not found on connection {id}
/api/comboMissing ticker400Invalid request body. 'ticker' is required.
/api/connections/{id}Connection not found404Connection {id} not found
/api/connections/{id}/...Invalid connection ID400Invalid connection ID
/api/connections/{id}/...Connection not found404Connection {id} not found
/api/connections/{id}/...Connection not active400Connection {id} is not active
/api/connections/{id}/ordersMissing ticker query param400Query parameter 'Ticker' is required
/api/connections/{id}/ordersInvalid order fields400Invalid request body. 'ticker', 'side', 'price', and 'size' are required.
/api/connections/{id}/ordersSize <= 0400Size must be greater than zero
/api/connections/{id}/ordersPrice <= 0 (non-market)400Price must be greater than zero for non-market orders
/api/connections/{id}/orders/cancelMissing fields400Invalid request body. 'ticker' and 'orderId' are required.
/api/connections/{id}/orders/cancel-allMissing ticker400Invalid request body. 'ticker' is required.
anyUnknown path400Not found
anyWrong HTTP method400Method not allowed

Socket error messages

Socket errors are sent as { "type": "error", "data": { "error": "..." } }

ConditionError message
Subscribe to non-existent connectionConnection {id} not found or not active
Trade/orderbook subscribe with missing tickerTicker is required for trade subscription / Ticker is required for order book subscription
Trade/orderbook subscribe with invalid connectionConnection {id} not found or not active
Unknown message typeUnknown message type: {type}
Invalid JSONInvalid message format

📄 MetaScalp-Api.md

⬇ Download .md

MetaScalp API

MetaScalp exposes a local API that lets your scripts and bots interact with connected exchanges. Use HTTP REST endpoints for request/response operations and WebSocket for real-time streaming of orders, positions, balances, trades, and order book data.

  • Host: 127.0.0.1 (localhost only)
  • HTTP port range: 1784517855 (first available)
  • WebSocket: Same port as HTTP (upgrade requests accepted automatically)
  • Content-Type: application/json
  • CORS: All responses include Access-Control-Allow-Origin: *.

Overview

HTTP REST endpoints

Use HTTP to discover connections, query data, and execute trades:

EndpointPurpose
GET /pingFind the running MetaScalp instance and check its version
POST /api/change-tickerSwitch the active ticker in the MetaScalp UI
POST /api/comboOpen a combo layout for a ticker
GET /api/connectionsList all active exchange connections
GET /api/connections/{id}/...Query tickers, orders, positions, balances for a connection
POST /api/connections/{id}/ordersPlace an order on a connection
POST /api/connections/{id}/orders/cancelCancel a single order
POST /api/connections/{id}/orders/cancel-allCancel all orders for a ticker

WebSocket streaming

Connect via WebSocket to receive real-time updates for your exchange connections.

  • Connect to ws://127.0.0.1:{port}/ (same port as HTTP — scan 1784517855)
  • Connection-level: Send subscribe with a connection ID to receive order, position, balance, and finres updates
  • Market data: Send trade_subscribe or orderbook_subscribe with connection ID + ticker to receive trade or order book updates
  • You can subscribe to multiple connections and tickers simultaneously
  • All subscriptions are automatically cleaned up when you disconnect

Getting started

1. Launch MetaScalp — both HTTP and WebSocket servers start automatically.

2. Discover the port — scan 1784517855 with GET /ping.

3. List connections — call GET /api/connections to see available exchange connections.

4. Execute operations — use a connection ID for REST queries or WebSocket subscriptions.

Typical REST client flow

GET /ping                                         → find MetaScalp
GET /api/connections                              → list active connections
GET /api/connections/{id}/tickers                 → get available tickers
GET /api/connections/{id}/balance                 → check balances
GET /api/connections/{id}/orders?Ticker=BTCUSDT   → view open orders
POST /api/connections/{id}/orders                 → place an order
POST /api/connections/{id}/orders/cancel          → cancel an order
POST /api/connections/{id}/orders/cancel-all      → cancel all orders for a ticker

Typical WebSocket client flow

1. Connect
ws = new WebSocket("ws://127.0.0.1:17845/")

2. Subscribe to a connection (orders, positions, balances, finres)
ws.send('{"type":"subscribe","data":{"connectionId":1}}')
← {"type":"subscribed","data":{"connectionId":1}}

3. Subscribe to market data for a specific ticker
ws.send('{"type":"trade_subscribe","data":{"connectionId":1,"ticker":"BTCUSDT"}}')
← {"type":"trade_subscribed","data":{"connectionId":1,"ticker":"BTCUSDT"}}
ws.send('{"type":"orderbook_subscribe","data":{"connectionId":1,"ticker":"BTCUSDT"}}')
← {"type":"orderbook_subscribed","data":{"connectionId":1,"ticker":"BTCUSDT"}}

4. Receive real-time updates
← {"type":"order_update","data":{"connectionId":1,"orderId":123,...}}
← {"type":"position_update","data":{"connectionId":1,...}}
← {"type":"balance_update","data":{"connectionId":1,"balances":[...]}}
← {"type":"finres_update","data":{"connectionId":1,"finreses":[...]}}
← {"type":"trade_update","data":{"connectionId":1,"ticker":"BTCUSDT","trades":[...]}}
← {"type":"orderbook_snapshot","data":{"connectionId":1,"ticker":"BTCUSDT","asks":[...],"bids":[...],...}}
← {"type":"orderbook_update","data":{"connectionId":1,"ticker":"BTCUSDT","updates":[...]}}

5. Unsubscribe when done
ws.send('{"type":"trade_unsubscribe","data":{"connectionId":1,"ticker":"BTCUSDT"}}')
ws.send('{"type":"orderbook_unsubscribe","data":{"connectionId":1,"ticker":"BTCUSDT"}}')
ws.send('{"type":"unsubscribe","data":{"connectionId":1}}')
← {"type":"unsubscribed","data":{"connectionId":1}}

WebSocket message reference

Messages you send

TypeDataDescription
subscribe{ "connectionId": 123 }Start receiving order, position, balance, finres updates for a connection.
unsubscribe{ "connectionId": 123 }Stop receiving connection-level updates.
trade_subscribe{ "connectionId": 123, "ticker": "BTCUSDT" }Start receiving trade updates for a specific ticker.
trade_unsubscribe{ "connectionId": 123, "ticker": "BTCUSDT" }Stop receiving trade updates for that ticker.
orderbook_subscribe{ "connectionId": 123, "ticker": "BTCUSDT" }Start receiving order book snapshot + incremental updates for a specific ticker.
orderbook_unsubscribe{ "connectionId": 123, "ticker": "BTCUSDT" }Stop receiving order book updates for that ticker.

Messages you receive

TypeData fields
subscribedconnectionId
unsubscribedconnectionId
trade_subscribedconnectionId, ticker
trade_unsubscribedconnectionId, ticker
orderbook_subscribedconnectionId, ticker
orderbook_unsubscribedconnectionId, ticker
order_updateconnectionId, orderId, ticker, side, type, price, filledPrice, size, filledSize, fee, feeCurrency, status, time
position_updateconnectionId, positionId, ticker, side, size, avgPrice, avgPriceFix, avgPriceDyn, status
balance_updateconnectionId, balances[]: coin, total, free, locked
finres_updateconnectionId, finreses[]: currency, result, fee, funds, available, blocked
trade_updateconnectionId, ticker, trades[]: price, size, side, time
orderbook_snapshotconnectionId, ticker, asks[], bids[], bestAsk, bestBid — each: price, size, type
orderbook_updateconnectionId, ticker, updates[]: price, size, type
errorerror (string message)

For complete endpoint documentation with request/response details, field descriptions, and integration examples, see the interactive panels above or download the Markdown file.