Error: API Error: 401 - Unauthorized

Hi, I am new to using Gainium API. I created a READ key/secret pair. In the swagger documentation page I see a Authorize button where I input my key and secret and (as far as I can understand) I authorized my key. I am getting a “API Error: 401 - Unauthorized” response. Can you help me resolving this issue?
Thanks

Moving this to bug reports since we are tracking all issues here l, I will update you soon.

Thank you. FYI, the endpoint I am trying to call is /api/bots/combo.

Did you correctly register the developer API key at Gainium? Can you access other protected endpoints?

d_yo_r, referring my original post Ares moved here: “I created a READ key/secret pair. In the swagger documentation page I see a Authorize button where I input my key and secret and (as far as I can understand) I authorized my key.”



As of this morning (local time) the error is 403, according to swagger doc, it is User not found.
I both have a paid Basic sub and an affiliate link sub from Bybit. Please let me know if I need to increase my plan.

No your plan should have access. Bear with the bugs because the API is the least tested component. We don’t have a lot of devs building on top but maybe that will change as we grow.

Did you add the key in your Gainium account in Settings > API key?

Please check previous messages and screenshots.

That’s why I was asking. It isn’t enough to have an API key and use it on Gainium’s Swagger page. You have to register it at first.

An exchange key is generated on the exchange and “registered” in Gainium. The Developer key is generated in Gainium and is showing on Settings page in Gainium. Please let me know if there is another registration setup. There is no mention of such a registration step on Gainium API for developers.

Enable 2FA

2FA must be enabled before you can create API keys. If you haven’t already, enable 2FA on your account before proceeding.

Create API keys

To generate a new API key:

    1. Click “New API access token.”
    1. Give the key a descriptive name so you can remember its purpose later
    1. Choose the permissions this key should have in your Gainium account. With Read permission, you can view the details of your bots and deals but not make any changes. If you need to be able to create/edit bot and values, you’ll need Write access.
    1. Click “Create”
    1. Copy and paste the newly created API Key and Secret into your favorite coding IDE or third-party app

API Documentation …

image

Add an a API key to Gainium.

image

Key and secret are only shown once. Store it at a secure place.

By default the API key is read-only. If you require write access, you have to edit the permissions afterwards.

image

Make sure that your API key isn’t expired.

image

Else you can renew it by clicking on actions.

image

Cannot reproduce, using your keys we got 200 response

1 Like

Thanks for the feedback that the key is working. I will rework the code that is calling the end-point.

By the way, that scares me a little. Yes, Gainium surely trades on the users’ behalf. But isn’t the developer API key a RSA key, where Gainium should only have access to the public key?

From the documentation:

To sign a request:

Use API-Secret to encrypt the prehash string {body+method+endpoint+timestamp} with sha256 HMAC. The request body is a JSON string and need to be the same with the parameters passed by the API.

After that, use base64-encode to encrypt the result in step 1 again

Example: crypto.createHmac(‘sha256’, secret).update(body + method + endpoint + time).digest(‘base64’)

Is timestamp here in UNIX timestamp format? If not, what is the format?

In ms, not seconds

Yes. I tried that without waiting for your answer Maksym. I got a 200,ok. Thank you very much. Now you have a builder/user/tester for your API endpoints. Please let me know if I can contribute in any way…
PS. Maybe it’s better to include that piece of info in the doc.

1 Like


The very first iteration (proof of concept) of my personal/private bot dashboard. Thank you Maksym, Ares both for your support.

1 Like

very nice. Why don’t you create a new seperate topic and update your progress/iterations for us to follow :wink:

Awesome! Yes I agree this should be on its own topic, we can follow the progress and contribute/rest the app.