Authentication
There are two methods of authenticating on a Websocket connection.
Authenticate Per-Connection
Authenticate Per-Message
Authenticate One-Off Signature
Authenticate Per-Connection
In order to send authenticated requests over the websocket connection, you will have to send an auth message.
{
"op": "auth",
"data": {
"key": `[Insert API key]`,
"secret": `[Insert API secret]`
}
}// Code Example
import os
import json
import asyncio
import websockets
async def main():
connection = await websockets.connect("wss://ws-testnet.aevo.xyz")
auth_msg = json.dumps({
"op": "auth",
"data": {
"key": os.environ["API_KEY"],
"secret": os.environ["API_SECRET"],
}
})
await connection.send(auth_msg)
await connection.recv() # receive the outcome of authentication here
msg = json.dumps({"op": "status"})
await connection.send(msg)
print(await connection.recv())
asyncio.run(main())Authenticate Per-Message
👍 Keep your API secret safe!
Using signature is a safer method of authenticating since your API secret is not passed along in the requests. This prevents potential API secret leakage during transport.
To authenticate with this method, the following fields should be sent with the request:
signatureis generated by performingHMAC_SHA256(apiSecret, message).messageis a concatenation ofapiKey,timestamp,ws,op,datawith comma separation.timestampis UNIX timestamp in nanoseconds.wsis a string constant with the value "ws". Must be lowercase.apiKey,timestamp,ws,op,dataare all required. If the request does not have anydata, use a blank space for the value ofdata.
Example:
apiKey:API_KEYtimestamp: 1673425955575713842op: "status"ws: "ws"data: ""
📘 Note!
There is a trailing comma in the message, since the
dataof "status"oprequest is empty.
Authenticate One-Off Message
In order to send authenticated requests over the websocket connection, you will have to send an auth message.
signatureis generated by performingHMAC_SHA256(apiSecret, message).messageis a concatenation ofapiKey,timestamp,ws,op,datawith comma separation.timestampis UNIX timestamp in nanoseconds.wsis a string constant with the value "ws". Must be lowercase.apiKey,timestamp,ws,op,dataare all required. If the request does not have anydata, use a blank space for the value ofdata.
Example:
apiKey:API_KEYtimestamp: 1673425955575713842op: "auth"ws: "ws"data: ""
Authenticating as a Subaccount
Your main account's API key can bind a connection to one of its subaccounts. Add subaccount to the auth data (or to the per-message auth object), and with signed authentication append it to the signed message as a sixth field: apiKey,timestamp,ws,op,data,subaccount.
See Subaccounts for the exact formats.
Last updated
Was this helpful?

