Skip to main content

Authentication

Authentication is required to access protected endpoints in the Gunbot API. This section covers the /api/v1/auth/login endpoint for obtaining a JSON Web Token (JWT) and the /api/v1/auth/status endpoint to validate authentication.

Gunbot uses password encryption to ensure secure communication during authentication. Sample code snippets for encrypting passwords in different programming environments are provided.

/api/v1/auth/login​

  • Method: POST
  • Description: Authenticate a user and obtain a JSON Web Token (JWT) to access secured API endpoints.

Parameters​

NameTypeRequiredDescription
passwordstringYesThe user's encrypted password. See encryption helpers below.

Examples​

cURL​

curl -X POST https://your-gunbot-instance.com:3000/api/v1/auth/login \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_BEARER_TOKEN" \
-d '{"password": "your_encrypted_password"}'

JavaScript (fetch API)​

fetch('https://your-gunbot-instance.com:3000/api/v1/auth/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_BEARER_TOKEN'
},
body: JSON.stringify({ password: 'your_encrypted_password' }),
})
.then(response => response.json())
.then(data => console.log(data.token));

Python (requests library)​

import requests

url = 'https://your-gunbot-instance.com:3000/api/v1/auth/login'
data = {'password': 'your_encrypted_password'}
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_BEARER_TOKEN'
}
response = requests.post(url, json=data, headers=headers)
print(response.json()['token'])

Response​

Success (200)​

{
"status": "success",
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE4MTEwNjM4NTIsImlhdCI6MTczMzMXAwSnRyVi5JWmEwd0Vrc3lULnVCOVYxWXRObjAwRVB6NXlwTWo4UjRPblJoOFl1WGhxIn0.h1QiXh3EGl_LCqh0cgBTBle2ALgjSNhZPN9uwpvug6c"
}

/api/v1/auth/status​

  • Method: GET
  • Description: Validate the authentication status of the current session by checking the provided token.

Parameters​

NameTypeRequiredDescription
AuthorizationstringYesBearer token. Include in the Authorization header as Bearer <token>.

Examples​

cURL​

curl -X GET https://your-gunbot-instance.com:3000/api/v1/auth/status \
-H "Authorization: Bearer your_token"

JavaScript (fetch API)​

fetch('https://your-gunbot-instance.com:3000/api/v1/auth/status', {
headers: { 'Authorization': 'Bearer your_token' }
})
.then(response => response.json())
.then(data => console.log(data.status));

Python (requests library)​

import requests

url = 'https://your-gunbot-instance.com:3000/api/v1/auth/status'
headers = {'Authorization': 'Bearer your_token'}
response = requests.get(url, headers=headers)
print(response.json()['status'])

Response​

Success (200)​

{
"code": 200,
"isDemo": false,
"isRegistered": true,
"isTwoFA": false,
"metamask": false,
"status": "success",
"message": "Authenticated"
}

Encryption helpers​

Below you'll find several snippets to help you encrypt your Gunbot password for auth requests.

JavaScript - Browser​

async function encryptPassword(password, key) {
const encoder = new TextEncoder();
const data = encoder.encode(password);
const encodedKey = encoder.encode(key).slice(0, 16);
const iv = encodedKey;

const cryptoKey = await window.crypto.subtle.importKey(
'raw',
encodedKey,
{ name: 'AES-CBC' },
false,
['encrypt']
);

const encryptedBuffer = await window.crypto.subtle.encrypt(
{ name: 'AES-CBC', iv },
cryptoKey,
data
);

const encryptedBytes = new Uint8Array(encryptedBuffer);
const encryptedBase64 = btoa(String.fromCharCode(...encryptedBytes));
return `ENC:${encryptedBase64}`;
}

// Example usage in a browser environment:
// encryptPassword('your_password', 'value for config.bot.gunthy_wallet')

JavaScript - Node.js​

const crypto = require('crypto');

function encryptPassword(password, key) {
const encryptionKey = Buffer.from(key).slice(0, 16);
const iv = encryptionKey;

const cipher = crypto.createCipheriv('aes-128-cbc', encryptionKey, iv);
const encrypted = Buffer.concat([cipher.update(password, 'utf8'), cipher.final()]);

// Convert to Base64 and add prefix
return 'ENC:' + encrypted.toString('base64');
}

// Example usage:
// console.log(encryptPassword('your_password', 'value for config.bot.gunthy_wallet'));

Bash (Using OpenSSL)​

Requirements:

  • openssl must be installed.
  • No salt used, and ensure binary output before base64.
#!/usr/bin/env bash

PASSWORD="your_password"
KEY="value for config.bot.gunthy_wallet"

# Truncate key to 16 bytes
KEY_TRUNC=$(echo -n "$KEY" | head -c 16)

# Convert key and IV to hex
KEY_HEX=$(echo -n "$KEY_TRUNC" | xxd -p)
IV_HEX=$KEY_HEX

# Encrypt using openssl (no salt)
# -nosalt to prevent adding salt bytes
ENCRYPTED_BASE64=$(echo -n "$PASSWORD" | openssl enc -aes-128-cbc -K "$KEY_HEX" -iv "$IV_HEX" -nosalt -base64)

# Add prefix
echo "ENC:${ENCRYPTED_BASE64}"

Note: If you find a difference in output compared to the browser result, ensure no extra newline or whitespace is affecting the base64 output. You can add -A to openssl enc to avoid line wrapping if necessary.

Make sure openssl is installed on your system.


Python (Using OpenSSL from subprocess, no extra crypto libs)​

import subprocess

password = 'your_password'
key = 'value for config.bot.gunthy_wallet'

# Truncate key to 16 bytes
key_trunc = key[:16]

# Convert key to hex
key_hex = key_trunc.encode('utf-8').hex()
iv_hex = key_hex # same as key

# Run openssl command
res = subprocess.run([
'openssl', 'enc', '-aes-128-cbc',
'-K', key_hex,
'-iv', iv_hex,
'-nosalt',
'-base64'
], input=password.encode('utf-8'), stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True)

encrypted_base64 = res.stdout.decode().strip()

print(f"ENC:{encrypted_base64}")

Make sure openssl is installed on your system. --- id: api-balances-assets-pairs title: Balances, Assets, and Pairs - Gunbot API sidebar_label: Balances, Assets, and Pairs

Balances, Assets, and Pairs

The API provides endpoints to retrieve information about balances, asset values, and trading pairs on supported exchanges. This page outlines how to use these endpoints to monitor your account's asset balances, track historical values, and explore trading pairs available for trading.

/api/v1/balances​

  • Method: POST
  • Description: Retrieve the balances of assets across exchanges for the authenticated user.

Parameters​

This endpoint does not require any parameters in the request body.

Examples​

cURL​

curl -X POST "https://your-gunbot-instance.com:3000/api/v1/balances" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"

JavaScript (fetch API)​

fetch('https://your-gunbot-instance.com:3000/api/v1/balances', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN'
}
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));

Python (requests library)​

import requests

url = 'https://your-gunbot-instance.com:3000/api/v1/balances'
headers = {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN'
}

response = requests.post(url, headers=headers)
print(response.json())

Response​

[
{
"Asset": "USDT",
"Exchange": "binance",
"Available Qty": "442.84477668",
"On Order": "0.00000000"
},
{
"Asset": "PEPE",
"Exchange": "binance",
"Available Qty": "15837566.43915128",
"On Order": "0.00000000"
},
{
"Asset": "XRP",
"Exchange": "binance",
"Available Qty": "548.11945544",
"On Order": "0.00000000"
}
]

/api/v1/assets/total​

  • Method: POST
  • Description: Retrieve the historical total value of assets in the specified base currency over a time range.

Parameters​

ParameterTypeRequiredDescription
exchangestringYesExchange name (e.g., binance).
basestringYesBase currency to value the assets in (e.g., USDT).
startintYesStart timestamp in milliseconds since Unix epoch.
endintYesEnd timestamp in milliseconds since Unix epoch.

Examples​

cURL​

curl -X POST "https://your-gunbot-instance.com:3000/api/v1/assets/total" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-d '{
"exchange": "binance",
"base": "USDT",
"start": 0,
"end": 1733307452718
}'

JavaScript (fetch API)​

const data = {
exchange: 'binance',
base: 'USDT',
start: 0,
end: Date.now()
};

fetch('https://your-gunbot-instance.com:3000/api/v1/assets/total', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));

Python (requests library)​

import requests
import time

url = 'https://your-gunbot-instance.com:3000/api/v1/assets/total'
headers = {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
'Content-Type': 'application/json'
}
data = {
"exchange": "binance",
"base": "USDT",
"start": 0,
"end": int(time.time() * 1000)
}

response = requests.post(url, headers=headers, json=data)
print(response.json())

Response​

[
{
"id": 44,
"base_key": "binance/USDT",
"amount": 26.361644,
"timestamp": 1732789800000
},
{
"id": 85,
"base_key": "binance/USDT",
"amount": 26.131644,
"timestamp": 1732797000000
}
]

/api/v1/pairs​

  • Method: GET
  • Description: Retrieve a list of trading pairs available on the specified exchange.

Parameters​

