I have taken the example code from https://docs.woo.org/?shell#authentication and have adapted the code to get the V3 normalised request to use in the signature generation. For endpoints that don’t require any parameters, this works fine, but if parameters are required, I get this error:
"{‘success’: False, ‘code’: -1001, ‘message’: ‘The API signature is invalid.’}"
I have checked my API key and secret and the settings on my account, and everything should be fine.
import datetime
import hmac, hashlib, base64
import requests
import json
staging_api_secret_key = 'MY API SECRET'
staging_api_key = 'MY API KEY'
def _generate_signature(data):
key = staging_api_secret_key#'key' # Defined as a simple string.
key_bytes= bytes(key , 'utf-8') # Commonly 'latin-1' or 'utf-8'
data_bytes = bytes(data, 'utf-8') # Assumes `data` is also a string.
return hmac.new(key_bytes, data_bytes , hashlib.sha256).hexdigest()
milliseconds_since_epoch = round(datetime.datetime.now().timestamp() * 1000)
headers = {
'x-api-timestamp': str(milliseconds_since_epoch),
'x-api-key': staging_api_key,
'x-api-signature': _generate_signature(str(milliseconds_since_epoch)+'POST/v3/algo/order{ "symbol": "SPOT_BTC_USDT", "side": "BUY", "reduceOnly": false, "type": "MARKET", "quantity": "0.0001", "algoType": "TRAILING_STOP", "callbackRate": "0.012"}'),
'Content-Type': 'application/json',
'Cache-Control':'no-cache'
}
data = {"symbol": "SPOT_BTC_USDT", "side": "BUY", "reduceOnly": False, "type": "MARKET", "quantity": "0.0001", "algoType": "TRAILING_STOP", "callbackRate": "0.012"}
response = requests.post('https://api.woo.org/v3/algo/order', headers=headers, data=data)
print(response.json())
2
Answers
Customer support came with the following code that seems to work:
It’s hard for me to tell exactly if this will work since I don’t have the actual API credentials, but you should try something like this:
The difference is that I am created the signature with the exact data in the dictionary, using
json.dumps(data)
. Let me know if this works for you, and if not, what error messages you see.