'How to get a proper signature to authenticate to private websocket in Wootrade

I am trying to authenticate to private websocket on wootrade

I am keep getting this error :

{
  'errorMsg': 'signature error',
  'event': 'auth',    
  'id': '123r',       
  'success': False,   
  'ts': 1644835797096
}

How should a message that I am hashing looks like and what should I correct in the code?

API = "xxx"
SECRET = "yyy"
APPLICATION_ID = "zzz"

timestamp_unix = int(time.time()*1000)

def on_message_woo(ws_woo, message):
    json_message = json.loads(message)
    pprint.pprint(json_message)

def on_error_woo(ws_woo, error):
    print(error)

socket_woo=f'wss://wss.woo.network/v2/ws/private/stream/{APPLICATION_ID}'
ws_woo = websocket.WebSocketApp(socket_woo, on_message=on_message_woo, on_error=on_error_woo)

msg=f'|{timestamp_unix}' # I tried many combination here

signature1=hmac.new(SECRET.encode('utf8'), msg.encode('utf8'), hashlib.sha256).digest()
signature=base64.b64encode(signature1).decode('utf8')


def subskrypcje():
    time.sleep(5)
    ws_woo.send(json.dumps(
    {
    "id":"123r",
    "event":"auth",
    "params":{
        "apikey":API,
        "sign":signature,
        "timestamp":timestamp_unix
        }  
    }
                    ))
def ws_woo_start():
    ws_woo.run_forever()

t1=threading.Thread(target=ws_woo_start)
t2=threading.Thread(target=subskrypcje)


t1.start()
t2.start()

Below link to documentation https://docs.woo.org/#auth



Solution 1:[1]

After consulting with a friend we found a working solution

Subscription fuction should looks as fallow:

def subskrypcje():
    time.sleep(5)
    timestamp_unix = str(int(time.time()*1000))
    msg=f'|{timestamp_unix}'
    bytes_key = bytes(str(SECRET), "utf-8")
    bytes_msg = bytes(msg, "utf-8")
    signature = (
        hmac.new(bytes_key, msg=bytes_msg, digestmod=hashlib.sha256)
        .hexdigest()
        .upper()
    )
   
    ws_woo_private.send(json.dumps(
    {
    "id":"123r",
    "event":"auth",
    "params":{
        "apikey":API,
        "sign":signature,
        "timestamp":timestamp_unix
        }
        }
         ))

The rest stays the same with this difference that hasing process is now in subscription(authantication) function

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Iwan