ParameterTypeRequiredDescription
exchangestringYesExchange name (e.g., binance#3). URL-encoded.

Examples​

cURL​

curl -G "https://your-gunbot-instance.com:3000/api/v1/pairs" \
--data-urlencode "exchange=binance%233" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"

JavaScript (fetch API)​

const params = new URLSearchParams({
exchange: 'binance#3'
});

fetch(`https://your-gunbot-instance.com:3000/api/v1/pairs?${params.toString()}`, {
method: 'GET',
headers: {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN'
}
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));

Python (requests library)​

import requests

url = 'https://your-gunbot-instance.com:3000/api/v1/pairs'
params = {
'exchange': 'binance#3'
}
headers = {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN'
}

response = requests.get(url, headers=headers, params=params)
print(response.json())

Response​

{
"status": "success",
"pairList": [
"BTC-ETH",
"BTC-LTC",
"BTC-BNB",
"BTC-NEO",
"ETH-QTUM",
"ETH-EOS",
"ETH-SNT"
]
}

/api/v1/pairs/detailed​

  • Method: GET
  • Description: Retrieve detailed information about trading pairs available on the specified exchange.

Parameters​

ParameterTypeRequiredDescription
exchangestringYesExchange name (e.g., binance#3). URL-encoded.

Examples​

cURL​

curl -G "https://your-gunbot-instance.com:3000/api/v1/pairs/detailed" \
--data-urlencode "exchange=binance%233" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"

JavaScript (fetch API)​

const params = new URLSearchParams({
exchange: 'binance#3'
});

fetch(`https://your-gunbot-instance.com:3000/api/v1/pairs/detailed?${params.toString()}`, {
method: 'GET',
headers: {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN'
}
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));

Python (requests library)​

import requests

url = 'https://your-gunbot-instance.com:3000/api/v1/pairs/detailed'
params = {
'exchange': 'binance#3'
}
headers = {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN'
}

response = requests.get(url, headers=headers, params=params)
print(response.json())

Response​

{
"status": "success",
"pairList": {
"BTC": [
{
"pairName": "BTC-ETH",
"volume": 2448.96,
"low": "0.0371999999",
"high": "0.0387800000",
"change": "2.05"
},
{
"pairName": "BTC-LTC",
"volume": 204.38,
"low": "0.0012870000",
"high": "0.0014160000",
"change": "-2.53"
}
]
}
}
```---
id: api-config-files
title: Configuration and File Management - Gunbot API
sidebar_label: Configuration and File Management
sidebar_position: 7
---

# Configuration and File Management

The Configuration and File Management API endpoints provide tools to manage application settings, trading pairs, strategies, and related files. These endpoints allow you to retrieve, update, add, or remove configurations, as well as manage various file types such as backup files, AutoConfig variables, and custom strategies.

The following sections detail the available endpoints, parameters, request examples, and sample responses, enabling precise control and efficient management of Gunbot's configuration and file system.


## `/api/v1/config/full`

- **Method:** `GET`
- **Description:** Retrieve the entire configuration settings of the application.

### Parameters

This endpoint does not require any parameters.

### Examples

#### cURL

```bash
curl -X GET "http://localhost:5051/api/v1/config/full" \
-H "Authorization: Bearer YOUR_TOKEN"

JavaScript (fetch API)​

fetch('http://localhost:5051/api/v1/config/full', {
method: 'GET',
headers: {
'Authorization': 'Bearer YOUR_TOKEN'
}
})
.then(response => response.json())
.then(data => console.log(data));

Python (requests library)​

import requests

url = 'http://localhost:5051/api/v1/config/full'
headers = {
'Authorization': 'Bearer YOUR_TOKEN'
}

response = requests.get(url, headers=headers)
print(response.json())

Response​

{
"status": "success",
"config": {
"pairs": {
"binance": {
"USDT-PEPE": {
"strategy": "channelmaestro",
"enabled": true,
"override": {
"ADX_ENABLED": false,
"ADX_LEVEL": 25,
"ATRX": 0.5,
"ATR_PERIOD": "14",
// Truncated for brevity
}
}
}
}
}
}

/api/v1/config/update​

  • Method: POST
  • Description: Update the entire configuration with a new configuration object.

Parameters​

NameTypeDescription
dataJSONThe new configuration object to apply.

Examples​

cURL​

curl -X POST "http://localhost:5051/api/v1/config/update" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"data": {
// Your new configuration data
}
}'

JavaScript (fetch API)​

fetch('http://localhost:5051/api/v1/config/update', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json'
},
body: JSON.stringify({
data: {
// Your new configuration data
}
})
})
.then(response => response.json())
.then(data => console.log(data));

Python (requests library)​

import requests

url = 'http://localhost:5051/api/v1/config/update'
headers = {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json'
}
payload = {
'data': {
# Your new configuration data
}
}

response = requests.post(url, headers=headers, json=payload)
print(response.json())

Response​

{
"status": "success",
"config": {
// Your updated configuration data
}
}

/api/v1/config/pair/add​

  • Method: POST
  • Description: Add a new trading pair to the configuration.

Parameters​

NameTypeDescription
pairstringThe trading pair to add (e.g., USDT-PEPE).
exchangestringThe exchange name (e.g., binance).
settingsobject(Optional) Specific settings for the trading pair.

Examples​

cURL​

curl -X POST "http://localhost:5051/api/v1/config/pair/add" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"pair": "USDT-PEPE",
"exchange": "binance",
"settings": {}
}'

JavaScript (fetch API)​

fetch('http://localhost:5051/api/v1/config/pair/add', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json'
},
body: JSON.stringify({
pair: 'USDT-PEPE',
exchange: 'binance',
settings: {}
})
})
.then(response => response.json())
.then(data => console.log(data));

Python (requests library)​

import requests

url = 'http://localhost:5051/api/v1/config/pair/add'
headers = {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json'
}
payload = {
'pair': 'USDT-PEPE',
'exchange': 'binance',
'settings': {}
}

response = requests.post(url, headers=headers, json=payload)
print(response.json())

Response​

{
"status": "success"
}

/api/v1/config/pair/remove​

  • Method: POST
  • Description: Remove an existing trading pair from the configuration.

Parameters​

NameTypeDescription
pairstringThe trading pair to remove (e.g., USDT-PEPE).
exchangestringThe exchange name (e.g., binance).

Examples​

cURL​

curl -X POST "http://localhost:5051/api/v1/config/pair/remove" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"pair": "USDT-PEPE",
"exchange": "binance"
}'

JavaScript (fetch API)​

fetch('http://localhost:5051/api/v1/config/pair/remove', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json'
},
body: JSON.stringify({
pair: 'USDT-PEPE',
exchange: 'binance'
})
})
.then(response => response.json())
.then(data => console.log(data));

Python (requests library)​

import requests

url = 'http://localhost:5051/api/v1/config/pair/remove'
headers = {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json'
}
payload = {
'pair': 'USDT-PEPE',
'exchange': 'binance'
}

response = requests.post(url, headers=headers, json=payload)
print(response.json())

Response​

{
"status": "success"
}

/api/v1/config/strategy/add​

  • Method: POST
  • Description: Add a new trading strategy to the configuration.

Parameters​

NameTypeDescription
namestringThe name of the strategy to add (e.g., myStrategy).
settingsobject(Optional) Specific settings for the strategy.

Examples​

cURL​

curl -X POST "http://localhost:5051/api/v1/config/strategy/add" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "myStrategy",
"settings": {}
}'

JavaScript (fetch API)​

fetch('http://localhost:5051/api/v1/config/strategy/add', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'myStrategy',
settings: {}
})
})
.then(response => response.json())
.then(data => console.log(data));

Python (requests library)​

import requests

url = 'http://localhost:5051/api/v1/config/strategy/add'
headers = {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json'
}
payload = {
'name': 'myStrategy',
'settings': {}
}

response = requests.post(url, headers=headers, json=payload)
print(response.json())

Response​

{
"status": "success"
}

/api/v1/config/strategy/remove​

  • Method: POST
  • Description: Remove an existing trading strategy from the configuration.

Parameters​

NameTypeDescription
namestringThe name of the strategy to remove.

Examples​

cURL​

curl -X POST "http://localhost:5051/api/v1/config/strategy/remove" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"name": "myStrategy"}'

JavaScript (fetch API)​

fetch('http://localhost:5051/api/v1/config/strategy/remove', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'myStrategy'
})
})
.then(response => response.json())
.then(data => console.log(data));

Python (requests library)​

import requests

url = 'http://localhost:5051/api/v1/config/strategy/remove'
headers = {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json'
}
payload = {
'name': 'myStrategy'
}

response = requests.post(url, headers=headers, json=payload)
print(response.json())

Response​

{
"status": "success"
}

/api/v1/files/acvar​

  • Method: GET
  • Description: List filenames of available AutoConfig variable files.

Parameters​

This endpoint does not require any parameters.

Examples​

cURL​

curl -X GET "http://localhost:5051/api/v1/files/acvar" \
-H "Authorization: Bearer YOUR_TOKEN"

JavaScript (fetch API)​

fetch('http://localhost:5051/api/v1/files/acvar', {
method: 'GET',
headers: {
'Authorization': 'Bearer YOUR_TOKEN'
}
})
.then(response => response.json())
.then(data => console.log(data));

Python (requests library)​

import requests

url = 'http://localhost:5051/api/v1/files/acvar'
headers = {
'Authorization': 'Bearer YOUR_TOKEN'
}

response = requests.get(url, headers=headers)
print(response.json())

Response​

{
"status": "success",
"result": [
"autoconfig-pairVariables.json",
"autoconfig-variables.json"
]
}

/api/v1/files/acvar/get​

  • Method: POST
  • Description: Retrieve the contents of a specified AutoConfig variable file.

Parameters​

NameTypeDescription
filenamestringThe name of the AutoConfig variable file to retrieve.

Examples​

cURL​

curl -X POST "http://localhost:5051/api/v1/files/acvar/get" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"filename": "autoconfig-variables.json"}'

JavaScript (fetch API)​

fetch('http://localhost:5051/api/v1/files/acvar/get', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json'
},
body: JSON.stringify({
filename: 'autoconfig-variables.json'
})
})
.then(response => response.json())
.then(data => console.log(data));

Python (requests library)​

import requests

url = 'http://localhost:5051/api/v1/files/acvar/get'
headers = {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json'
}
payload = {
'filename': 'autoconfig-variables.json'
}

response = requests.post(url, headers=headers, json=payload)
print(response.json())

Response​

{
"this": 0.1855499735435755,
"pnd": false
}

/api/v1/files/autoconfig/write​

  • Method: POST
  • Description: Write content to the autoconfig.json file.

Parameters​

NameTypeDescription
documentJSONThe content to write into autoconfig.json.

Examples​

cURL​

curl -X POST "http://localhost:5051/api/v1/files/autoconfig/write" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"document": {
"key": "value"
}
}'

JavaScript (fetch API)​

fetch('http://localhost:5051/api/v1/files/autoconfig/write', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json'
},
body: JSON.stringify({
document: {
key: 'value'
}
})
})
.then(response => response.json())
.then(data => console.log(data));

Python (requests library)​

import requests

url = 'http://localhost:5051/api/v1/files/autoconfig/write'
headers = {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json'
}
payload = {
'document': {
'key': 'value'
}
}

response = requests.post(url, headers=headers, json=payload)
print(response.json())

Response​

{
"status": "success"
}

/api/v1/files/backup​

  • Method: POST
  • Description: List available backup files.

Parameters​

This endpoint does not require any parameters.

Examples​

cURL​

curl -X POST "http://localhost:5051/api/v1/files/backup" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json"

JavaScript (fetch API)​

fetch('http://localhost:5051/api/v1/files/backup', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json'
}
})
.then(response => response.json())
.then(data => console.log(data));

Python (requests library)​

import requests

url = 'http://localhost:5051/api/v1/files/backup'
headers = {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json'
}

response = requests.post(url, headers=headers)
print(response.json())

Response​

{
"status": "success",
"result": [
"autoconfig.json.1623252417412",
"autoconfig.json.1623252547918",
"autoconfig.json.1623312859755",
// Truncated for brevity
]
}

/api/v1/files/backup/get​

  • Method: POST
  • Description: Retrieve the contents of a specified backup file.

Parameters​

NameTypeDescription
filenamestringThe name of the backup file to retrieve.

Examples​

cURL​

curl -X POST "http://localhost:5051/api/v1/files/backup/get" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"filename": "autoconfig.json.1624608048720"}'

JavaScript (fetch API)​

