iconomi-ag / iconomi-api

ICONOMI platform open api
4 stars 3 forks source link

Struggling with Python API Auth, receiving 401 #20

Closed Nexus2k closed 2 years ago

Nexus2k commented 3 years ago

I've copied the signature generation from your python tests:

def generate_signature(payload, request_type, request_path, timestamp):
    data = ''.join([timestamp, request_type.upper(), request_path, payload]).encode()
    print(data)
    signed_data = hmac.new(ICNMI_API_SECRET.encode(), data, hashlib.sha512)
    return base64.b64encode(signed_data.digest())

And my post request:

print("Updating Strategy")
            try:
                timestamp = str(int(time.time() * 1000.0))
                headers = {
                    'ICN-API-KEY': ICNMI_API_KEY,
                    'ICN-SIGN': generate_signature(
                        json.dumps(request_json).replace(" ",""),
                        "POST",
                        "/v1/strategies/" + STRAT_NAME + "/structure",
                        timestamp
                    ),
                    'ICN-TIMESTAMP': timestamp,
                }
                print(headers)
                response = requests.post(
                    "https://api.iconomi.com/v1/strategies/" + STRAT_NAME + "/structure",
                    json=json.dumps(request_json).replace(" ",""),
                    headers=headers
                )
                response.raise_for_status()
                # access JSOn content
                jsonResponse = response.json()
                print("Entire JSON response")
                print(jsonResponse)
            except HTTPError as http_err:
                print(f'HTTP error occurred: {http_err}')
            except Exception as err:
                print(f'Other error occurred: {err}')

The data I'm signing looks like this:

b'1632302948727POST/v1/strategies/123123123/structure{"ticker":"123123123","values":[{"assetTicker":"BTC","rebalancedWeight":0.5629},{"assetTicker":"EGLD","reba
lancedWeight":0.2222},{"assetTicker":"AVAX","rebalancedWeight":0.2148}],"speedType":"FAST"}'

Any idea what's wrong?

Testing the same with Postman also doesn't work. I've already tried with a new API key w/o success.

robertnjenjic commented 3 years ago

Your rebalancedWeight sum is 9.999 (0.5629+0.2148+0.2222) ... It should be 1.0.

iconomi-support commented 2 years ago

Are you still experiencing this issue?