Skip to content

Legacy TCP protocol

Besides REST, MetaPortAPI speaks a simple line-based protocol for clients that prefer raw sockets (or tools like PuTTY/telnet).

Port Purpose
TCP 77 Commands — send one JSON object per line, receive one JSON line back
TCP 78 Data — streamed messages, one JSON object per line
  • Send each command on one line, ending with a newline (\r\n or \n).
  • Every reply is one line and includes ERROR_ID and ERROR_DESCRIPTION.
  • The command connection stays open; send as many commands as you like.
  • {"MSG":"EXIT"} replies Bye and closes the connection.
$ telnet 127.0.0.1 77
{"MSG":"QUOTE","SYMBOL":"EURUSD"}
{"MSG":"QUOTE","SYMBOL":"EURUSD","ASK":1.11214,"BID":1.11208,"FLAGS":6,"TIME":"2026.10.28 08:04:55.523","VOLUME":0,"ERROR_ID":0,"ERROR_DESCRIPTION":"The operation completed successfully"}
{"MSG":"HELP"}
{"MSG":"HELP","COMMAND":"ORDER_SEND"}

The second form lists the mandatory and optional tags of a command. All commands are listed in the command reference.

Subscribe on port 77 (for example {"MSG":"TRACK_PRICES","SYMBOLS":["EURUSD"]}), then connect any number of clients to port 78 to receive the data.

import json, socket
s = socket.create_connection(("127.0.0.1", 77), timeout=5)
f = s.makefile("r", encoding="utf-8")
def cmd(obj):
s.sendall((json.dumps(obj) + "\r\n").encode())
return json.loads(f.readline())
print(cmd({"MSG": "QUOTE", "SYMBOL": "EURUSD"}))
print(cmd({"MSG": "ORDER_SEND", "SYMBOL": "EURUSD", "VOLUME": 0.01, "TYPE": "ORDER_TYPE_BUY"}))