fetch('http://localhost:5051/api/v1/files/backup/get', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json'
},
body: JSON.stringify({
filename: 'autoconfig.json.1624608048720'
})
})
.then(response => response.json())
.then(data => console.log(data));

Python (requests library)​

import requests

url = 'http://localhost:5051/api/v1/files/backup/get'
headers = {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json'
}
payload = {
'filename': 'autoconfig.json.1624608048720'
}

response = requests.post(url, headers=headers, json=payload)
print(response.json())

Response​

{
"manageOverrides_binance": {
"pairs": {
"exclude": "UP,DOWN,1L,2L,3L,1S,2S,3S",
"include": "USDT-",
"exchange": "binances",
"maxPairs": 6
},
"filters": {},
"overrides": {},
// Truncated for brevity
}
}

/api/v1/files/custom-editor/get​

  • Method: POST
  • Description: Retrieve the contents of the custom strategy editor file.

Parameters​

This endpoint does not require any parameters.

Examples​

cURL​

curl -X POST "http://localhost:5051/api/v1/files/custom-editor/get" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json"

JavaScript (fetch API)​

fetch('http://localhost:5051/api/v1/files/custom-editor/get', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json'
}
})
.then(response => response.json())
.then(data => console.log(data));

Python (requests library)​

import requests

url = 'http://localhost:5051/api/v1/files/custom-editor/get'
headers = {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json'
}

response = requests.post(url, headers=headers)
print(response.json())

Response​

{}

/api/v1/files/custom-editor/write​

  • Method: POST
  • Description: Write content to the custom strategy editor file.

Parameters​

NameTypeDescription
documentJSONThe content to write into the custom editor file.

Examples​

cURL​

curl -X POST "http://localhost:5051/api/v1/files/custom-editor/write" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"document": {
// Your custom strategy data
}
}'

JavaScript (fetch API)​

fetch('http://localhost:5051/api/v1/files/custom-editor/write', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json'
},
body: JSON.stringify({
document: {
// Your custom strategy data
}
})
})
.then(response => response.json())
.then(data => console.log(data));

Python (requests library)​

import requests

url = 'http://localhost:5051/api/v1/files/custom-editor/write'
headers = {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json'
}
payload = {
'document': {
# Your custom strategy data
}
}

response = requests.post(url, headers=headers, json=payload)
print(response.json())

Response​

{
"status": "success"
}

/api/v1/files/state​

  • Method: GET
  • Description: List filenames of available state files.

Parameters​

This endpoint does not require any parameters.

Examples​

cURL​

curl -X GET "http://localhost:5051/api/v1/files/state" \
-H "Authorization: Bearer YOUR_TOKEN"

JavaScript (fetch API)​

fetch('http://localhost:5051/api/v1/files/state', {
method: 'GET',
headers: {
'Authorization': 'Bearer YOUR_TOKEN'
}
})
.then(response => response.json())
.then(data => console.log(data));

Python (requests library)​

import requests

url = 'http://localhost:5051/api/v1/files/state'
headers = {
'Authorization': 'Bearer YOUR_TOKEN'
}

response = requests.get(url, headers=headers)
print(response.json())

Response​

{
"status": "success",
"result": [
"binance-USDT-ETHFI-state.json",
"binance-USDT-PEPE-state.json",
"binance-USDT-XRP-state.json"
]
}

/api/v1/files/state/get​

  • Method: POST
  • Description: Retrieve the contents of a specific state file.

Parameters​

NameTypeDescription
filenamestringThe name of the state file to retrieve.

Examples​

cURL​

curl -X POST "http://localhost:5051/api/v1/files/state/get" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"filename": "binance-USDT-XRP-state.json"}'

JavaScript (fetch API)​

fetch('http://localhost:5051/api/v1/files/state/get', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json'
},
body: JSON.stringify({
filename: 'binance-USDT-XRP-state.json'
})
})
.then(response => response.json())
.then(data => console.log(data));

Python (requests library)​

import requests

url = 'http://localhost:5051/api/v1/files/state/get'
headers = {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json'
}
payload = {
'filename': 'binance-USDT-XRP-state.json'
}

response = requests.post(url, headers=headers, json=payload)
print(response.json())

Response​

{
"orders": [
{
"time": 1733307452789,
"pair": "USDT-XRP",
"type": "sell",
"rate": 2.3,
"amount": 0.1,
"id": 357044,
"cost": 0.22999999999999998
}
],
"balances": {
// Additional state data
}
}

/api/v1/files/strategy​

  • Method: GET
  • Description: List filenames of available custom strategy files.

Parameters​

This endpoint does not require any parameters.

Examples​

cURL​

curl -X GET "http://localhost:5051/api/v1/files/strategy" \
-H "Authorization: Bearer YOUR_TOKEN"

JavaScript (fetch API)​

fetch('http://localhost:5051/api/v1/files/strategy', {
method: 'GET',
headers: {
'Authorization': 'Bearer YOUR_TOKEN'
}
})
.then(response => response.json())
.then(data => console.log(data));

Python (requests library)​

import requests

url = 'http://localhost:5051/api/v1/files/strategy'
headers = {
'Authorization': 'Bearer YOUR_TOKEN'
}

response = requests.get(url, headers=headers)
print(response.json())

Response​

{
"status": "success",
"result": [
"ema-rsi-gain-sl_strategy.js",
"trend.js",
"stoch-supports_strategy.js"
]
}

/api/v1/files/strategy/get​

  • Method: POST
  • Description: Retrieve the contents of a specific custom strategy file.

Parameters​

NameTypeDescription
filenamestringThe name of the strategy file to retrieve.

Examples​

cURL​

curl -X POST "http://localhost:5051/api/v1/files/strategy/get" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"filename": "best_strategy.js"}'

JavaScript (fetch API)​

fetch('http://localhost:5051/api/v1/files/strategy/get', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json'
},
body: JSON.stringify({
filename: 'best_strategy.js'
})
})
.then(response => response.json())
.then(data => console.log(data));

Python (requests library)​

import requests

url = 'http://localhost:5051/api/v1/files/strategy/get'
headers = {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json'
}
payload = {
'filename': 'best_strategy.js'
}

response = requests.post(url, headers=headers, json=payload)
print(response.json())

Response​

{
// Contents of the strategy file
}

/api/v1/files/strategy/write​

  • Method: POST
  • Description: Write content to a specific custom strategy file.

Parameters​

NameTypeDescription
filenamestringThe name of the strategy file to write to.
documentstringThe content to write into the strategy file.

Examples​

cURL​

curl -X POST "http://localhost:5051/api/v1/files/strategy/write" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"filename": "best_strategy.js",
"document": "// Test Strategy"
}'

JavaScript (fetch API)​

fetch('http://localhost:5051/api/v1/files/strategy/write', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json'
},
body: JSON.stringify({
filename: 'best_strategy.js',
document: '// Test Strategy'
})
})
.then(response => response.json())
.then(data => console.log(data));

Python (requests library)​

import requests

url = 'http://localhost:5051/api/v1/files/strategy/write'
headers = {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json'
}
payload = {
'filename': 'best_strategy.js',
'document': '// Test Strategy'
}

response = requests.post(url, headers=headers, json=payload)
print(response.json())

Response​

{
"status": "success"
}

/api/v1/files/strategy/delete​

  • Method: POST (Note: The method is POST based on the example code, even though it may logically be DELETE.)
  • Description: Delete a specific custom strategy file.

Parameters​

NameTypeDescription
filenamestringThe name of the strategy file to delete.

Examples​

cURL​

curl -X POST "http://localhost:5051/api/v1/files/strategy/delete" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"filename": "best_strategy.js"}'

JavaScript (fetch API)​

fetch('http://localhost:5051/api/v1/files/strategy/delete', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json'
},
body: JSON.stringify({
filename: 'best_strategy.js'
})
})
.then(response => response.json())
.then(data => console.log(data));

Python (requests library)​

import requests

url = 'http://localhost:5051/api/v1/files/strategy/delete'
headers = {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json'
}
payload = {
'filename': 'best_strategy.js'
}

response = requests.post(url, headers=headers, json=payload)
print(response.json())

Response​

{
"status": "success"
}

id: gunbot-api-intro title: Gunbot API Documentation sidebar_label: Intro

Gunbot REST API

The Gunbot REST API enables you to programmatically interact with Gunbot, allowing automation and integration with your own applications and services. It gives you a single API with which you can control trading operations on many exchanges.

Base URL​

All API endpoints use the following base URL:

http://your-gunbot-instance.com:3000/api/v1/
https://your-gunbot-instance.com:3000/api/v1/

Replace your-gunbot-instance.com with the actual domain or IP of your Gunbot instance. The port is identical to the GUI port for your Gunbot instance. When not using the API on localhost, make sure to configure https.

Authentication​

The API uses token-based authentication. Before accessing protected endpoints, authenticate and obtain a token.

Data Format​

  • The API accepts and returns data in JSON format.
  • It uses standard HTTP response codes to indicate request outcomes.

Response Codes​

  • 200 OK: The request was successful.
  • 400 Bad Request: The request was invalid or cannot be processed.
  • 401 Unauthorized: Authentication failed, or the user lacks necessary permissions.
  • 500 Internal Server Error: A server-side error occurred.

Gunbot Workflow​

To automate trading for any pair using the API, follow these steps - similar to when using Gunbot in any other way:

  1. Add the trading pair to the configuration with a valid strategy.
  2. Start the core to activate trading operations.

After completing these steps, you can access API endpoints for market data and trading actions. Gunbot will actively monitor and execute strategies for the specified pairs.

Except for API endpoints that place orders or fetch pair lists, the returned data comes from Gunbot core directly.--- id: api-market-data title: Market, Chart, and Strategy Data - Gunbot API sidebar_label: Market, Chart, and Strategy Data

Market, Chart, and Strategy Data

The Market, Chart, and Strategy Data endpoints provide access to market data collected by Gunbot for active trading pairs. These endpoints allow you to retrieve historical market candles, order book details and data from core memory snapshots.

Endpoints in this category provide market data already collected by Gunbot for active trading pairs.

/api/v1/market/candles​

  • Method: GET
  • Description: Retrieve historical candle data in OHLCV format for a specific trading pair.

Parameters​

ParameterTypeRequiredDescription
keystringYesThe unique identifier for the trading pair, URL-encoded (e.g., binance/USDT-XRP becomes binance%2FUSDT-XRP).

Examples​

cURL​

curl -X GET "https://your-gunbot-instance.com:3000/api/v1/market/candles?key=binance%2FUSDT-PEPE" \
-H "Authorization: Bearer YOUR_TOKEN"

JavaScript (fetch API)​

const params = new URLSearchParams({
key: 'binance/USDT-PEPE',
});
fetch(`https://your-gunbot-instance.com:3000/api/v1/market/candles?${params.toString()}`, {
method: 'GET',
headers: {
'Authorization': 'Bearer YOUR_TOKEN',
},
})
.then(response => response.json())
.then(data => console.log(data));

