Web Socket Streams for NiceHash

General WSS information


Signing WSS

Generating an API key

Visit the website: NiceHash -> API Keys

Signing connection

A signed connection needs to contain the following query string parameters:

You can use https://api2.nicehash.com/api/v2/time endpoint to get current server time in order to account for any difference with your local system clock.

Example

Subscribe to channel

Method: wss
API Key: 787ba136-c1bc-4684-a215-69f8d86a1300 (received when API Key is generated at API Keys)
API Secret: 21dd1480-29b2-43f1-a782-0407d588977d757b0f62-221a-4172-a154-174b5a4ece4d (received when API Key is generated at API Keys)
X-Time: 1560162680789 (current UTC time in ms)
X-Nonce: 8279fb4e-d9da-43b4-899e-b10a7ce81a80 (generate some random string, for example: UUID.randomUUID().toString(), must be different each time you sign a request)
X-Organization-Id: cd005e9a-dbc5-430c-a10c-3359c5fa5184
Path: my

Input for signing:
787ba136-c1bc-4684-a215-69f8d86a1300 1560162680789 8279fb4e-d9da-43b4-899e-b10a7ce81a80 cd005e9a-dbc5-430c-a10c-3359c5fa5184 wss my

Signature is generated via HMAC-SHA256 (input, API_SECRET): e8e360f598c15115c2dc324966fcb24244135d7d9cba0dfb2fde041083f6ea1c

Create X-Auth: API_KEY:SIGNATURE -> 787ba136-c1bc-4684-a215-69f8d86a1300:e8e360f598c15115c2dc324966fcb24244135d7d9cba0dfb2fde041083f6ea1c

Do NOT include a plain text API Secret in any of the parameters of your request. A novice software developer might mistakenly put an API Secret into the second part of X-Auth header value.

Pass query string parameters:

wss://exchange-tzectbtc-ws.nicehash.com/?a=787ba136-c1bc-4684-a215-69f8d86a1300:e8e360f598c15115c2dc324966fcb24244135d7d9cba0dfb2fde041083f6ea1c&t=1560162680789&n=8279fb4e-d9da-43b4-899e-b10a7ce81a80&o=cd005e9a-dbc5-430c-a10c-3359c5fa5184


Detailed Stream information

OrderBook Stream

Push orderbook information.

OrderBook object

{
  "b": [                // Buy orders
    [
      "0.0024",         // Price
      "10"              // Quantity
    ]
  ],
  "s": [                // Sell orders
    [
      "0.0024",         // Price
      "10"              // Quantity
    ]
  ]
}

Subscribe to orderbook channel

{"m":"subscribe.orderbook"}

Response to subscribe
m: message type, b: list of buy orders, s: list of sell orders

{"m":"ob.s","b": [[ 0.5, 0.001]],"s": [[1.0, 0.009 ]]}

Update message
m: message type, b: list of buy orders, s: list of sell orders

{"m":"ob.u","b": [[ 0.5, 0.002]],"s": [[1.0, 0]]}

Unsubscribe to orderbook channel

{"m":"unsubscribe.orderbook"}

Trade Stream

Push trade information; each trade has a unique buyer and seller.

Trade object

{
  "d": "BUY",                   // Trade direction
  "p": 2,                       // Price
  "q": "1.999998",              // Quantity
  "sq": 3.999996,      	        // Secondary quantity
  "ts": "1556175673039870",     // Timestamp
}

Subscribe to trades channel

{"m":"subscribe.trades"}

Response to subscribe
m: message type, t: list of 200 most recent trades

{"m":"t.s","t":[]}

Update message
m: message type, t: list of trade objects

{"m":"t.u","t":[]}

Unsubscribe to trades channel

{"m":"unsubscribe.trades"}

MyTrade Stream

Push my trade information; each trade has a unique buyer and seller. MyTrade stream requires to be signed.


MyTrade object

{
  "i": "fb651ea3-08c0-2704-dcfc-5971e401f989", // Trade id
  "d": "SELL",                  // Trade direction
  "p": 2,                       // Price
  "q": "1.999998",              // Quantity
  "sq": 3.999996,      	        // Secondary quantity
  "ts": "1556175673039870",     // Timestamp
  "f": 0.000002,      	        // Fee ammount
  "m": 0,      	                // Is maker
}

Subscribe to mytrades channel

{"m":"subscribe.mytrades"}

Update message
m: message type, t: list of my trade objects

{"m":"mt.u","t":[]}

Unsubscribe to mytrades channel

{"m":"unsubscribe.mytrades"}

Order Stream

Push my order information; Order stream requires to be signed.


Order object

{
  "i": "b8b7fae1-1a52-442e-9635-bfb67061e3c4", // Order id
  "p": 0.02,                   // Price
  "oq": 5,                     // Original quantity
  "osq": 0.01,                 // Original secondary quantity
  "eq": 0,                     // Executed quantity
  "esq": 0,                    // Executed secondary quantity
  "t": "LIMIT",      	       // Order type
  "d": "BUY",      	       // Order side
  "sts": 1560160982108488,     // Order submission timestamp
  "uts": 1560160982138085,     // Response time of order's last response
  "s": "ENTERED"               // Order state
}

Subscribe to orders channel

{"m":"subscribe.orders"}

Update message
m: message type, o: list of order objects

{"m":"o.u","o":[]}

Unsubscribe to orders channel

{"m":"unsubscribe.orders"}

Candlestick Stream

Push candlestick information. Supported resolutions: 1 (minute), 60 (hour), 1440 (day).

Candlestick object

{
  "t": 1560165600,         // Interval start time
  "o": 0.001,              // Open price
  "c": 0.01,               // Close price
  "l": "0.001",            // Lowest price
  "h": 0.1,      	   // Highest price
  "v": 2,                  // Volume
}

Subscribe to candlesticks channel

{"m":"subscribe.candlesticks", "r": resolution}

Update message
m: message type, r: resolution, c: list of raw candlesticks objects.

{"m":"c.u","r":1,"c":[]}

Unsubscribe to candlesticks channel

{"m":"unsubscribe.candlesticks"}

Trade Statistics Stream

Push price change and trade volume information for the last 24 hours.

Subscribe to trade statistics channel

{"m":"subscribe.statistics"}

Update message
m: message type, pd: price change in percentage (24h), v: trade volume (24h).

{"m":"s.u","pd":-1.247990,"v":0.34102674}

Unsubscribe to statistics channel

{"m":"unsubscribe.statistics"}