Clone combo bot

Hi Maksym

I have been trying to clone a combo bot through my python code but havent had much luck
i fetch my 1 combo bot which i created in UI and use its settings dictionary to make a copy for the pair i pass

the error i get is
HTTPError: 401 Client Error: Unauthorized for url: https://api.gainium.io/api/cloneComboBot?botId=68ea0305f3011652961f3fe6

botId = 68ea0305f3011652961f3fe6

I have write access on my api and secret and i am able to fetch my combo bot with it

Attached is my python script

test.txt (4.7 KB)

Body should be a part of signature. You signed first then added body

I did it similar to fetch combo bots so I thought it would work.

Also the clone combo bot in the swagger UI payload doesn’t have a “pair” key so probably needs updating documentation

Could you also mention the mandatory keys needed in the payload for all the api endpoints on swagger UI

If body is empty, its not used in signature, in all other cases must be used.
Mandatory parameters are marked as required.
Pair will be added to schema.

So if I do

url = ``https://api.gainium.io/api/cloneComboBot?botId=68ea0305f3011652961f3fe6

payload = {"pair": [new_pair] }

And

headers = sign_request(api_secret, method, endpoint, timestamp, body=payload)
response = requests.put(f"{url}?botId={bot_id}", headers=headers, json=payload)

Would that be enough for the clone?

As there is no python sdk in github this is new to me

I believe yes, but not an expert in python.

didnt work in python or through the swagger UI as you see
I tried pairs as LINK_USDT and also LINKUSDT
its on a futures accoun

There was a wrong url.
Fixed and added pair to body description.
Symbol must be in format base_quote

1 Like

Am i doing something wrong?

You got 200 response with new bot id.

it worked
Thanks alot

1 Like

For anyone needing python code to clone a combo bot here it is

import base64
import json
import time
import requests
from hashlib import sha256
from hmac import HMAC

# === Credentials ===
api_token = '64ecaaexxx' # Replace with generated token
api_secret = 'e12cb620-cfb4xxx' # Replace with generated secret

# === Clone parameters ===
bot_id = '68ea0xxx' # Replace with botID
pair = 'ADA_USDT' # New pair
strategy = 'short' # Direction
name = f"{strategy}_{pair.split('_')[0]}USDT"

# === Timestamp ===
timestamp = str(int(time.time() * 1000))

# === Payload ===
payload = {
    "name": name,
    "pair": [pair]
}
body_str = json.dumps(payload, separators=(',', ':'), sort_keys=True)

# === Endpoint ===
endpoint = f"/api/cloneComboBot?botId={bot_id}&paperContext=false"
url = f"https://api.gainium.io{endpoint}"

# === Signature ===
prehash_string = f"{body_str}PUT{endpoint}{timestamp}"
signature = HMAC(api_secret.encode('utf-8'), prehash_string.encode('utf-8'), sha256).digest()
signature_encoded = base64.b64encode(signature).decode('utf-8')

# === Shared headers ===
headers = {
    "accept": "application/json",
    "Content-Type": "application/json",
    "token": api_token,
    "time": timestamp,
    "signature": signature_encoded
}

# === Send with requests ===
print("\n=== Requests ===")
response = requests.put(url, headers=headers, json=payload)
print("Status:", response.status_code)
print("Response:", response.text)

Thanks Maksym

3 Likes

Amazing! Thanks for sharing

1 Like

This is really useful, thank you :+1:

1 Like