Python (requests library)​

import requests
url = 'https://your-gunbot-instance.com:3000/api/v1/market/candles'
params = {
'key': 'binance/USDT-PEPE',
}
headers = {
'Authorization': 'Bearer YOUR_TOKEN',
}
response = requests.get(url, params=params, headers=headers)
data = response.json()
print(data)

Response​

{
"data": {
"close": [
// Array of close prices (truncated for brevity)
],
"high": [
// Array of high prices (truncated for brevity)
],
"low": [
// Array of low prices (truncated for brevity)
],
"volume": [
// Array of volumes (truncated for brevity)
],
"open": [
// Array of open prices (truncated for brevity)
]
}
}

/api/v1/market/orderbook​

  • Method: GET
  • Description: Retrieve the current order book data (bids and asks) for a specific trading pair.

Parameters​

ParameterTypeRequiredDescription
keystringYesThe unique identifier for the trading pair, URL-encoded (e.g., binance/USDT-XRP becomes binance%2FUSDT-XRP).

Examples​

cURL​

curl -X GET "https://your-gunbot-instance.com:3000/api/v1/market/orderbook?key=binance%2FUSDT-PEPE" \
-H "Authorization: Bearer YOUR_TOKEN"

JavaScript (fetch API)​

const params = new URLSearchParams({
key: 'binance/USDT-PEPE',
});
fetch(`https://your-gunbot-instance.com:3000/api/v1/market/orderbook?${params.toString()}`, {
method: 'GET',
headers: {
'Authorization': 'Bearer YOUR_TOKEN',
},
})
.then(response => response.json())
.then(data => console.log(data));

Python (requests library)​

import requests
url = 'https://your-gunbot-instance.com:3000/api/v1/market/orderbook'
params = {
'key': 'binance/USDT-PEPE',
}
headers = {
'Authorization': 'Bearer YOUR_TOKEN',
}
response = requests.get(url, params=params, headers=headers)
data = response.json()
print(data)

Response​

{
"data": {
"ask": [
// Array of ask orders (truncated for brevity)
],
"bid": [
// Array of bid orders (truncated for brevity)
]
}
}

/api/v1/coremem/raw​

  • Method: POST
  • Description: Retrieves raw core memory data for a specific trading pair. Allows filtering to include only specific elements or returns all core memory data for the pair if no elements are specified.

Parameters​

NameTypeRequiredDescription
exchangestringYesThe exchange to query (e.g., binance).
pairstringYesThe trading pair to query (e.g., BTC-ADA).
elementsarrayNoOptional array of elements to filter the response (e.g., ['ABP', 'Bid']). If omitted, returns all core memory data.

Examples​

cURL​

curl -X POST "https://your-gunbot-instance.com:3000/api/v1/coremem/raw" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN_HERE" \
-d '{
"exchange": "binance",
"pair": "BTC-ADA",
"elements": ["ABP", "Bid"]
}'

JavaScript (fetch API)​

const body = {
exchange: 'binance',
pair: 'BTC-ADA',
elements: ['ABP', 'Bid'] // Optional
};

fetch('https://your-gunbot-instance.com:3000/api/v1/coremem/raw', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_TOKEN_HERE',
'Content-Type': 'application/json'
},
body: JSON.stringify(body)
})
.then(response => response.json())
.then(data => console.log(data));

Python (requests library)​

import requests

data = {
'exchange': 'binance',
'pair': 'BTC-ADA',
'elements': ['ABP', 'Bid'] # Optional
}

headers = {
'Authorization': 'Bearer YOUR_TOKEN_HERE',
'Content-Type': 'application/json'
}

response = requests.post('https://your-gunbot-instance.com:3000/api/v1/coremem/raw', json=data, headers=headers)
print(response.json())

Response​

When specific elements are requested:

{
"ABP": 0.000012009454969475356,
"Bid": 0.00001137
}

When no elements are specified, the response includes all core memory data for the specified trading pair:

{
"ABP": 0.000012009454969475356,
"Bid": 0.00001137,
"...": "All other core memory key-value pairs for the trading pair"
}

/api/v1/coremem​

  • Method: POST
  • Description: Retrieve a snapshot of relevant core memory data for all active trading pairs. Data is slightly delayed and sometimes transformed, for example from number to string, intended for frontend usage.

Parameters None​

Examples​

cURL​

curl -X POST "https://your-gunbot-instance.com:3000/api/v1/coremem" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN"

JavaScript (fetch API)​

fetch('https://your-gunbot-instance.com:3000/api/v1/coremem', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json'
},
})
.then(response => response.json())
.then(data => console.log(data));

Python (requests library)​

import requests
url = 'https://your-gunbot-instance.com:3000/api/v1/coremem'
headers = {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json'
}
response = requests.post(url, headers=headers)
data = response.json()
print(data)

Response​

{
// Core memory data for all active symbols (truncated for brevity)
}

/api/v1/coremem/single​

  • Method: POST
  • Description: Retrieve a snapshot of relevant core memory data for a single active trading pair. Data is slightly delayed and sometimes transformed, for example from number to string, intended for frontend usage.

Parameters​

ParameterTypeRequiredDescription
exchangestringYesThe exchange name (e.g., binance).
pairstringYesThe trading pair (e.g., USDT-XRP).

Examples​

cURL​

curl -X POST "https://your-gunbot-instance.com:3000/api/v1/coremem/single" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{
"exchange": "binance",
"pair": "USDT-XRP"
}'

JavaScript (fetch API)​

const data = {
exchange: 'binance',
pair: 'USDT-XRP',
};
fetch('https://your-gunbot-instance.com:3000/api/v1/coremem/single', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
})
.then(response => response.json())
.then(data => console.log(data));

Python (requests library)​

import requests
url = 'https://your-gunbot-instance.com:3000/api/v1/coremem/single'
headers = {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json',
}
data = {
'exchange': 'binance',
'pair': 'USDT-XRP',
}
response = requests.post(url, headers=headers, json=data)
data = response.json()
print(data)

Response​

{
// Core memory data for the specified symbol (truncated for brevity)
}

/api/v1/chart/data​

  • Method: POST
  • Description: Retrieve chart data, including candles and indicators, for a specific trading pair.

Parameters​

ParameterTypeRequiredDescription
exchangestringYesThe exchange name (e.g., binance).
pairstringYesThe trading pair (e.g., USDT-XRP).

Examples​

cURL​

curl -X POST "https://your-gunbot-instance.com:3000/api/v1/chart/data" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{
"exchange": "binance",
"pair": "USDT-XRP"
}'

JavaScript (fetch API)​

const data = {
exchange: 'binance',
pair: 'USDT-XRP',
};
fetch('https://your-gunbot-instance.com:3000/api/v1/chart/data', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
})
.then(response => response.json())
.then(data => console.log(data));

Python (requests library)​

import requests
url = 'https://your-gunbot-instance.com:3000/api/v1/chart/data'
headers = {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json',
}
data = {
'exchange': 'binance',
'pair': 'USDT-XRP',
}
response = requests.post(url, headers=headers, json=data)
data = response.json()
print(data)

Response​

{
// Chart data with candle and indicator arrays
}

/api/v1/chart/marks​

  • Method: GET
  • Description: Retrieve chart timescale marks (annotations) such as buy/sell trigger info for a specific trading pair and time interval.

Parameters​

ParameterTypeRequiredDescription
exchangestringYesThe exchange name (e.g., binance).
pairstringYesThe trading pair (e.g., USDT-XRP).
intervalstringYesThe time interval in minutes (e.g., 15).
startTimestringYesThe start time in UNIX timestamp seconds (e.g., 0).
endTimestringYesThe end time in UNIX timestamp seconds (e.g., 2114377200).

Examples​

cURL​

curl -X GET "https://your-gunbot-instance.com:3000/api/v1/chart/marks?exchange=binance&pair=USDT-XRP&interval=15&startTime=0&endTime=2114377200" \
-H "Authorization: Bearer YOUR_TOKEN"

JavaScript (fetch API)​

const params = new URLSearchParams({
exchange: 'binance',
pair: 'USDT-XRP',
interval: '15',
startTime: '0',
endTime: '2114377200',
});
fetch(`https://your-gunbot-instance.com:3000/api/v1/chart/marks?${params.toString()}`, {
method: 'GET',
headers: {
'Authorization': 'Bearer YOUR_TOKEN',
},
})
.then(response => response.json())
.then(data => console.log(data));

Python (requests library)​

import requests
url = 'https://your-gunbot-instance.com:3000/api/v1/chart/marks'
params = {
'exchange': 'binance',
'pair': 'USDT-XRP',
'interval': '15',
'startTime': '0',
'endTime': '2114377200',
}
headers = {
'Authorization': 'Bearer YOUR_TOKEN',
}
response = requests.get(url, params=params, headers=headers)
data = response.json()
print(data)

Response​

[
{
"exchange": "binance",
"pair": "USDT-PEPE",
"id": "3313",
"time": 1733391240,
"color": "rgba(38, 166, 154, 0.8)",
"label": "â–²",
"tooltip": [
"",
"🟩 1733391279657 convert",
"Buy 9083536.00028041 PEPE",
"@ 0.00002162 USDT",
"Total: 196.386 USDT"
]
},
{
"exchange": "binance",
"pair": "USDT-PEPE",
"id": "3314",
"time": 1733391300,
"color": "rgba(38, 166, 154, 0.8)",
"label": "â–²",
"tooltip": [
"",
"🟦 1733391324904 convert",
"Buy step skipped 0.00002157: order blocked by trend module"
]
},
// Additional entries (truncated for brevity)
]

id: api-pnl title: Profit and Loss (PNL) - Gunbot API sidebar_label: Profit and Loss

Profit and Loss (PNL)

The Profit and Loss (PNL) API endpoints provide tools to retrieve detailed financial performance metrics for trading keys and exchanges. These endpoints allow you to track daily PNL data, calculate the total sum of PNL and investment over time, and navigate large datasets with pagination.

The following sections outline how to use these endpoints, including required parameters, request examples in various programming languages, and sample responses for common use cases.

/api/v1/pnl/overview​

  • Method: POST
  • Description: Retrieves an overview of Profit and Loss (PNL) data, summarized over different time periods and trading pairs.

Parameters​

NameTypeRequiredDescription
timezonestringYesThe timezone to use for calculating date ranges (e.g., Europe/Amsterdam).
keysarrayYesAn array of trading keys (e.g., ['binance/USDT-BTC', 'binance/USDT-XRP']). Use ['All'] to get all the results.
dateRangeobjectNoOptional custom date range. If provided, it must be in the format { startDate: 1733743909461, endDate: 1734348709461 }.

Examples​

cURL​

