API
Last updated
Was this helpful?
Last updated
Was this helpful?
The API is currently in beta, which means that breaking changes may be introduced
The WebSocket API provides real-time updates about various accounts (e.g., UpdateAccountInformationDTO
, UpdateHistoryDTO
, UpdateOpenPositionsDTO
). Clients can subscribe to one or more accounts and automatically receive new data whenever it’s published.
Communication uses STOMP (Simple Text Oriented Messaging Protocol) over a standard WebSocket. You can use any STOMP client library that supports WebSockets (e.g., @stomp/stompjs in Node.js or JavaScript).
Do not forget to add the 'Socket' feature to the account from which you want to receive real-time data. If the feature is not added, no updates will be sent for this account.
Endpoint: wss://api.metacopier.io/ws/api/v1
Authentication:
Each client must provide an api-key
in the STOMP CONNECT headers.
Example STOMP connect header:
If the api-key
is missing or invalid, the connection will be rejected.
After a successful STOMP CONNECT
:
SUBSCRIBE to a private queue destination such as:
or any other user-specific route your server is configured to send messages to.
This tells the server: “Send updates for my session to me at this address.”
SEND a JSON body to "/app/subscribe"
that indicates which accounts you want:
If you send an empty list, it means “subscribe me to all accounts that my api-key
can access.”
If you send a non-empty list (["uuid1", "uuid2"]
), you only receive updates for those specific accounts.
Example Subscription Request
(Empty array => all accounts)
STOMP Frame
Receiving Updates:
You will receive messages on your private user queue (e.g. "/user/queue/accounts/changes"
).
The server sends a copy of each relevant update (based on your subscription) to only your session.
Message Types:
UpdateAccountInformationDTO
UpdateHistoryDTO (contains a list of PositionDTO
)
UpdateOpenPositionsDTO (contains a list of PositionDTO
)
(See Data Format for details.)
The server wraps each outgoing message in a MessageWrapper
object with two fields:
type
– This is the simple name of the DTO class. For example:
"UpdateAccountInformationDTO"
"UpdateOpenPositionsDTO"
"UpdateHistoryDTO"
data
– The actual DTO (serialized as JSON).
UpdateAccountInformationDTO
UpdateHistoryDTO (history positions only for the last 24h)
UpdateOpenPositionsDTO
Since "type"
is now the class simple name, you can simply check:
"UpdateAccountInformationDTO"
=> The "data"
field is an UpdateAccountInformationDTO
"UpdateHistoryDTO"
=> The "data"
field is an UpdateHistoryDTO
"UpdateOpenPositionsDTO"
=> The "data"
field is an UpdateOpenPositionsDTO
For example (in JavaScript/Node):
This ensures you always know which DTO you’re handling without guessing based on field names.
Here is a simplified Node.js example using @stomp/stompjs and ws:
brokerURL: Points to the WebSocket/STOMP endpoint.
connectHeaders: Replace 'REPLACE_WITH_YOUR_API_KEY'
with your own API key.
subscribe: We subscribe to "/user/queue/accounts/changes"
, which is a private user queue (messages are sent only to your session).
publish: We send a JSON body to "/app/subscribe"
specifying which account IDs we want ([]
means all).
message handling: We parse the JSON body. Because the server sends a MessageWrapper
with a type
field, we switch on data.type
to see whether it’s an UpdateAccountInformationDTO
, UpdateHistoryDTO
, or UpdateOpenPositionsDTO
.
That’s all you need to connect, authenticate, subscribe, and receive real-time data!
Invalid API Key: If your api-key
is wrong or expired, the server will send a STOMP ERROR frame or close the socket. Check logs for the cause.
Connection Loss: If the server or network goes down, your client might attempt to reconnect (reconnectDelay=5000
means it tries every 5 seconds).
Disconnect: The client can call client.deactivate()
(in @stomp/stompjs) or close the WebSocket to end the session.
Server may forcibly close the connection if you exceed concurrency limits or do not have permission for certain accounts.
Global or Per-API-Key Limits: We may enforce a maximum number of concurrent WebSocket sessions per API key (or a global total). If you try to exceed these limits, the server will reject additional connections.
Disconnect on Excess: If your API key opens more than the allowed sessions, the newest or oldest connection might be forcibly disconnected, or the server might send an ERROR frame.
IP-Based Limits: We may also optionally limit the number of connections from a single IP address to prevent abuse.
What This Means for You: If you encounter frequent disconnects or ERROR
frames mentioning concurrency, verify how many clients are simultaneously connecting with your API key/IP.
Contact Support: If you need higher concurrency or have special requirements, reach out to the support team.
This WebSocket STOMP API allows real-time account updates. Once connected (with a valid api-key
), you send a subscription message specifying which account(s) you want, and you receive JSON-encoded DTOs for relevant updates.
If you have any further questions or need more details, please contact our support team. Enjoy building real-time solutions with the WebSocket API!