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​
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​
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 | No | Optional 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​
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 sell. |
price | number | Yes | Limit 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​
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 sell. |
price | number | No | Optional 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​
Parameter | Type | Required | Description |
---|---|---|---|
exch | string | Yes | Exchange name (e.g., binance ). |
pair | string | Yes | Trading pair symbol (e.g., USDT-BTC ). |
id | string | Yes | Order ID of the order to cancel. |
price | number | Yes | Price at which the order was placed. |
type | string | Yes | Order 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​
Parameter | Type | Required | Description |
---|---|---|---|
key | string | Yes | Combined 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​
Parameter | Type | Required | Description |
---|---|---|---|
timezone | string | Yes | Timezone identifier (e.g., America/New_York ). Must be a valid IANA timezone. |
keys[] | array | Yes | Array 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​
Parameter | Type | Required | Description |
---|---|---|---|
key | string | Yes | Combined exchange and trading pair in the format exchange/pair (e.g., binance/USDT-XRP ). Must be URL-encoded. |
page | number | Yes | Page number starting from 0. |
pageSize | number | Yes | Number 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​
Parameter | Type | Required | Description |
---|---|---|---|
keys[] | array | Yes | Array of keys in the format exchange/pair (e.g., binance/USDT-XRP ). Must be URL-encoded. |
page | number | Yes | Page number starting from 0. |
pageSize | number | Yes | Number 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​
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. |
stopPrice | number | Yes | The price at which the limit order will be triggered. |
limitPrice | number | Yes | The 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​
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 sell. |
stopPrice | number | Yes | The price at which the limit order will be triggered. |
limitPrice | number | Yes | The 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​
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 | Reference price for the order. |
stopPrice | number | Yes | Trailing 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​
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 sell. |
price | number | Yes | Reference price for the order. |
stopPrice | number | Yes | Trailing 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​
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 for the OCO order. |
stopPrice | number | Yes | Stop price for the stop-limit part. |
limit | number | Yes | Limit 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​
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 sell. |
price | number | Yes | Limit price for the OCO order. |
stopPrice | number | Yes | Stop price for the stop-limit part. |
limit | number | Yes | Limit 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​
Parameter | Type | Required | Description |
---|---|---|---|
exch | string | Yes | Exchange name (e.g., bybit ). |
pair | string | Yes | Trading pair symbol (e.g., USDT-BTC-LONG ). |
amt | number | Yes | Amount of the asset to close. |
price | number | Yes | Limit 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​
Parameter | Type | Required | Description |
---|---|---|---|
exch | string | Yes | Exchange name (e.g., bybit ). |
pair | string | Yes | Trading pair symbol (e.g., USDT-BTC-LONG ). |
amt | number | Yes | Amount 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"
}