curl -X POST "https://your-gunbot-instance.com:3000/api/v1/pnl/overview" \
-H "Authorization: Bearer YOUR_TOKEN_HERE" \
-H "Content-Type: application/json" \
-d '{
"timezone": "Europe/Amsterdam",
"keys": ["All"],
"dateRange": { "startDate": 1733743909461, "endDate": 1734348709461 }
}'

JavaScript (fetch API)​

const body = {
timezone: 'Europe/Amsterdam',
keys: ['All'],
dateRange: { startDate: 1733743909461, endDate: 1734348709461 }
};

fetch('https://your-gunbot-instance.com:3000/api/v1/pnl/overview', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_TOKEN_HERE',
'Content-Type': 'application/json'
},
body: JSON.stringify(body)
})
.then(response => response.json())
.then(data => console.log(data));

Python (requests library)​

import requests

data = {
'timezone': 'Europe/Amsterdam',
'keys': ['All'],
'dateRange': { 'startDate': 1733743909461, 'endDate': 1734348709461 }
}

headers = {
'Authorization': 'Bearer YOUR_TOKEN_HERE',
'Content-Type': 'application/json'
}

response = requests.post('https://your-gunbot-instance.com:3000/api/v1/pnl/overview', json=data, headers=headers)
print(response.json())

Response​

{
"today": {
"pnl": 0,
"perPair": {}
},
"yesterday": {
"pnl": 0
},
"weekAgo": {
"pnl": 13.966174729957487
},
"monthAgo": {
"pnl": 172.26520619518234
},
"yearAgo": {
"pnl": 172.26520619518234,
"perPair": {
"binance/BTC-ADA": {...},
"binance/BTC-DOGE": {...}
}
},
"total": {
"pnl": 172.26520619518234,
"numberOfTrades": 106,
"heroTrade": {
"pnl": 43.28911255406681,
"time": 1733099150422
},
"fuckupTrade": {
"pnl": -2.1478359571630734,
"time": 1732896563996
},
"averagePnl": 1.6251434546715315,
"sellCount": 21,
"buyCount": 85,
"winning": 6,
"losing": 0,
"breakeven": 8,
"winRate": "100.0",
"buyPnl": 0,
"sellPnl": 172.26520619518234,
"buyBaseValue": 4270.679722132944,
"sellBaseValue": 3291.7711708390443
},
"lastYear": {
"pnl": 0
},
"dailyHistory": [
{
"date": "2024-11-22",
"numberOfTrades": 1,
"totalVolume": 39.113713719480394,
"pnl": 0,
"cumulativePnl": 0,
"cumulativePnlPercent": 0
},
...
],
"pnlsPerPair": [
{
"key": "binance/BTC-ADA",
"pnl": 120.91196932835516
},
{
"key": "binance/BTC-DOGE",
"pnl": 51.35323686682719
}
],
"detailedPerPair": [
{
"strategy": "stepgrid",
"cumulative_pnl": 0.001224695617080708,
"cumulative_profit": 0.0012591197692164793,
"cumulative_loss": -0.00003442415213577119,
"cumulative_fees": 0.000052610508000000016,
"cumulative_costproceed_wins": 0.022683785508000005,
"cumulative_costproceed_losses": 0.0010369140480000001,
"profit_count": 17,
"loss_count": 2,
"unique_profit_count": 7,
"unique_loss_count": 0,
"buy_count": 55,
"sell_count": 19,
"unique_buy_count": 55,
"unique_sell_count": 7,
"cumulative_buy_value": 0.028866064000000004,
"cumulative_sell_value": 0.023744444,
"daily_pnl_per_thousand": "16.74",
"unrealized_pnl": -0.0003144618476607431,
"key": "binance/BTC-ADA"
},
...
],
"unit": "USDT"
}

/api/v1/pnl/daily​

  • Method: GET
  • Description: Retrieves daily Profit and Loss (PNL) data for a specific trading key within a given time range.

Parameters​

NameTypeRequiredDescription
keystringYesThe trading key (e.g., binance/USDT-XRP). URL-encode if necessary (e.g., binance%2FUSDT-XRP).
startTimestampnumberYesStart timestamp in milliseconds since epoch (e.g., 0).
endTimestampnumberYesEnd timestamp in milliseconds since epoch (e.g., Date.now()).

Examples​

cURL​

curl -X GET "https://your-gunbot-instance.com:3000/api/v1/pnl/daily?key=binance%2FUSDT-XRP&startTimestamp=0&endTimestamp=1733307452623" \
-H "Authorization: Bearer YOUR_TOKEN_HERE"

JavaScript (fetch API)​

const params = new URLSearchParams({
key: 'binance/USDT-XRP', // URL-encoded automatically
startTimestamp: 0,
endTimestamp: Date.now()
});

fetch(`https://your-gunbot-instance.com:3000/api/v1/pnl/daily?${params.toString()}`, {
method: 'GET',
headers: {
'Authorization': 'Bearer YOUR_TOKEN_HERE'
}
})
.then(response => response.json())
.then(data => console.log(data));

Python (requests library)​

import requests

params = {
'key': 'binance/USDT-XRP',
'startTimestamp': 0,
'endTimestamp': 1733307452623
}

headers = {
'Authorization': 'Bearer YOUR_TOKEN_HERE'
}

response = requests.get('https://your-gunbot-instance.com:3000/api/v1/pnl/daily', params=params, headers=headers)
print(response.json())

Response​

{
"dateRangeDailyHistory": [],
"unmatchedBaseValuePerDateRange": 0
}

/api/v1/pnl/daily/paginated​

  • Method: GET
  • Description: Retrieves paginated daily PNL data for a specific trading key, allowing for efficient data handling and navigation through large datasets.

Parameters​

NameTypeRequiredDescription
keystringYesThe trading key (e.g., binance/USDT-XRP). URL-encode if necessary.
pageNumnumberYesThe page number to retrieve (e.g., 1).
pageSizenumberYesThe number of records per page (e.g., 10).
endTimenumberYesEnd timestamp in milliseconds since epoch (e.g., Date.now()).

Examples​

cURL​

curl -X GET "https://your-gunbot-instance.com:3000/api/v1/pnl/daily/paginated?key=binance%2FUSDT-XRP&pageNum=1&pageSize=10&endTime=1733307452649" \
-H "Authorization: Bearer YOUR_TOKEN_HERE"

JavaScript (fetch API)​

const params = new URLSearchParams({
key: 'binance/USDT-XRP',
pageNum: 1,
pageSize: 10,
endTime: Date.now()
});

fetch(`https://your-gunbot-instance.com:3000/api/v1/pnl/daily/paginated?${params.toString()}`, {
method: 'GET',
headers: {
'Authorization': 'Bearer YOUR_TOKEN_HERE'
}
})
.then(response => response.json())
.then(data => console.log(data));

Python (requests library)​

import requests

params = {
'key': 'binance/USDT-XRP',
'pageNum': 1,
'pageSize': 10,
'endTime': 1733307452649
}

headers = {
'Authorization': 'Bearer YOUR_TOKEN_HERE'
}

response = requests.get('https://your-gunbot-instance.com:3000/api/v1/pnl/daily/paginated', params=params, headers=headers)
print(response.json())

Response​

{
"totalSize": 0,
"data": []
}

/api/v1/pnl/sum​

  • Method: GET
  • Description: Retrieves the total sum of PNL and investment for a specific exchange over a given time range.

Parameters​

NameTypeRequiredDescription
exchangestringYesThe exchange key (e.g., binance/USDT-XRP). URL-encode if necessary.
startTimestampnumberYesStart timestamp in milliseconds since epoch (e.g., 0).
endTimestampnumberYesEnd timestamp in milliseconds since epoch (e.g., Date.now()).

Examples​

cURL​

curl -X GET "https://your-gunbot-instance.com:3000/api/v1/pnl/sum?exchange=binance%2FUSDT-XRP&startTimestamp=0&endTimestamp=1733307452649" \
-H "Authorization: Bearer YOUR_TOKEN_HERE"

JavaScript (fetch API)​

const params = new URLSearchParams({
exchange: 'binance/USDT-XRP',
startTimestamp: 0,
endTimestamp: Date.now()
});

fetch(`https://your-gunbot-instance.com:3000/api/v1/pnl/sum?${params.toString()}`, {
method: 'GET',
headers: {
'Authorization': 'Bearer YOUR_TOKEN_HERE'
}
})
.then(response => response.json())
.then(data => console.log(data));

Python (requests library)​

import requests

params = {
'exchange': 'binance/USDT-XRP',
'startTimestamp': 0,
'endTimestamp': 1733307452649
}

headers = {
'Authorization': 'Bearer YOUR_TOKEN_HERE'
}

response = requests.get('https://your-gunbot-instance.com:3000/api/v1/pnl/sum', params=params, headers=headers)
print(response.json())

Response​

{
"tournamentData": {
"sommaPnl": "0.00000000",
"invested": "0.00000000"
},
"data": []
}

/api/v1/pnl/total​

  • Method: GET
  • Description: Retrieves the total PNL for a specific trading key.

Parameters​

NameTypeRequiredDescription
keystringYesThe trading key (e.g., binance/USDT-XRP). URL-encode if necessary.

Examples​

cURL​

curl -X GET "https://your-gunbot-instance.com:3000/api/v1/pnl/total?key=binance%2FUSDT-XRP" \
-H "Authorization: Bearer YOUR_TOKEN_HERE"

JavaScript (fetch API)​

const params = new URLSearchParams({
key: 'binance/USDT-XRP'
});

fetch(`https://your-gunbot-instance.com:3000/api/v1/pnl/total?${params.toString()}`, {
method: 'GET',
headers: {
'Authorization': 'Bearer YOUR_TOKEN_HERE'
}
})
.then(response => response.json())
.then(data => console.log(data));

Python (requests library)​

import requests

params = {
'key': 'binance/USDT-XRP'
}

headers = {
'Authorization': 'Bearer YOUR_TOKEN_HERE'
}

response = requests.get('https://your-gunbot-instance.com:3000/api/v1/pnl/total', params=params, headers=headers)
print(response.json())

Response​

{}

Note: Replace YOUR_TOKEN_HERE with your actual authorization token in the headers. Ensure that all query parameters are properly URL-encoded, especially if they contain special characters like / or #.--- id: api-system-status-license title: System, Status, and License Management - Gunbot API sidebar_label: System and License Management

System, Status, and License Management

The System, Status, and License Management API endpoints provide tools to control Gunbot's system operations and manage license configurations. These endpoints allow you to start or stop the system, retrieve server time, and update license keys.

The following sections outline the available endpoints, including parameter details, request examples in multiple programming languages, and example responses to help users effectively interact with Gunbot's system and licensing features.

/api/v1/system/start​

  • Method: POST
  • Description: Starts the system and returns the current configuration without private keys.

Headers:

NameTypeDescription
AuthorizationstringBearer token for authentication.
Content-Typestringapplication/json

Parameters​

