WebSocket Api

Contracts Can Be Switched In The Same Rout Within The Number Of Limit.Supported Contracts
AuthCode Information And Connection Diagnostic Logs:Query
Code Example:Download Example

Request Connection

Command
Url:ws://map.fxnapi.com:10004/connect/{token}
Command:connect
Command Args:
nametyperequiredremark
tokenstringyesYour AuthCode
Command Sample
ws.connect ws://map.fxnapi.com:10004/connect/(authcode)
Response:
Response Sample
{"Cmd":"connect","Code":0,"Msg":"connect xxx"}
Warning:One connection corresponds to one data channel. The number of connections established by the customer cannot exceed the maximum number of connections that can be connected by the key. Connections exceeding the number cannot be established, or you can configure new connections that exceed the number to replace existing connections。
Warning:Please Log When Connect Fail, Reconnect Should Do In 10 Second Interval,Server May Block The Clienter When Repeated Reconnection。
Warning:Disconnection is inevitable,Please Reconnect When Send HeartBeat No Response。

Subsription Contracts

Sub Contract,Up to 100 In Command
Command
Url:/sub/{symbols}
Command:sub
Command Args:
nametyperequiredremark
symbolsstringyesFull Symbol Code Such As EURUSD,Reference,
Multiple FullSymbol Split With ',',Up To 100
Support Group Sub,Such As CMEBTC* = CMEBTC,CMEBTC1909,CMEBTC2002...
Command Sample
ws.send /sub/EURJPY,SH600128
Response:
Response Sample
{"Cmd":"sub","Code":0,"Msg":"sub:xxx"}
Stream:When sub Success,You Will Receive Stream Data From Server
nametyperemark
Cmdstringdata type Cmd = rm
...anyThe Real Data Json Reference
Stream Sample
{"Cmd":"rm","M":"HBG","S":"BTC","C":"","Tick":1678846800,"P":24886.85,"B1":24886.85,"B1V":9,"S1":24886.86,"S1V":18,"O":24343.9,"H":26346.54,"L":24034.91,"YC":24343.9,"A":291445011.97,"V":11602.35,"B2":24886.84,"B2V":8,"S2":24887.69,"S2V":16,"B3":24884.36,"B3V":1,"S3":24889.31,"S3V":97,"B4":24884.35,"B4V":8,"S4":24889.32,"S4V":8,"B5":24883.12,"B5V":4,"S5":24889.5,"S5V":29,"HS":0.0616,"ZF":2.230,"LS":468619684142.20,"ZS":468619684142.20,"VF":9.496,"NV":0.06,"Z":18830012.00,"Z2":18830012.00}
Warning:When Sub Count Over Max Limit,The Previous Sub Will Be Replace。
Warning:Please Log When Fail, Repeat Sub Command In 5 Second Interval。

Subsription Markets

Sub Markets,Multiple Markets Split By ','
Command
Url:/submkt/{markets}
Command:submkt
Command Args:
nametyperequiredremark
marketsstringyesFull Market Code,Multiple Market Split With ','
Command Sample
ws.send /submkt/TAI,NYMEX
Response:
Response Sample
{"Cmd":"submkt","Code":0,"Msg":"submkt:xxx"}
Stream:When submkt Success,You Will Receive Stream Data From Server
nametyperemark
Cmdstringdata type Cmd = rm
...anyThe Real Data Json Reference
Stream Sample
{"Cmd":"rm","M":"HBG","S":"BTC","C":"","Tick":1678846800,"P":24886.85 ...}
Warning:Please Log When Fail, Repeat Sub Command In 5 Second Interval。

Subsription Routs

Sub Routs,Multiple Markets Split By ','
Command
Url:/subrout/{routs}
Command:subrout
Command Args:
nametyperequiredremark
routsstringyesFull Rout Code,Multiple Rout Split With ','
Command Sample
ws.send /subrout/GBCFD,TWST
Response:
Response Sample
{"Cmd":"subrout","Code":0,"Msg":"subrout:xxx"}
Stream:When subrout Success,You Will Receive Stream Data From Server
nametyperemark
Cmdstringdata type Cmd = rm
...anyThe Real Data Json Reference
Stream Sample
{"Cmd":"rm","M":"HBG","S":"BTC","C":"","Tick":1678846800,"P":24886.85 ...}
Warning:Please Log When Fail, Repeat Sub Command In 5 Second Interval。

UnSubsription

Cancel Sub,Multiple Symbol Split By ','
Command
Url:/unsub/{symbols}
Command:unsub
Command Args:
nametyperequiredremark
symbolsstringyesFull Symbol or Market,Split By ',' Such As BTC,EURJPY,CME Reference
Command Sample
ws.send /unsub/EURJPY,SH600128
Response:
Response Sample
{"Cmd":"unsub","Code":0,"Msg":"unsub:xxx"}

