Deribit websocket API connection example, use the JavaScript language, policy runs in FMZ inventor quantification platform.
Source Address: https://www.fmz.com/strategy/147765
Client null = var var deribitAcc = {} // save global objects may be provided a token function WS_GetAccount () {// Get a currency account asset information var MSG = { "jsonrpc": "2.0", "ID": 2515, "Method": "Private / get_account_summary", "the params": { "Currency": "the ETH", "Extended": to true } } client.write (the JSON.stringify (MSG)) var RET = client.read ( ) the Log (RET, "# FF0000") } Function WS_GetToken () {// authentication, and acquires the token var MSG = { "jsonrpc": "2.0", "ID": 9929, "method": "public/auth", "params": { "grant_type": "client_credentials", "client_id": "XXXXXXX", // 申请 API KEY 时获取 "client_secret": "XXXXXXXXXXXXXXXXXXXXXXXXXX" // 申请 API KEY 时获取 } } while (1) { client.write(JSON.stringify(msg)) var ret = client.read() try { var jsonObj = JSON.parse(ret) if (jsonObj) { deribitAcc.accessToken = jsonObj.result.access_token deribitAcc.refToken = jsonObj.result.refresh_token break } The catch} (E) { function main() { Log ( "error:", E) } } log ( "Update accessToken deribitAcc, refToken:", deribitAcc) } function WS_Depth () {// get_order_book common channel access, a thin depth data acquisition order var MSG = { "jsonrpc": "2.0", "ID": 8772, "Method": "public / get_order_book", "the params": { "INSTRUMENT_NAME": "BTC-pERPETUAL", // specified, obtaining depth data BTC sustainable contracts "depth" :. 5 } } client.write (the JSON.stringify (MSG)) var RET = client.read () the Log ( "depth:",ret) } client = Dial("wss://www.deribit.com/ws/api/v2") WS_GetToken() WS_GetAccount() WS_Depth() } function onexit() { Log("关闭 ws 连接") client.close() }