This endpoint does not require any request parameters.

Examples​

cURL​

curl -X POST "https://your-gunbot-instance.com:3000/api/v1/system/start" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_BEARER_TOKEN"

JavaScript (fetch API)​

fetch('https://your-gunbot-instance.com:3000/api/v1/system/start', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_BEARER_TOKEN',
'Content-Type': 'application/json'
}
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));

Python (requests library)​

import requests

url = 'https://your-gunbot-instance.com:3000/api/v1/system/start'
headers = {
'Authorization': 'Bearer YOUR_BEARER_TOKEN',
'Content-Type': 'application/json'
}

response = requests.post(url, headers=headers)
print(response.json())

Response​

{
// returns the current configuration without private keys
}

/api/v1/system/stop​

  • Method: POST
  • Description: Stops the system and returns the current configuration without private keys.

Headers:

NameTypeDescription
AuthorizationstringBearer token for authentication.
Content-Typestringapplication/json

Parameters​

This endpoint does not require any request parameters.

Examples​

cURL​

curl -X POST "https://your-gunbot-instance.com:3000/api/v1/system/stop" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_BEARER_TOKEN"

JavaScript (fetch API)​

fetch('https://your-gunbot-instance.com:3000/api/v1/system/stop', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_BEARER_TOKEN',
'Content-Type': 'application/json'
}
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));

Python (requests library)​

import requests

url = 'https://your-gunbot-instance.com:3000/api/v1/system/stop'
headers = {
'Authorization': 'Bearer YOUR_BEARER_TOKEN',
'Content-Type': 'application/json'
}

response = requests.post(url, headers=headers)
print(response.json())

Response​

{
// returns the current configuration without private keys
}

/api/v1/time​

  • Method: GET
  • Description: Retrieves the current server time in milliseconds since Unix epoch.

Headers:

NameTypeDescription
AuthorizationstringBearer token for authentication.

Parameters​

This endpoint does not require any request parameters.

Examples​

cURL​

curl -X GET "https://your-gunbot-instance.com:3000/api/v1/time" \
-H "Authorization: Bearer YOUR_BEARER_TOKEN"

JavaScript (fetch API)​

fetch('https://your-gunbot-instance.com:3000/api/v1/time', {
method: 'GET',
headers: {
'Authorization': 'Bearer YOUR_BEARER_TOKEN'
}
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));

Python (requests library)​

import requests

url = 'https://your-gunbot-instance.com:3000/api/v1/time'
headers = {
'Authorization': 'Bearer YOUR_BEARER_TOKEN'
}

response = requests.get(url, headers=headers)
print(response.json())

Response​

{
"serverTime": 1733307452501
}

/api/v1/license/keys/edit​

  • Method: POST
  • Description: Edits license keys associated with a wallet and optionally verifies an exchange.

Parameters​

NameTypeDescription
walletstringWallet address (e.g., 0xYourWalletAddress).
newLicensesobjectObject containing new license data. Use the entire config.exchanges object to place in config, with key changes. For new keys, set the isEncrypted value to false. Multiple key changes at once are possible
verifyExchangestringExchange used to verify (e.g., binance). Provide the name of an exchange that currently has valid, registered credentials in your configuration. This name will be used to authenticate the request.

Examples​

cURL​

curl -X POST "https://your-gunbot-instance.com:3000/api/v1/license/keys/edit" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_BEARER_TOKEN" \
-d '{
"wallet": "0xYourWalletAddress",
"newLicenses": {},
"verifyExchange": "binance"
}'

JavaScript (fetch API)​

const data = {
wallet: '0xYourWalletAddress',
newLicenses: {

},
verifyExchange: 'binance'
};

fetch('https://your-gunbot-instance.com:3000/api/v1/license/keys/edit', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_BEARER_TOKEN',
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));

Python (requests library)​

import requests

url = 'https://your-gunbot-instance.com:3000/api/v1/license/keys/edit'
headers = {
'Authorization': 'Bearer YOUR_BEARER_TOKEN',
'Content-Type': 'application/json'
}
data = {
"wallet": "0xYourWalletAddress",
"newLicenses": {
},
"verifyExchange": "binance"
}

response = requests.post(url, headers=headers, json=data)
print(response.json())

Response​

{
"status": "success"
}
```---
id: api-trading-orders
title: Trading and Orders - Gunbot API
sidebar_label: Trading and Orders
sidebar_position: 5
---

# Trading and Orders

The Trading and Orders API endpoints allow you to execute various trading actions such as placing buy and sell orders on supported exchanges, canceling existing orders, and retrieving detailed historical order information.

The following sections outline how to interact with these endpoints, including parameter details, request examples in multiple programming languages, and sample responses.

To place an order for any pair, at least one trading pair on that exchange must be actively cyling in Gunbot Core.


## `/api/v1/trade/buy`

- **Method:** `POST`
- **Description:** Place a limit buy order on a specified exchange for a given trading pair at a set price.

### Parameters

| Parameter | Type | Required | Description |
|-----------|--------|----------|-----------------------------------------------------|
| `exch` | string | Yes | Exchange name (e.g., `binance`). |
| `pair` | string | Yes | Trading pair symbol (e.g., `USDT-BTC`). |
| `amt` | number | Yes | Amount of the asset to buy. |
| `price` | number | Yes | Limit price at which to place the buy order. |

### Examples

#### cURL

```bash
curl -X POST https://your-gunbot-instance.com:3000/api/v1/trade/buy \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{
"data": {
"exch": "binance",
"pair": "USDT-BTC",
"amt": 1.0,
"price": 50000
}
}'

JavaScript (fetch API)​

fetch('https://your-gunbot-instance.com:3000/api/v1/trade/buy', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_TOKEN'
},
body: JSON.stringify({
data: {
exch: 'binance',
pair: 'USDT-BTC',
amt: 1.0,
price: 50000
}
})
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));

Python (requests library)​

import requests

url = 'https://your-gunbot-instance.com:3000/api/v1/trade/buy'
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_TOKEN'
}
data = {
'data': {
'exch': 'binance',
'pair': 'USDT-BTC',
'amt': 1.0,
'price': 50000
}
}
response = requests.post(url, json=data, headers=headers)
print(response.json())

Response​

{
"status": "success",
"message": "Order sent"
}

/api/v1/trade/buy/market​

  • Method: POST
  • Description: Place a market buy order on a specified exchange for a given trading pair at the current market price.

Parameters​

ParameterTypeRequiredDescription
exchstringYesExchange name (e.g., binance).
pairstringYesTrading pair symbol (e.g., USDT-BTC).
amtnumberYesAmount of the asset to buy.
pricenumberNoOptional for market orders; defaults to market price.

Examples​

cURL​

curl -X POST https://your-gunbot-instance.com:3000/api/v1/trade/buy/market \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{
"data": {
"exch": "binance",
"pair": "USDT-BTC",
"amt": 1.0
}
}'

JavaScript (fetch API)​

fetch('https://your-gunbot-instance.com:3000/api/v1/trade/buy/market', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_TOKEN'
},
body: JSON.stringify({
data: {
exch: 'binance',
pair: 'USDT-BTC',
amt: 1.0
}
})
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));

Python (requests library)​

import requests

url = 'https://your-gunbot-instance.com:3000/api/v1/trade/buy/market'
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_TOKEN'
}
data = {
'data': {
'exch': 'binance',
'pair': 'USDT-BTC',
'amt': 1.0
}
}
response = requests.post(url, json=data, headers=headers)
print(response.json())

Response​

{
"status": "success",
"message": "Order sent"
}

/api/v1/trade/sell​

  • Method: POST
  • Description: Place a limit sell order on a specified exchange for a given trading pair at a set price.

Parameters​

ParameterTypeRequiredDescription
exchstringYesExchange name (e.g., binance).
pairstringYesTrading pair symbol (e.g., USDT-BTC).
amtnumberYesAmount of the asset to sell.
pricenumberYesLimit price at which to place the sell order.

Examples​

cURL​

curl -X POST https://your-gunbot-instance.com:3000/api/v1/trade/sell \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{
"data": {
"exch": "binance",
"pair": "USDT-BTC",
"amt": 1.0,
"price": 52500
}
}'

JavaScript (fetch API)​

fetch('https://your-gunbot-instance.com:3000/api/v1/trade/sell', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_TOKEN'
},
body: JSON.stringify({
data: {
exch: 'binance',
pair: 'USDT-BTC',
amt: 1.0,
price: 52500
}
})
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));

Python (requests library)​

import requests

url = 'https://your-gunbot-instance.com:3000/api/v1/trade/sell'
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_TOKEN'
}
data = {
'data': {
'exch': 'binance',
'pair': 'USDT-BTC',
'amt': 1.0,
'price': 52500
}
}
response = requests.post(url, json=data, headers=headers)
print(response.json())

Response​

{
"status": "success",
"message": "Order sent"
}

/api/v1/trade/sell/market​

  • Method: POST
  • Description: Place a market sell order on a specified exchange for a given trading pair at the current market price.

Parameters​

ParameterTypeRequiredDescription
exchstringYesExchange name (e.g., binance).
pairstringYesTrading pair symbol (e.g., USDT-BTC).
amtnumberYesAmount of the asset to sell.
pricenumberNoOptional for market orders; defaults to market price.

Examples​

cURL​

curl -X POST https://your-gunbot-instance.com:3000/api/v1/trade/sell/market \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{
"data": {
"exch": "binance",
"pair": "USDT-BTC",
"amt": 1.0
}
}'

JavaScript (fetch API)​

fetch('https://your-gunbot-instance.com:3000/api/v1/trade/sell/market', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_TOKEN'
},
body: JSON.stringify({
data: {
exch: 'binance',
pair: 'USDT-BTC',
amt: 1.0
}
})
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));

Python (requests library)​

import requests

url = 'https://your-gunbot-instance.com:3000/api/v1/trade/sell/market'
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_TOKEN'
}
data = {
'data': {
'exch': 'binance',
'pair': 'USDT-BTC',
'amt': 1.0
}
}
response = requests.post(url, json=data, headers=headers)
print(response.json())

Response​

{
"status": "success",
"message": "Order sent"
}

/api/v1/trade/cancel​

  • Method: POST
  • Description: Cancel an existing order on a specified exchange for a given trading pair.

Parameters​

ParameterTypeRequiredDescription
exchstringYesExchange name (e.g., binance).
pairstringYesTrading pair symbol (e.g., USDT-BTC).
idstringYesOrder ID of the order to cancel.
pricenumberYesPrice at which the order was placed.
typestringYesOrder type (limit or market).

Examples​

cURL​

curl -X POST https://your-gunbot-instance.com:3000/api/v1/trade/cancel \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{
"data": {
"exch": "binance",
"pair": "USDT-BTC",
"id": "357044",
"price": 50000,
"type": "limit"
}
}'

JavaScript (fetch API)​

