I am following the example here: WebSocket Overview | Coinbase Cloud
However, I am using C++. Here is my code:
websocket_client websocket;
websocket.connect("advanced-trade-ws.coinbase.com", "443");
epoch_time = chrono::duration_cast<chrono::seconds>(chrono::system_clock::now().time_since_epoch()).count();
string concat = fmt::format("{}level2ETH-USD,ETH-EUR", epoch_time);
signature = hmac_sha256(api_secret, concat);
string subscribe_message = fmt::format(R"({{
"type": "subscribe",
"product_ids": [
"ETH-USD",
"ETH-EUR"
],
"channel": "level2",
"api_key": "{}",
"timestamp": {},
"signature": "{}"
}})", api_key, epoch_time, signature);
cout << "Writing to websocket:\n" << subscribe_message << endl;
websocket.write(subscribe_message);
The output from this is as follows:
Writing to websocket:
{
"type": "subscribe",
"product_ids": [
"ETH-USD",
"ETH-EUR"
],
"channel": "level2",
"api_key": "redacted",
"timestamp": 1676174456,
"signature": "redacted"
}
The response is
{"type":"error","message":"authentication failure"}
I have already successfully authenticated against the REST API using the same key, and my key has all permissions enabled.
The example in the documentation uses the following code
CryptoJS.HmacSHA256(str, secret).toString()
I double checked to make sure that my hmac_sha256 method produces the same output given the same secret and string. Also, as I have mentioned, I can successfully authenticate against the REST API when using this method and my same key and secret.