Subsription Fields

Option。Default Fields Is Not All The Model Fields
Command
Url:/fields/{fields}
Command:fields
Command Args:
nametyperequiredremark
fieldsstringyesSplit By ',' Such As Z,Z2,TS,H1,Reference Model
Command Sample
ws.send /fields/P,Z,Z2,TS,H1,JS
Response:
Response Sample
{"Cmd":"fields","Code":0,"Msg":"fields:xxx"}

Request KData

Receive KData One Time When Success,Max 25 kData,Request In 5 Second Interval。*Request Only In Contract Being Subscribed
More History Data By Using rest interface
Command
Url:/reqk/{symbol},{period},{num}
Command:reqk
Command Args:
nametyperequiredremark
symbolstringyesFull Symbol Code Reference
periodstringyesPeriod 1M,3M,5M,10M,15M,30M,1H,2H,4H,D
numstringyes1~25~90~180~365~730
Command Sample
ws.send /reqk/BTC,1M,10
Response:Receive KData One Time When Success
nametyperemark
CmdstringCmd = reqk-{symbol}-{period}
CodestringSuccess when Code >= 0
MsgstringTimeTick,Open,High,Low,Close,Vol;TimeTick,Open,High,Low,Close,Vol (Fields Split By ',', Data Split By ';')
Response Sample
{"Cmd":"reqk-BTC-1M","Code":0,"Msg":"1582424400,9664.9,9664.9,9664.8,9664.8,1.12;1582424340,9664.9,9665,9661.8,9664.9,26.93"}
Warning:Max 4 Tims In One Minute, Request Only In Contract Being Subscribed

Request Real Data

Return Data One Time,Max 5 Tims In One Minute。*Request Only In Contract Being Subscribed
Some Data Update In Low Frequency,Using This Function Acquisition InTime
Command
Url:/req/{symbosl}
Command:req
Command Args:
nametyperequiredremark
symbolsstringyesFull Symbol Code,Multiple Symbols Split By ',' Reference
Command Sample
ws.send /req/BTC,EURJPY
Response:Receive Real Data One Time When Success
nametyperemark
Cmdstringdata type Cmd = rm
...anyThe Real Data Json Reference
Response Sample
{"Cmd":"rm","M":"HBG","S":"BTC","C":"","Tick":1678846800,"P":24886.85 ...}
Warning:Request Only In Contract Being Subscribed

Keep Connection Alive By Send HeartBeat

Important!The Server Will Close Connection When Not Receive Heartbeat Command From Clienter Over 60 Seconds
Heartbeat Can Be Sent In Two Ways:
Way 1.Send HeartBeat to Server in 15-60 Seconds Interval
Way 2.Send HeartBeat To Server When Receive '{"Cmd":"heartbeat","Msg":"ping"}' From Server
Command
Url:/ping/ok
Command:ping
Command Args:
nametyperequiredremark
Command Sample
ws.send /ping/ok
Response:
Response Sample
{"Cmd":"ping","Code":0,"Msg":"ok"}
Warning:When There No HeartBeat Response Over 2 Times,Then The Connection Should Break

ReSub/ReConnect

1Important!ReConnect:Disconnection Is Inevitable,Send HeartBeat Every 15 Seconds,When There No HeartBeat Response Over 2 Times,Then ReConnect,Reference Command "connect"
2Important!ReSub:If Not Sure Whether The Contract Is subscriped,You Can Send Sub Command Again,Reference Command "sub" or "submkt"
3、Don't Repeat Reconnect,System Will Block Clienter When Over 10 Times Reconnect In 1 Minute.
4、When Connect Count Over Max Limit,The Previous Connection Will Be Closed
5、Repeat Command In 5 Second Interval

Dealing ReceiveData

Important!Dealing Data:Put The Data In Queue Or Processed Asynchronously When Receive。

Command Output And ErrorCode

Model
json: {"Cmd":"CmdCode","Code":0,"Msg":""}
nametyperemark
CmdstringCommand
CodestringSuccess when Code >= 0
MsgstringMessage
Description
Code >= 0,Success
Code <0 Fail,ErrorMessage In Msg
Cmd,CmdCode

Stream Output and Debugging Code

DebuggingCode
AuthCode + "DEV"3 char = DebuggingCode。(DebuggingCode Only Allow 1 Connection,Sub Only BTC,Frequency Only 2 Second)
Stream Output
nametyperemark
Cmdstringdata type such as rm
...stringany fields