fetch('https://your-gunbot-instance.com:3000/api/v1/trade/cancel', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_TOKEN'
},
body: JSON.stringify({
data: {
exch: 'binance',
pair: 'USDT-BTC',
id: '357044',
price: 50000,
type: 'limit'
}
})
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));

Python (requests library)​

import requests

url = 'https://your-gunbot-instance.com:3000/api/v1/trade/cancel'
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_TOKEN'
}
data = {
'data': {
'exch': 'binance',
'pair': 'USDT-BTC',
'id': '357044',
'price': 50000,
'type': 'limit'
}
}
response = requests.post(url, json=data, headers=headers)
print(response.json())

Response​

{
"status": "success",
"message": "Order sent"
}

/api/v1/orders​

  • Method: GET
  • Description: Retrieve all locally stored order history for a specified trading pair on an exchange.

Parameters​

ParameterTypeRequiredDescription
keystringYesCombined exchange and trading pair in the format exchange/pair (e.g., binance/USDT-XRP). Must be URL-encoded.

Examples​

cURL​

curl -G https://your-gunbot-instance.com:3000/api/v1/orders \
-H "Authorization: Bearer YOUR_TOKEN" \
--data-urlencode "key=binance/USDT-XRP"

JavaScript (fetch API)​

const params = new URLSearchParams({
key: 'binance/USDT-XRP'
});

fetch(`https://your-gunbot-instance.com:3000/api/v1/orders?${params.toString()}`, {
method: 'GET',
headers: {
'Authorization': 'Bearer YOUR_TOKEN'
}
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));

Python (requests library)​

import requests

url = 'https://your-gunbot-instance.com:3000/api/v1/orders'
headers = {
'Authorization': 'Bearer YOUR_TOKEN'
}
params = {
'key': 'binance/USDT-XRP'
}
response = requests.get(url, headers=headers, params=params)
print(response.json())

Response​

{
"data": [
{
"time": 1731617894238,
"pair": "USDT-BTC",
"type": "buy",
"rate": 87740.105,
"amount": 0.0007884042071927771,
"id": 166132,
"cost": 69.17466792153601,
"toCancel": true,
"fees": 0.06917466792153601,
"baseValue": 69.24384258945754,
"costProceed": -69.24384258945754,
"averagePrice": 87827.84510499999,
"pnlPrice": 62265.7632540246,
"balance": 0.0018547712531865415,
"baseBalance": 5199.37490001808,
"inventory_cost": 89053.68482887851,
"ABP": 89885.66715497107,
"pnl": 0
},
{
"time": 1731596553416,
"pair": "USDT-BTC",
"type": "sell",
"rate": 88888.03,
"amount": 0.0005572244556575904,
"id": 448165,
"cost": 49.53058413122556,
"fees": 0.04953058413122556,
"baseValue": 49.481053547094334,
"costProceed": 49.481053547094334,
"averagePrice": 85700.7154144933,
"pnlPrice": 61279.0778096541,
"balance": 0.0010663670459937643,
"baseBalance": 5268.549567939615,
"inventory_cost": 89697.41560740759,
"ABP": 90864.57035248159,
"pnl": 0.17646695031266005
},
{
"time": 1731596480207,
"pair": "USDT-BTC",
"type": "buy",
"rate": 88392.70000000001,
"amount": 0.0005572244556575904,
"id": 826436,
"cost": 49.25457414160469,
"toCancel": true,
"fees": 0.049254574141604696,
"baseValue": 49.3038287157463,
"costProceed": -49.3038287157463,
"averagePrice": 87665.81682479104,
"pnlPrice": 62257.51727031601,
"balance": 0.0016235915016513548,
"baseBalance": 5219.01898380839,
"inventory_cost": 89710.661199906,
"ABP": 90267.99857431499,
"pnl": 0
},
{
"time": 1731595106491,
"pair": "USDT-BTC",
"type": "buy",
"rate": 90399.035,
"amount": 0.000515321047902929,
"id": 613198,
"cost": 46.58452544561356,
"toCancel": true,
"fees": 0.04658452544561356,
"baseValue": 46.631109971059175,
"costProceed": -46.631109971059175,
"averagePrice": 88781.90272859199,
"pnlPrice": 63166.40338265961,
"balance": 0.0010663670459937645,
"baseBalance": 5268.273557949994,
"inventory_cost": 90167.15161602566,
"ABP": 90864.26884252609,
"pnl": 0
}
]
}

/api/v1/orders/day​

  • Method: GET
  • Description: Retrieve orders from the current day for multiple trading pairs and exchanges.

Parameters​

ParameterTypeRequiredDescription
timezonestringYesTimezone identifier (e.g., America/New_York). Must be a valid IANA timezone.
keys[]arrayYesArray of keys in the format exchange/pair (e.g., binance/USDT-XRP). Must be URL-encoded.

Examples​

cURL​

curl -G https://your-gunbot-instance.com:3000/api/v1/orders/day \
-H "Authorization: Bearer YOUR_TOKEN" \
--data-urlencode "timezone=America/New_York" \
--data-urlencode "keys[]=binance/USDT-XRP" \
--data-urlencode "keys[]=mex_gunthy/USDT-DOGE"

JavaScript (fetch API)​

const params = new URLSearchParams({
timezone: 'America/New_York'
});
['binance/USDT-XRP', 'mex_gunthy/USDT-DOGE'].forEach(key => params.append('keys[]', key));

fetch(`https://your-gunbot-instance.com:3000/api/v1/orders/day?${params.toString()}`, {
method: 'GET',
headers: {
'Authorization': 'Bearer YOUR_TOKEN'
}
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));

Python (requests library)​

import requests

url = 'https://your-gunbot-instance.com:3000/api/v1/orders/day'
headers = {
'Authorization': 'Bearer YOUR_TOKEN'
}
params = [
('timezone', 'America/New_York'),
('keys[]', 'binance/USDT-XRP'),
('keys[]', 'mex_gunthy/USDT-DOGE')
]
response = requests.get(url, headers=headers, params=params)
print(response.json())

Response​

{
"days": [],
"orders": [],
"closeOrders": []
}

/api/v1/orders/page​

  • Method: GET
  • Description: Retrieve paginated orders for a specified trading pair on an exchange.

Parameters​

ParameterTypeRequiredDescription
keystringYesCombined exchange and trading pair in the format exchange/pair (e.g., binance/USDT-XRP). Must be URL-encoded.
pagenumberYesPage number starting from 0.
pageSizenumberYesNumber of records per page.

Examples​

cURL​

curl -G https://your-gunbot-instance.com:3000/api/v1/orders/page \
-H "Authorization: Bearer YOUR_TOKEN" \
--data-urlencode "key=binance/USDT-XRP" \
--data-urlencode "page=0" \
--data-urlencode "pageSize=10"

JavaScript (fetch API)​

const params = new URLSearchParams({
key: 'binance/USDT-XRP',
page: '0',
pageSize: '10'
});

fetch(`https://your-gunbot-instance.com:3000/api/v1/orders/page?${params.toString()}`, {
method: 'GET',
headers: {
'Authorization': 'Bearer YOUR_TOKEN'
}
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));

Python (requests library)​

import requests

url = 'https://your-gunbot-instance.com:3000/api/v1/orders/page'
headers = {
'Authorization': 'Bearer YOUR_TOKEN'
}
params = {
'key': 'binance/USDT-XRP',
'page': '0',
'pageSize': '10'
}
response = requests.get(url, headers=headers, params=params)
print(response.json())

Response​

{
"total": 0,
"page": 0,
"data": []
}

/api/v1/orders/page/multi​

  • Method: GET
  • Description: Retrieve paginated orders for multiple trading pairs and exchanges.

Parameters​

ParameterTypeRequiredDescription
keys[]arrayYesArray of keys in the format exchange/pair (e.g., binance/USDT-XRP). Must be URL-encoded.
pagenumberYesPage number starting from 0.
pageSizenumberYesNumber of records per page.

Examples​

cURL​

curl -G https://your-gunbot-instance.com:3000/api/v1/orders/page/multi \
-H "Authorization: Bearer YOUR_TOKEN" \
--data-urlencode "page=0" \
--data-urlencode "pageSize=10" \
--data-urlencode "keys[]=binance/USDT-XRP" \
--data-urlencode "keys[]=mex_gunthy/USDT-DOGE"

JavaScript (fetch API)​

const params = new URLSearchParams({
page: '0',
pageSize: '10'
});
['binance/USDT-XRP', 'mex_gunthy/USDT-DOGE'].forEach(key => params.append('keys[]', key));

fetch(`https://your-gunbot-instance.com:3000/api/v1/orders/page/multi?${params.toString()}`, {
method: 'GET',
headers: {
'Authorization': 'Bearer YOUR_TOKEN'
}
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));

Python (requests library)​

import requests

url = 'https://your-gunbot-instance.com:3000/api/v1/orders/page/multi'
headers = {
'Authorization': 'Bearer YOUR_TOKEN'
}
params = [
('page', '0'),
('pageSize', '10'),
('keys[]', 'binance/USDT-XRP'),
('keys[]', 'mex_gunthy/USDT-DOGE')
]
response = requests.get(url, headers=headers, params=params)
print(response.json())

Response​

{
"total": 0,
"totalCount": 0,
"page": 0,
"data": []
}

Binance Specific Endpoints​

/api/v1/trade/buy/stoplimit​

  • Method: POST
  • Description: Place a stop-limit buy order on Binance. The order will convert to a limit buy order once the stop price is reached.

Parameters​

ParameterTypeRequiredDescription
exchstringYesExchange name (e.g., binance).
pairstringYesTrading pair symbol (e.g., USDT-BTC).
amtnumberYesAmount of the asset to buy.
stopPricenumberYesThe price at which the limit order will be triggered.
limitPricenumberYesThe limit price used once the stop price has been reached.

Examples​

cURL​
curl -X POST https://your-gunbot-instance.com:3000/api/v1/trade/buy/stoplimit \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{
"data": {
"exch": "binance",
"pair": "USDT-BTC",
"amt": 1.0,
"stopPrice": 49900,
"limitPrice": 49850
}
}'
JavaScript (fetch API)​
fetch('https://your-gunbot-instance.com:3000/api/v1/trade/buy/stoplimit', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_TOKEN'
},
body: JSON.stringify({
data: {
exch: 'binance',
pair: 'USDT-BTC',
amt: 1.0,
stopPrice: 49900,
limitPrice: 49850
}
})
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));
Python (requests library)​
import requests

url = 'https://your-gunbot-instance.com:3000/api/v1/trade/buy/stoplimit'
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_TOKEN'
}
data = {
'data': {
'exch': 'binance',
'pair': 'USDT-BTC',
'amt': 1.0,
'stopPrice': 49900,
'limitPrice': 49850
}
}
response = requests.post(url, json=data, headers=headers)
print(response.json())
Response​
{
"status": "success",
"message": "Order sent"
}

/api/v1/trade/sell/stoplimit​

  • Method: POST
  • Description: Place a stop-limit sell order on Binance. The order will convert to a limit sell order once the stop price is reached.

Parameters​

ParameterTypeRequiredDescription
exchstringYesExchange name (e.g., binance).
pairstringYesTrading pair symbol (e.g., USDT-BTC).
amtnumberYesAmount of the asset to sell.
stopPricenumberYesThe price at which the limit order will be triggered.
limitPricenumberYesThe limit price used once the stop price has been reached.

Examples​

cURL​
curl -X POST https://your-gunbot-instance.com:3000/api/v1/trade/sell/stoplimit \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{
"data": {
"exch": "binance",
"pair": "USDT-BTC",
"amt": 1.0,
"stopPrice": 50100,
"limitPrice": 50150
}
}'
JavaScript (fetch API)​
fetch('https://your-gunbot-instance.com:3000/api/v1/trade/sell/stoplimit', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_TOKEN'
},
body: JSON.stringify({
data: {
exch: 'binance',
pair: 'USDT-BTC',
amt: 1.0,
stopPrice: 50100,
limitPrice: 50150
}
})
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));
Python (requests library)​
import requests

url = 'https://your-gunbot-instance.com:3000/api/v1/trade/sell/stoplimit'
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_TOKEN'
}
data = {
'data': {
'exch': 'binance',
'pair': 'USDT-BTC',
'amt': 1.0,
'stopPrice': 50100,
'limitPrice': 50150
}
}
response = requests.post(url, json=data, headers=headers)
print(response.json())
Response​
{
"status": "success",
"message": "Order sent"
}

/api/v1/trade/buy/trailingstop​

  • Method: POST
  • Description: Place a trailing stop buy order on Binance. This adjusts the stop price automatically as the market moves, attempting to buy as the price recovers after a drop.

Parameters​

ParameterTypeRequiredDescription
exchstringYesExchange name (e.g., binance).
pairstringYesTrading pair symbol (e.g., USDT-BTC).
amtnumberYesAmount of the asset to buy.
pricenumberYesReference price for the order.
stopPricenumberYesTrailing stop price.

Examples​

cURL​
curl -X POST https://your-gunbot-instance.com:3000/api/v1/trade/buy/trailingstop \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{
"data": {
"exch": "binance",
"pair": "USDT-BTC",
"amt": 1.0,
"price": 50000,
"stopPrice": 49900
}
}'
JavaScript (fetch API)​
fetch('https://your-gunbot-instance.com:3000/api/v1/trade/buy/trailingstop', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_TOKEN'
},
body: JSON.stringify({
data: {
exch: 'binance',
pair: 'USDT-BTC',
amt: 1.0,
price: 50000,
stopPrice: 49900
}
})
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));
Python (requests library)​
import requests

url = 'https://your-gunbot-instance.com:3000/api/v1/trade/buy/trailingstop'
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_TOKEN'
}
data = {
'data': {
'exch': 'binance',
'pair': 'USDT-BTC',
'amt': 1.0,
'price': 50000,
'stopPrice': 49900
}
}
response = requests.post(url, json=data, headers=headers)
print(response.json())
Response​
{
"status": "success",
"message": "Order sent"
}

/api/v1/trade/sell/trailingstop​

  • Method: POST
  • Description: Place a trailing stop sell order on Binance. This adjusts the stop price automatically as the market moves, attempting to sell as the price declines after a rise.

Parameters​

ParameterTypeRequiredDescription
exchstringYesExchange name (e.g., binance).
pairstringYesTrading pair symbol (e.g., USDT-BTC).
amtnumberYesAmount of the asset to sell.
pricenumberYesReference price for the order.
stopPricenumberYesTrailing stop price.

Examples​

cURL​
curl -X POST https://your-gunbot-instance.com:3000/api/v1/trade/sell/trailingstop \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{
"data": {
"exch": "binance",
"pair": "USDT-BTC",
"amt": 1.0,
"price": 52500,
"stopPrice": 52550
}
}'
JavaScript (fetch API)​
fetch('https://your-gunbot-instance.com:3000/api/v1/trade/sell/trailingstop', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_TOKEN'
},
body: JSON.stringify({
data: {
exch: 'binance',
pair: 'USDT-BTC',
amt: 1.0,
price: 52500,
stopPrice: 52550
}
})
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));
Python (requests library)​
import requests

url = 'https://your-gunbot-instance.com:3000/api/v1/trade/sell/trailingstop'
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_TOKEN'
}
data = {
'data': {
'exch': 'binance',
'pair': 'USDT-BTC',
'amt': 1.0,
'price': 52500,
'stopPrice': 52550
}
}
response = requests.post(url, json=data, headers=headers)
print(response.json())
Response​
{
"status": "success",
"message": "Order sent"
}

/api/v1/trade/buy/oco​

  • Method: POST
  • Description: Place a one-cancels-the-other (OCO) buy order on Binance. This places a limit order and a stop-limit order simultaneously. If one order executes fully or partially, the other is automatically canceled.

Parameters​

ParameterTypeRequiredDescription
exchstringYesExchange name (e.g., binance).
pairstringYesTrading pair symbol (e.g., USDT-BTC).
amtnumberYesAmount of the asset to buy.
pricenumberYesLimit price for the OCO order.
stopPricenumberYesStop price for the stop-limit part.
limitnumberYesLimit price used after the stop is triggered.

Examples​

cURL​
curl -X POST https://your-gunbot-instance.com:3000/api/v1/trade/buy/oco \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{
"data": {
"exch": "binance",
"pair": "USDT-BTC",
"amt": 1.0,
"price": 50000,
"stopPrice": 49900,
"limit": 49850
}
}'
JavaScript (fetch API)​
fetch('https://your-gunbot-instance.com:3000/api/v1/trade/buy/oco', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_TOKEN'
},
body: JSON.stringify({
data: {
exch: 'binance',
pair: 'USDT-BTC',
amt: 1.0,
price: 50000,
stopPrice: 49900,
limit: 49850
}
})
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));
Python (requests library)​
import requests

url = 'https://your-gunbot-instance.com:3000/api/v1/trade/buy/oco'
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_TOKEN'
}
data = {
'data': {
'exch': 'binance',
'pair': 'USDT-BTC',
'amt': 1.0,
'price': 50000,
'stopPrice': 49900,
'limit': 49850
}
}
response = requests.post(url, json=data, headers=headers)
print(response.json())
Response​
{
"status": "success",
"message": "Order sent"
}

/api/v1/trade/sell/oco​

  • Method: POST
  • Description: Place a one-cancels-the-other (OCO) sell order on Binance. This places a limit order and a stop-limit order simultaneously. If one order executes fully or partially, the other is automatically canceled.

Parameters​

ParameterTypeRequiredDescription
exchstringYesExchange name (e.g., binance).
pairstringYesTrading pair symbol (e.g., USDT-BTC).
amtnumberYesAmount of the asset to sell.
pricenumberYesLimit price for the OCO order.
stopPricenumberYesStop price for the stop-limit part.
limitnumberYesLimit price used after the stop is triggered.

Examples​

cURL​
curl -X POST https://your-gunbot-instance.com:3000/api/v1/trade/sell/oco \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{
"data": {
"exch": "binance",
"pair": "USDT-BTC",
"amt": 1.0,
"price": 52500,
"stopPrice": 52550,
"limit": 52600
}
}'
JavaScript (fetch API)​
fetch('https://your-gunbot-instance.com:3000/api/v1/trade/sell/oco', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_TOKEN'
},
body: JSON.stringify({
data: {
exch: 'binance',
pair: 'USDT-BTC',
amt: 1.0,
price: 52500,
stopPrice: 52550,
limit: 52600
}
})
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));
Python (requests library)​
import requests

url = 'https://your-gunbot-instance.com:3000/api/v1/trade/sell/oco'
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_TOKEN'
}
data = {
'data': {
'exch': 'binance',
'pair': 'USDT-BTC',
'amt': 1.0,
'price': 52500,
'stopPrice': 52550,
'limit': 52600
}
}
response = requests.post(url, json=data, headers=headers)
print(response.json())
Response​
{
"status": "success",
"message": "Order sent"
}

Bybit Specific Endpoints​

/api/v1/trade/close​

  • Method: POST
  • Description: Close an open position at a specified limit price on Bybit (futures).

Parameters​

ParameterTypeRequiredDescription
exchstringYesExchange name (e.g., bybit).
pairstringYesTrading pair symbol (e.g., USDT-BTC-LONG).
amtnumberYesAmount of the asset to close.
pricenumberYesLimit price at which to close the position.

Examples​

cURL​
curl -X POST https://your-gunbot-instance.com:3000/api/v1/trade/close \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{
"data": {
"exch": "bybit",
"pair": "USDT-BTC-LONG",
"amt": 1.0,
"price": 51000
}
}'
JavaScript (fetch API)​
fetch('https://your-gunbot-instance.com:3000/api/v1/trade/close', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_TOKEN'
},
body: JSON.stringify({
data: {
exch: 'bybit',
pair: 'USDT-BTC-LONG',
amt: 1.0,
price: 51000
}
})
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));
Python (requests library)​
import requests

url = 'https://your-gunbot-instance.com:3000/api/v1/trade/close'
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_TOKEN'
}
data = {
'data': {
'exch': 'bybit',
'pair': 'USDT-BTC-LONG',
'amt': 1.0,
'price': 51000
}
}
response = requests.post(url, json=data, headers=headers)
print(response.json())
Response​
{
"status": "success",
"message": "Order sent"
}

/api/v1/trade/close/market​

  • Method: POST
  • Description: Close an open position at the current market price on Bybit (futures).

Parameters​

ParameterTypeRequiredDescription
exchstringYesExchange name (e.g., bybit).
pairstringYesTrading pair symbol (e.g., USDT-BTC-LONG).
amtnumberYesAmount of the asset to close.

Examples​

cURL​
curl -X POST https://your-gunbot-instance.com:3000/api/v1/trade/close/market \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{
"data": {
"exch": "bybit",
"pair": "USDT-BTC-LONG",
"amt": 1.0
}
}'
JavaScript (fetch API)​
fetch('https://your-gunbot-instance.com:3000/api/v1/trade/close/market', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_TOKEN'
},
body: JSON.stringify({
data: {
exch: 'bybit',
pair: 'USDT-BTC-LONG',
amt: 1.0
}
})
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));
Python (requests library)​
import requests

url = 'https://your-gunbot-instance.com:3000/api/v1/trade/close/market'
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_TOKEN'
}
data = {
'data': {
'exch': 'bybit',
'pair': 'USDT-BTC-LONG',
'amt': 1.0
}
}
response = requests.post(url, json=data, headers=headers)
print(response.json())
Response​
{
"status": "success",
"message": "Order sent"
}