Skip to content

Execution Module - Rest API

Alternative API documentation

To use different API documentation styles, please check it from any of the below available options

Using this style, can able to invoke the api right away from browser for testing purposes


Section Description
EndPoint Connection EndPoint details
Broker Accounts Management Manage Broker accounts on Quantsapp
Order Management Manage Orders on Broker accounts
Position Management Manage Positions on Broker accounts
Broker Websocket Management Manage Orders on Broker accounts

Base Endpoint

https://tradeapi.quantsapp.com/v1

HTTP/1, HTTP/2 & HTTP/3 are supported on the endpoint. Based on your performance requirement, specific HTTP protocol can be used

Headers

The below headers needs to be sent on all requests

Name Description
X-API-Token Authentication Token to be sent on all requests 1
X-Mac-Address MAC address of connected network device, which is required by some brokers 2

API Health Check

Type Endpoint Query Params Body
GET /ping
Sample Code
Bash
curl -X 'GET' 'https://tradeapi.quantsapp.com/v1/ping'
Bash
curl --http2 -X 'GET' 'https://tradeapi.quantsapp.com/v1/ping'
Bash
curl --http3 -X 'GET' 'https://tradeapi.quantsapp.com/v1/ping'
Python
import httpx  # (1)!

client = httpx.Client()

r = client.get(
    url='https://tradeapi.quantsapp.com/v1/ping',
)

print(r)
# <Response [200 OK]>

print(r.http_version)
# HTTP/1.1

print(r.text)
# "HTTP 200 OK: 'Found my happy place. It's here, responding to you.'"
  1. pip install httpx
Python
import httpx  # (1)!

client = httpx.Client(http2=True)

r = client.get(
    url='https://tradeapi.quantsapp.com/v1/ping'
)

print(r)
# <Response [200 OK]>

print(r.http_version)
# HTTP/2

print(r.text)
# "HTTP 200 OK: 'Found my happy place. It's here, responding to you.'"
  1. pip install httpx[http2]
Python
if __name__ == "__main__":
    r = asyncio.run(
        quantsapp_http3_request(  # (1)!
            url='https://tradeapi.quantsapp.com/v1/ping',
            method='GET',
        )
    )

    print(r)
    # <Response [200 OK]>

    print(r.http_version)
    # HTTP/3

    print(r.text)
    # "HTTP 200 OK: 'Found my happy place. It's here, responding to you.'"
  1. Use custom function quantsapp_http3_request 3

Response

200 HTTP Code

["HTTP 200 OK: 'Net positive health check. My vitals are soaring like the stock market!'"]

4XX HTTP code

Returned with proper response message


Broker Accounts Management

Section Description
List Mapped Broker List Mapped Broker accounts to Quantsapp
Add Broker Add Broker account to Quantsapp Account
Delete Broker Delete Broker account from Quantsapp Account

List Mapped Brokers

Type Endpoint Query Params Body
GET /broker/mapped_accounts

Query Params

Name Description Default Allowed Values
revalidate
bool
On true will Revalidate all mapped broker accounts token if expiried false bool
Sample Code
Bash
curl -X 'GET' \
    'https://tradeapi.quantsapp.com/v1/broker/mapped_accounts?revalidate=false' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: <MAC_ADDRESS>' \
    -H 'X-API-Token: <JWT_TOKEN>'
Bash
curl --http2 -X 'GET' \
    'https://tradeapi.quantsapp.com/v1/broker/mapped_accounts?revalidate=false' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: <MAC_ADDRESS>' \
    -H 'X-API-Token: <JWT_TOKEN>'
Bash
curl --http3 -X 'GET' \
    'https://tradeapi.quantsapp.com/v1/broker/mapped_accounts?revalidate=false' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: <MAC_ADDRESS>' \
    -H 'X-API-Token: <JWT_TOKEN>'
Python
import httpx  # (1)!

client = httpx.Client()

r = client.get(
    url='https://tradeapi.quantsapp.com/v1/broker/mapped_accounts',
    headers={
        'X-API-Token': '<JWT_TOKEN>',
        'X-Mac-Address': '<MAC_ADDRESS>',
    },
    params={
        'revalidate': False,
    },
)

print(r)
# <Response [200 OK]>

print(r.http_version)
# HTTP/1.1

print(r.json())
  1. pip install httpx
Python
import httpx  # (1)!

client = httpx.Client(http2=True)

r = client.get(
    url='https://tradeapi.quantsapp.com/v1/broker/mapped_accounts',
    headers={
        'X-API-Token': '<JWT_TOKEN>',
        'X-Mac-Address': '<MAC_ADDRESS>',
    },
    params={
        'revalidate': False,
    },
)

print(r)
# <Response [200 OK]>

print(r.http_version)
# HTTP/2

print(r.json())
  1. pip install httpx[http2]
Python
if __name__ == "__main__":
    r = asyncio.run(
        quantsapp_http3_request(  # (1)!
            url='https://tradeapi.quantsapp.com/v1/broker/mapped_accounts',
            method='GET',
        )
    )

    print(r)
    # <Response [200 OK]>

    print(r.http_version)
    # HTTP/3

    print(r.json())
  1. Use custom function quantsapp_http3_request 3

Response

200 HTTP Code

JSON
{
    # Only available if accounts are mapped
    "data": [
        {
           "broker": "fivepaisa",
            "client_id": "51372260",
            "role": "executor",
            "name": "NAME",
            "validity": "02-May-25 23:59:59",
            "valid": true,
            "margin": {
                "dt": "02-May-25 02:18:50",
                "NSE-FO": "1534.53"
            }
        },
    ],
    "version": "9",
    "next_margin_dt_utc": "02-May-25 02:33:50",
}

4XX HTTP code

Returned with proper response message

Add Broker

Type Endpoint Query Params Body
POST /broker/add_broker

Body

Name Description Default Allowed Values
broker
str
Broker to be added required Broker
delete_previous_users
bool
Whether to delete previous added users required bool
update_owner
bool
Whether to update current user as owner required bool
login_type
str
Login Mode required totp
credentials
dict
Broker Login Credentials to Login required Broker Credentials
Sample Payload
Bash
curl -X 'POST' \
    'https://tradeapi.quantsapp.com/v1/broker/add_broker' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: asd' \
    -H 'X-API-Token: asd' \
    -H 'Content-Type: application/json' \
    -d '{
        "broker": "choice",
        "delete_previous_users": false,
        "update_owner": false,
        "credentials": {
            "access_token": "YOUR_DHAN_ACCESS_TOKEN_HERE"
        }
    }'
Bash
curl -X 'POST' \
    'https://tradeapi.quantsapp.com/v1/broker/add_broker' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: asd' \
    -H 'X-API-Token: asd' \
    -H 'Content-Type: application/json' \
    -d '{
        "broker": "choice",
        "delete_previous_users": false,
        "update_owner": false,
        "credentials": {
            "mobile": "YOUR_MOBILE_NUMBER_HERE",
            "client_access_token": "YOUR_CHOICE_CLIENT_ACCESS_TOKEN_HERE"
        },
    }'
Bash
curl -X --http2 'POST' \
    'https://tradeapi.quantsapp.com/v1/broker/add_broker' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: asd' \
    -H 'X-API-Token: asd' \
    -H 'Content-Type: application/json' \
    -d '{
        "broker": "choice",
        "delete_previous_users": false,
        "update_owner": false,
        "credentials": {
            "access_token": "YOUR_DHAN_ACCESS_TOKEN_HERE"
        }
    }'
Bash
curl -X --http2 'POST' \
    'https://tradeapi.quantsapp.com/v1/broker/add_broker' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: asd' \
    -H 'X-API-Token: asd' \
    -H 'Content-Type: application/json' \
    -d '{
        "broker": "choice",
        "delete_previous_users": false,
        "update_owner": false,
        "credentials": {
            "mobile": "YOUR_MOBILE_NUMBER_HERE",
            "client_access_token": "YOUR_CHOICE_CLIENT_ACCESS_TOKEN_HERE"
        },
    }'
Bash
curl -X --http3 'POST' \
    'https://tradeapi.quantsapp.com/v1/broker/add_broker' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: asd' \
    -H 'X-API-Token: asd' \
    -H 'Content-Type: application/json' \
    -d '{
        "broker": "choice",
        "delete_previous_users": false,
        "update_owner": false,
        "credentials": {
            "access_token": "YOUR_DHAN_ACCESS_TOKEN_HERE"
        }
    }'
Bash
curl -X --http3 'POST' \
    'https://tradeapi.quantsapp.com/v1/broker/add_broker' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: asd' \
    -H 'X-API-Token: asd' \
    -H 'Content-Type: application/json' \
    -d '{
        "broker": "choice",
        "delete_previous_users": false,
        "update_owner": false,
        "credentials": {
            "mobile": "YOUR_MOBILE_NUMBER_HERE",
            "client_access_token": "YOUR_CHOICE_CLIENT_ACCESS_TOKEN_HERE"
        },
    }'
Python
import httpx  # (1)!

client = httpx.Client()

r = client.post(
    url='https://tradeapi.quantsapp.com/v1/broker/add_broker',
    headers={
        'X-API-Token': '<JWT_TOKEN>',
        'X-Mac-Address': '<MAC_ADDRESS>',
    },
    data={
        'broker': 'choice',
        'delete_previous_users': false,
        'update_owner': false,
        'credentials': {
            'access_token': 'YOUR_DHAN_ACCESS_TOKEN_HERE',
        },
    }
)

print(r)
# <Response [200 OK]>

print(r.http_version)
# HTTP/1.1

print(r.json())
  1. pip install httpx
Python
import httpx  # (1)!

client = httpx.Client()

r = client.post(
    url='https://tradeapi.quantsapp.com/v1/broker/add_broker',
    headers={
        'X-API-Token': '<JWT_TOKEN>',
        'X-Mac-Address': '<MAC_ADDRESS>',
    },
    data={
        'broker': 'choice',
        'delete_previous_users': false,
        'update_owner': false,
        'credentials': {
            'mobile': 'YOUR_MOBILE_NUMBER_HERE',
            'client_access_token': 'YOUR_CHOICE_CLIENT_ACCESS_TOKEN_HERE'
        },
    }
)

print(r)
# <Response [200 OK]>

print(r.http_version)
# HTTP/1.1

print(r.json())
  1. pip install httpx
Python
import httpx  # (1)!

client = httpx.Client(http2=True)

r = client.post(
    url='https://tradeapi.quantsapp.com/v1/broker/add_broker',
    headers={
        'X-API-Token': '<JWT_TOKEN>',
        'X-Mac-Address': '<MAC_ADDRESS>',
    },
    data={
        'broker': 'choice',
        'delete_previous_users': false,
        'update_owner': false,
        'credentials': {
            'access_token': 'YOUR_DHAN_ACCESS_TOKEN_HERE',
        },
    }
)

print(r)
# <Response [200 OK]>

print(r.http_version)
# HTTP/1.1

print(r.json())
  1. pip install httpx[http2]
Python
import httpx  # (1)!

client = httpx.Client(http2=True)

r = client.post(
    url='https://tradeapi.quantsapp.com/v1/broker/add_broker',
    headers={
        'X-API-Token': '<JWT_TOKEN>',
        'X-Mac-Address': '<MAC_ADDRESS>',
    },
    data={
        'broker': 'choice',
        'delete_previous_users': false,
        'update_owner': false,
        'credentials': {
            'mobile': 'YOUR_MOBILE_NUMBER_HERE',
            'client_access_token': 'YOUR_CHOICE_CLIENT_ACCESS_TOKEN_HERE'
        },
    }
)

print(r)
# <Response [200 OK]>

print(r.http_version)
# HTTP/1.1

print(r.json())
  1. pip install httpx[http2]
Python
if __name__ == "__main__":
    r = asyncio.run(
        quantsapp_http3_request(  # (1)!
            url='https://tradeapi.quantsapp.com/v1/broker/add_broker',
            method='POST',
            headers={
                'X-API-Token': '<JWT_TOKEN>',
                'X-Mac-Address': '<MAC_ADDRESS>',
            },
            data={
                'broker': 'choice',
                'delete_previous_users': false,
                'update_owner': false,
                'credentials': {
                    'access_token': 'YOUR_DHAN_ACCESS_TOKEN_HERE',
                },
            }
        )
    )

    print(r)
    # <Response [200 OK]>

    print(r.http_version)
    # HTTP/3

    print(r.json())
  1. Use custom function quantsapp_http3_request 3
Python
if __name__ == "__main__":
    r = asyncio.run(
        quantsapp_http3_request(  # (1)!
            url='https://tradeapi.quantsapp.com/v1/broker/add_broker',
            method='POST',
            headers={
                'X-API-Token': '<JWT_TOKEN>',
                'X-Mac-Address': '<MAC_ADDRESS>',
            },
            data={
                'broker': 'choice',
                'delete_previous_users': false,
                'update_owner': false,
                'credentials': {
                    'mobile': 'YOUR_MOBILE_NUMBER_HERE',
                    'client_access_token': 'YOUR_CHOICE_CLIENT_ACCESS_TOKEN_HERE'
                },
            }
        )
    )

    print(r)
    # <Response [200 OK]>

    print(r.http_version)
    # HTTP/3

    print(r.json())
  1. Use custom function quantsapp_http3_request 3

Response

200 HTTP Code

JSON
{
    "msg": "success",
}

4XX HTTP code

Returned with proper response message

Delete Broker

Type Endpoint Query Params Body
DELETE /broker/delete_broker

Query Params

Name Description Default Allowed Values
broker
str
Broker to be deleted required Broker
client_id
str
Client ID of Broker Account required str
Sample Code
Bash
curl -X 'DELETE' \
    'https://tradeapi.quantsapp.com/v1/broker/delete_broker?broker=choice&client_id=123' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: <MAC_ADDRESS>' \
    -H 'X-API-Token: <JWT_TOKEN>'
Bash
curl --http2 -X 'DELETE' \
    'https://tradeapi.quantsapp.com/v1/broker/delete_broker?broker=choice&client_id=123' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: <MAC_ADDRESS>' \
    -H 'X-API-Token: <JWT_TOKEN>'
Bash
curl --http3 -X 'DELETE' \
    'https://tradeapi.quantsapp.com/v1/broker/delete_broker?broker=choice&client_id=123' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: <MAC_ADDRESS>' \
    -H 'X-API-Token: <JWT_TOKEN>'
Python
import httpx  # (1)!

client = httpx.Client()

r = client.delete(
    url='https://tradeapi.quantsapp.com/v1/broker/delete_broker',
    headers={
        'X-API-Token': '<JWT_TOKEN>',
        'X-Mac-Address': '<MAC_ADDRESS>',
    },
    params={
        'broker': 'choice',
        'client_id': '123',
    },
)

print(r)
# <Response [200 OK]>

print(r.http_version)
# HTTP/1.1

print(r.json())
  1. pip install httpx
Python
import httpx  # (1)!

client = httpx.Client(http2=True)

r = client.delete(
    url='https://tradeapi.quantsapp.com/v1/broker/delete_broker',
    headers={
        'X-API-Token': '<JWT_TOKEN>',
        'X-Mac-Address': '<MAC_ADDRESS>',
    },
    params={
        'broker': 'choice',
        'client_id': '123',
    },
)

print(r)
# <Response [200 OK]>

print(r.http_version)
# HTTP/2

print(r.json())
  1. pip install httpx[http2]
Python
if __name__ == "__main__":
    r = asyncio.run(
        quantsapp_http3_request(  # (1)!
            url='https://tradeapi.quantsapp.com/v1/broker/delete_broker',
            method='DELETE',
            headers={
                'X-API-Token': '<JWT_TOKEN>',
                'X-Mac-Address': '<MAC_ADDRESS>',
            },
            params={
                'broker': 'choice',
                'client_id': '123',
            },
        )
    )

    print(r)
    # <Response [200 OK]>

    print(r.http_version)
    # HTTP/3

    print(r.json())
  1. Use custom function quantsapp_http3_request 3

Response

200 HTTP Code

JSON
{
    "msg": "success",
}

4XX HTTP code

Returned with proper response message


Order Management

Section Description
Get OrderBook Get OrderBook data
Get My OrderBook Get My OrderBook data
Get OrderBook by OrderIDs Get OrderBook data by OrderIDs
Place Order Placing order on Broker Accounts
Modify Order Modify order on Broker Accounts
Cancel Order Cancel orders on multiple Broker accounts
Cancel All Order Cancel all orders on specific Broker account

Get Order Book

Type Endpoint Query Params Body
GET /order/order_book

Query Params

Name Description Default Allowed Values
broker
str
Broker to be added required Broker
client_id
str
Client ID of Broker Account required str
Sample Code
Bash
curl -X 'GET' \
    'https://tradeapi.quantsapp.com/v1/order/order_book?broker=choice&client_id=123' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: <MAC_ADDRESS>' \
    -H 'X-API-Token: <JWT_TOKEN>'
Bash
curl --http2 -X 'GET' \
    'https://tradeapi.quantsapp.com/v1/order/order_book?broker=choice&client_id=123' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: <MAC_ADDRESS>' \
    -H 'X-API-Token: <JWT_TOKEN>'
Bash
curl --http3 -X 'GET' \
    'https://tradeapi.quantsapp.com/v1/order/order_book?broker=choice&client_id=123' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: <MAC_ADDRESS>' \
    -H 'X-API-Token: <JWT_TOKEN>'
Python
import httpx  # (1)!

client = httpx.Client()

r = client.get(
    url='https://tradeapi.quantsapp.com/v1/order/order_book',
    headers={
        'X-API-Token': '<JWT_TOKEN>',
        'X-Mac-Address': '<MAC_ADDRESS>',
    },
    params={
        'broker': 'choice',
        'client_id': '123,
    },
)

print(r)
# <Response [200 OK]>

print(r.http_version)
# HTTP/1.1

print(r.json())
  1. pip install httpx
Python
import httpx  # (1)!

client = httpx.Client(http2=True)

r = client.get(
    url='https://tradeapi.quantsapp.com/v1/order/order_book',
    headers={
        'X-API-Token': '<JWT_TOKEN>',
        'X-Mac-Address': '<MAC_ADDRESS>',
    },
    params={
        'broker': 'choice',
        'client_id': '123,
    },
)

print(r)
# <Response [200 OK]>

print(r.http_version)
# HTTP/2

print(r.json())
  1. pip install httpx[http2]
Python
if __name__ == "__main__":
    r = asyncio.run(
        quantsapp_http3_request(  # (1)!
            url='https://tradeapi.quantsapp.com/v1/order/order_book',
            method='GET',
            headers={
                'X-API-Token': '<JWT_TOKEN>',
                'X-Mac-Address': '<MAC_ADDRESS>',
            },
            params={
                'broker': 'choice',
                'client_id': '123,
            },
        )
    )

    print(r)
    # <Response [200 OK]>

    print(r.http_version)
    # HTTP/3

    print(r.json())
  1. Use custom function quantsapp_http3_request 3

Response

200 HTTP Code

Gzip Compressed Response
{
    "gzip": true,
    "orders": "H4sIAPONSWgC/02Qu27EIBBFf2VFvbvCPG13aSKl2FRpoihCNiYRWvwIDIUV5d/D2MlqqWDunTPDffsmfZyvLhobvJuAtAcyJpjt9Xh5qBhnjHNyPJDezHFw0Q9o4FwwJmVNNed1hfIXrEXQslyX6K0rj+rMsC+vJrkQsK1Hp58SxDz+jXp+enx5bSt5unTricnWtoVLKRq3eQbWBWEk+NED2fDzkC3chCmOYdvA5OQsztVCyUZx1WgtheBFK8q+uSprN+IGT9BBTkhZ3DT46XP/KYJMXoYO3B1P0/0Ui7sLo1J7WctaaEUbhBsLEaU9GPPhQ3Doxd6S7WL+M6Jn+vP+C9F3KnODAQAA",
}

If gzip is true, then decode the orders data with below logic

orders decompress logic
Python
import json, gzip, base64

def decompress_gzip_json_data(orders_data: str) -> list | dict:
    return json.loads(gzip.decompress(base64.b64decode(orders_data)))
JavaScript
// For Node.js environments
const pako = require('pako');  // npm install pako

/**
* Decompresses Base64-encoded, gzipped JSON data.
*
* @param {string} orders_data - The Base64-encoded, gzipped string.
* @returns {Array | Object} The decompressed JSON data.
* @throws {Error} If decompression or JSON parsing fails.
*/
function decompressGzipJsonData(orders_data) {
try {
    // 1. Base64 decode the string
    const decoded = Buffer.from(orders_data, 'base64');

    // 2. Gzip decompress the decoded buffer
    // pako.inflate returns a Uint8Array, which we convert to a Buffer for consistency
    const decompressed = Buffer.from(pako.inflate(decoded));

    // 3. Parse the decompressed data as JSON
    const jsonData = JSON.parse(decompressed.toString('utf8'));

    return jsonData;
} catch (error) {
    console.error("Error decompressing or parsing data:", error);
    throw error; // Re-throw the error for the caller to handle
}
}

// --- Example Usage (Node.js) ---
const compressed_data = "H4sIAPONSWgC/02Qu27EIBBFf2VFvbvCPG13aSKl2FRpoihCNiYRWvwIDIUV5d/D2MlqqWDunTPDffsmfZyvLhobvJuAtAcyJpjt9Xh5qBhnjHNyPJDezHFw0Q9o4FwwJmVNNed1hfIXrEXQslyX6K0rj+rMsC+vJrkQsK1Hp58SxDz+jXp+enx5bSt5unTricnWtoVLKRq3eQbWBWEk+NED2fDzkC3chCmOYdvA5OQsztVCyUZx1WgtheBFK8q+uSprN+IGT9BBTkhZ3DT46XP/KYJMXoYO3B1P0/0Ui7sLo1J7WctaaEUbhBsLEaU9GPPhQ3Doxd6S7WL+M6Jn+vP+C9F3KnODAQAA";

try {
  const decompressedResult = decompressGzipJsonData(python_compressed_data);
  console.log("Decompressed Data:", decompressedResult);
} catch (e) {
   // Handle error
}
Decompressed 'orders' data
[
    {
        "broker_client": "mstock,MA1232233",
        "b_orderid": "33422558073381",
        "qty": 75,
        "price": 1.2,
        "buy_sell": "b",
        "instrument": "NIFTY:15-May-25:c:25500",
        "order_type": "limit",
        "product_type": "nrml",
        "q_usec": 1746596369775443,
        "userid": 622594,
        "order_status": "pending",
        "b_usec_update": 1746596370000000,
        "e_orderid": 1600000075847609,
        "o_ctr": 1,
        "qty_filled": 0,
        "stop_price": 0.0
    }
]

4XX HTTP code

Returned with proper response message

Get My Order Book

Type Endpoint Query Params Body
GET /order/my_order_book
Sample Code
Bash
curl -X 'GET' \
    'https://tradeapi.quantsapp.com/v1/order/my_order_book' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: <MAC_ADDRESS>' \
    -H 'X-API-Token: <JWT_TOKEN>'
Bash
curl --http2 -X 'GET' \
    'https://tradeapi.quantsapp.com/v1/order/my_order_book' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: <MAC_ADDRESS>' \
    -H 'X-API-Token: <JWT_TOKEN>'
Bash
curl --http3 -X 'GET' \
    'https://tradeapi.quantsapp.com/v1/order/my_order_book' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: <MAC_ADDRESS>' \
    -H 'X-API-Token: <JWT_TOKEN>'
Python
import httpx  # (1)!

client = httpx.Client()

r = client.get(
    url='https://tradeapi.quantsapp.com/v1/order/my_order_book',
    headers={
        'X-API-Token': '<JWT_TOKEN>',
        'X-Mac-Address': '<MAC_ADDRESS>',
    },
)

print(r)
# <Response [200 OK]>

print(r.http_version)
# HTTP/1.1

print(r.json())
  1. pip install httpx
Python
import httpx  # (1)!

client = httpx.Client(http2=True)

r = client.get(
    url='https://tradeapi.quantsapp.com/v1/order/my_order_book',
    headers={
        'X-API-Token': '<JWT_TOKEN>',
        'X-Mac-Address': '<MAC_ADDRESS>',
    },
)

print(r)
# <Response [200 OK]>

print(r.http_version)
# HTTP/2

print(r.json())
  1. pip install httpx[http2]
Python
if __name__ == "__main__":
    r = asyncio.run(
        quantsapp_http3_request(  # (1)!
            url='https://tradeapi.quantsapp.com/v1/order/my_order_book',
            method='GET',
            headers={
                'X-API-Token': '<JWT_TOKEN>',
                'X-Mac-Address': '<MAC_ADDRESS>',
            },
        )
    )

    print(r)
    # <Response [200 OK]>

    print(r.http_version)
    # HTTP/3

    print(r.json())
  1. Use custom function quantsapp_http3_request 3

Response

200 HTTP Code

Gzip Compressed Response
{
    "gzip": true,
    "orders": "H4sIAPONSWgC/02Qu27EIBBFf2VFvbvCPG13aSKl2FRpoihCNiYRWvwIDIUV5d/D2MlqqWDunTPDffsmfZyvLhobvJuAtAcyJpjt9Xh5qBhnjHNyPJDezHFw0Q9o4FwwJmVNNed1hfIXrEXQslyX6K0rj+rMsC+vJrkQsK1Hp58SxDz+jXp+enx5bSt5unTricnWtoVLKRq3eQbWBWEk+NED2fDzkC3chCmOYdvA5OQsztVCyUZx1WgtheBFK8q+uSprN+IGT9BBTkhZ3DT46XP/KYJMXoYO3B1P0/0Ui7sLo1J7WctaaEUbhBsLEaU9GPPhQ3Doxd6S7WL+M6Jn+vP+C9F3KnODAQAA",
}

If gzip is true, then decode the orders data with below logic

orders decompress logic
Python
import json, gzip, base64

def decompress_gzip_json_data(orders_data: str) -> list | dict:
    return json.loads(gzip.decompress(base64.b64decode(orders_data)))
JavaScript
// For Node.js environments
const pako = require('pako');  // npm install pako

/**
* Decompresses Base64-encoded, gzipped JSON data.
*
* @param {string} orders_data - The Base64-encoded, gzipped string.
* @returns {Array | Object} The decompressed JSON data.
* @throws {Error} If decompression or JSON parsing fails.
*/
function decompressGzipJsonData(orders_data) {
try {
    // 1. Base64 decode the string
    const decoded = Buffer.from(orders_data, 'base64');

    // 2. Gzip decompress the decoded buffer
    // pako.inflate returns a Uint8Array, which we convert to a Buffer for consistency
    const decompressed = Buffer.from(pako.inflate(decoded));

    // 3. Parse the decompressed data as JSON
    const jsonData = JSON.parse(decompressed.toString('utf8'));

    return jsonData;
} catch (error) {
    console.error("Error decompressing or parsing data:", error);
    throw error; // Re-throw the error for the caller to handle
}
}

// --- Example Usage (Node.js) ---
const compressed_data = "H4sIAPONSWgC/02Qu27EIBBFf2VFvbvCPG13aSKl2FRpoihCNiYRWvwIDIUV5d/D2MlqqWDunTPDffsmfZyvLhobvJuAtAcyJpjt9Xh5qBhnjHNyPJDezHFw0Q9o4FwwJmVNNed1hfIXrEXQslyX6K0rj+rMsC+vJrkQsK1Hp58SxDz+jXp+enx5bSt5unTricnWtoVLKRq3eQbWBWEk+NED2fDzkC3chCmOYdvA5OQsztVCyUZx1WgtheBFK8q+uSprN+IGT9BBTkhZ3DT46XP/KYJMXoYO3B1P0/0Ui7sLo1J7WctaaEUbhBsLEaU9GPPhQ3Doxd6S7WL+M6Jn+vP+C9F3KnODAQAA";

try {
  const decompressedResult = decompressGzipJsonData(python_compressed_data);
  console.log("Decompressed Data:", decompressedResult);
} catch (e) {
   // Handle error
}
Decompressed 'orders' data
[
    {
        "broker_client": "mstock,MA1232233",
        "b_orderid": "33422558073381",
        "qty": 75,
        "price": 1.2,
        "buy_sell": "b",
        "instrument": "NIFTY:15-May-25:c:25500",
        "order_type": "limit",
        "product_type": "nrml",
        "q_usec": 1746596369775443,
        "userid": 622594,
        "order_status": "pending",
        "b_usec_update": 1746596370000000,
        "e_orderid": 1600000075847609,
        "o_ctr": 1,
        "qty_filled": 0,
        "stop_price": 0.0
    }
]

4XX HTTP code

Returned with proper response message

Get Order Book by OrderIDs

Type Endpoint Query Params Body
GET /order/order_book_by_orderids

Query Params

Name Description Default Allowed Values
broker
str
Broker to be added required Broker
client_id
str
Client ID of Broker Account required str
order_id_type
str
OrderID type to get the data required broker | exchange
order_ids
list[str]
List of OrderIDs to get data required list[str]
Sample Code
Bash
curl -X 'GET' \
    'https://tradeapi.quantsapp.com/v1/order/order_book_by_orderids?broker=aliceblue&client_id=123&order_id_type=broker&order_ids=id1&order_ids=id2' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: <MAC_ADDRESS>' \
    -H 'X-API-Token: <JWT_TOKEN>'
Bash
curl --http2 -X 'GET' \
    'https://tradeapi.quantsapp.com/v1/order/order_book_by_orderids?broker=aliceblue&client_id=123&order_id_type=broker&order_ids=id1&order_ids=id2' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: <MAC_ADDRESS>' \
    -H 'X-API-Token: <JWT_TOKEN>'
Bash
curl --http3 -X 'GET' \
    'https://tradeapi.quantsapp.com/v1/order/order_book_by_orderids?broker=aliceblue&client_id=123&order_id_type=broker&order_ids=id1&order_ids=id2' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: <MAC_ADDRESS>' \
    -H 'X-API-Token: <JWT_TOKEN>'
Python
import httpx  # (1)!

client = httpx.Client()

r = client.get(
    url='https://tradeapi.quantsapp.com/v1/order/order_book_by_orderids',
    headers={
        'X-API-Token': '<JWT_TOKEN>',
        'X-Mac-Address': '<MAC_ADDRESS>',
    },
    params={
        'broker': 'aliceblue',
        'client_id': '123',
        'order_id_type': 'broker',
        'order_ids': ['id1', 'id2'],
    },
)

print(r)
# <Response [200 OK]>

print(r.http_version)
# HTTP/1.1

print(r.json())
  1. pip install httpx
Python
import httpx  # (1)!

client = httpx.Client(http2=True)

r = client.get(
    url='https://tradeapi.quantsapp.com/v1/order/order_book_by_orderids',
    headers={
        'X-API-Token': '<JWT_TOKEN>',
        'X-Mac-Address': '<MAC_ADDRESS>',
    },
    params={
        'broker': 'aliceblue',
        'client_id': '123',
        'order_id_type': 'broker',
        'order_ids': ['id1', 'id2'],
    },
)

print(r)
# <Response [200 OK]>

print(r.http_version)
# HTTP/2

print(r.json())
  1. pip install httpx[http2]
Python
if __name__ == "__main__":
    r = asyncio.run(
        quantsapp_http3_request(  # (1)!
            url='https://tradeapi.quantsapp.com/v1/order/order_book_by_orderids',
            method='GET',
            headers={
                'X-API-Token': '<JWT_TOKEN>',
                'X-Mac-Address': '<MAC_ADDRESS>',
            },
            params={
                'broker': 'aliceblue',
                'client_id': '123',
                'order_id_type': 'broker',
                'order_ids': ['id1', 'id2'],
            },
        )
    )

    print(r)
    # <Response [200 OK]>

    print(r.http_version)
    # HTTP/3

    print(r.json())
  1. Use custom function quantsapp_http3_request 3

Response

200 HTTP Code

Gzip Compressed Response
{
    "gzip": true,
    "orders": "H4sIAPONSWgC/02Qu27EIBBFf2VFvbvCPG13aSKl2FRpoihCNiYRWvwIDIUV5d/D2MlqqWDunTPDffsmfZyvLhobvJuAtAcyJpjt9Xh5qBhnjHNyPJDezHFw0Q9o4FwwJmVNNed1hfIXrEXQslyX6K0rj+rMsC+vJrkQsK1Hp58SxDz+jXp+enx5bSt5unTricnWtoVLKRq3eQbWBWEk+NED2fDzkC3chCmOYdvA5OQsztVCyUZx1WgtheBFK8q+uSprN+IGT9BBTkhZ3DT46XP/KYJMXoYO3B1P0/0Ui7sLo1J7WctaaEUbhBsLEaU9GPPhQ3Doxd6S7WL+M6Jn+vP+C9F3KnODAQAA",
}

If gzip is true, then decode the orders data with below logic

orders decompress logic
Python
import json, gzip, base64

def decompress_gzip_json_data(orders_data: str) -> list | dict:
    return json.loads(gzip.decompress(base64.b64decode(orders_data)))
JavaScript
// For Node.js environments
const pako = require('pako');  // npm install pako

/**
* Decompresses Base64-encoded, gzipped JSON data.
*
* @param {string} orders_data - The Base64-encoded, gzipped string.
* @returns {Array | Object} The decompressed JSON data.
* @throws {Error} If decompression or JSON parsing fails.
*/
function decompressGzipJsonData(orders_data) {
try {
    // 1. Base64 decode the string
    const decoded = Buffer.from(orders_data, 'base64');

    // 2. Gzip decompress the decoded buffer
    // pako.inflate returns a Uint8Array, which we convert to a Buffer for consistency
    const decompressed = Buffer.from(pako.inflate(decoded));

    // 3. Parse the decompressed data as JSON
    const jsonData = JSON.parse(decompressed.toString('utf8'));

    return jsonData;
} catch (error) {
    console.error("Error decompressing or parsing data:", error);
    throw error; // Re-throw the error for the caller to handle
}
}

// --- Example Usage (Node.js) ---
const compressed_data = "H4sIAPONSWgC/02Qu27EIBBFf2VFvbvCPG13aSKl2FRpoihCNiYRWvwIDIUV5d/D2MlqqWDunTPDffsmfZyvLhobvJuAtAcyJpjt9Xh5qBhnjHNyPJDezHFw0Q9o4FwwJmVNNed1hfIXrEXQslyX6K0rj+rMsC+vJrkQsK1Hp58SxDz+jXp+enx5bSt5unTricnWtoVLKRq3eQbWBWEk+NED2fDzkC3chCmOYdvA5OQsztVCyUZx1WgtheBFK8q+uSprN+IGT9BBTkhZ3DT46XP/KYJMXoYO3B1P0/0Ui7sLo1J7WctaaEUbhBsLEaU9GPPhQ3Doxd6S7WL+M6Jn+vP+C9F3KnODAQAA";

try {
  const decompressedResult = decompressGzipJsonData(python_compressed_data);
  console.log("Decompressed Data:", decompressedResult);
} catch (e) {
   // Handle error
}
Decompressed 'orders' data
[
    {
        "broker_client": "mstock,MA1232233",
        "b_orderid": "33422558073381",
        "qty": 75,
        "price": 1.2,
        "buy_sell": "b",
        "instrument": "NIFTY:15-May-25:c:25500",
        "order_type": "limit",
        "product_type": "nrml",
        "q_usec": 1746596369775443,
        "userid": 622594,
        "order_status": "pending",
        "b_usec_update": 1746596370000000,
        "e_orderid": 1600000075847609,
        "o_ctr": 1,
        "qty_filled": 0,
        "stop_price": 0.0
    }
]

4XX HTTP code

Returned with proper response message

Place Order

Type Endpoint Query Params Body
POST /order/place_order

Body

Name Description Default Allowed Values
accounts
dict
Broker Accounts to place order required OrderPlacementBrokerAccounts
exchange
str
Exchange to place order required Exchange
product
str
Product Type to place order required ProductType
order_type
str
Order Type to place order required OrderType
validity
str
Order Validity to place order required Validity
settings
dict
Settings for the Order to be placed required OrderPlacementSetting
legs
list[dict]
Settings for the Order to be placed required list[OrderPlacementLeg]
Sample Payload
Bash
curl -X 'POST' \
    'https://tradeapi.quantsapp.com/v1/order/place_order' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: asd' \
    -H 'X-API-Token: asd' \
    -H 'Content-Type: application/json' \
    -d '{
        "accounts": {
            "mstock,MA6215631": 1
        },
        "exchange": "NSE-FO",
        "product": "nrml",
        "order_type": "limit",
        "validity": "day",
        "legs": [
            {
                "qty": 75,
                "price": 1.1,
                "symbol": "NIFTY",
                "segment": "o",
                "opt_type": "c",
                "expiry": "31-Jul-25",
                "strike": 25500,
                "buy_sell": "b"
            },
            {
                "qty": 75,
                "price": 1.1,
                "symbol": "NIFTY",
                "segment": "o",
                "opt_type": "p",
                "expiry": "31-Jul-25",
                "strike": 23500,
                "buy_sell": "s"
            },
        ],
        "settings": {
            "margin_benefit": True,
        }
    }'
Bash
curl -X --http2 'POST' \
    'https://tradeapi.quantsapp.com/v1/order/place_order' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: asd' \
    -H 'X-API-Token: asd' \
    -H 'Content-Type: application/json' \
    -d '{
        "accounts": {
            "mstock,MA6215631": 1
        },
        "exchange": "NSE-FO",
        "product": "nrml",
        "order_type": "limit",
        "validity": "day",
        "legs": [
            {
                "qty": 75,
                "price": 1.1,
                "symbol": "NIFTY",
                "segment": "o",
                "opt_type": "c",
                "expiry": "31-Jul-25",
                "strike": 25500,
                "buy_sell": "b"
            },
            {
                "qty": 75,
                "price": 1.1,
                "symbol": "NIFTY",
                "segment": "o",
                "opt_type": "p",
                "expiry": "31-Jul-25",
                "strike": 23500,
                "buy_sell": "s"
            },
        ],
        "settings": {
            "margin_benefit": True,
        }
    }'
Bash
curl -X --http3 'POST' \
    'https://tradeapi.quantsapp.com/v1/order/place_order' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: asd' \
    -H 'X-API-Token: asd' \
    -H 'Content-Type: application/json' \
    -d '{
        "accounts": {
            "mstock,MA6215631": 1
        },
        "exchange": "NSE-FO",
        "product": "nrml",
        "order_type": "limit",
        "validity": "day",
        "legs": [
            {
                "qty": 75,
                "price": 1.1,
                "symbol": "NIFTY",
                "segment": "o",
                "opt_type": "c",
                "expiry": "31-Jul-25",
                "strike": 25500,
                "buy_sell": "b"
            },
            {
                "qty": 75,
                "price": 1.1,
                "symbol": "NIFTY",
                "segment": "o",
                "opt_type": "p",
                "expiry": "31-Jul-25",
                "strike": 23500,
                "buy_sell": "s"
            },
        ],
        "settings": {
            "margin_benefit": True,
        }
    }'
Python
import httpx  # (1)!

client = httpx.Client()

r = client.post(
    url='https://tradeapi.quantsapp.com/v1/order/place_order',
    headers={
        'X-API-Token': '<JWT_TOKEN>',
        'X-Mac-Address': '<MAC_ADDRESS>',
    },
    data={
        'accounts': {
            'mstock,MA6215631': 1
        },
        'exchange': 'NSE-FO',
        'product': 'nrml',
        'order_type': 'limit',
        'validity': 'day',
        'legs': [
            {
                'qty': 75,
                'price': 1.1,
                'symbol': 'NIFTY',
                'segment': 'o',
                'opt_type': 'c',
                'expiry': '31-Jul-25',
                'strike': 25500,
                'buy_sell': 'b'
            },
            {
                'qty': 75,
                'price': 1.1,
                'symbol': 'NIFTY',
                'segment': 'o',
                'opt_type': 'p',
                'expiry': '31-Jul-25',
                'strike': 23500,
                'buy_sell': 's'
            },
        ],
        'settings': {
            'margin_benefit': True,
        }
    }
)

print(r)
# <Response [200 OK]>

print(r.http_version)
# HTTP/1.1

print(r.json())
  1. pip install httpx
Python
import httpx  # (1)!

client = httpx.Client(http2=True)

r = client.post(
    url='https://tradeapi.quantsapp.com/v1/order/place_order',
    headers={
        'X-API-Token': '<JWT_TOKEN>',
        'X-Mac-Address': '<MAC_ADDRESS>',
    },
    data={
        'accounts': {
            'mstock,MA6215631': 1
        },
        'exchange': 'NSE-FO',
        'product': 'nrml',
        'order_type': 'limit',
        'validity': 'day',
        'legs': [
            {
                'qty': 75,
                'price': 1.1,
                'symbol': 'NIFTY',
                'segment': 'o',
                'opt_type': 'c',
                'expiry': '31-Jul-25',
                'strike': 25500,
                'buy_sell': 'b'
            },
            {
                'qty': 75,
                'price': 1.1,
                'symbol': 'NIFTY',
                'segment': 'o',
                'opt_type': 'p',
                'expiry': '31-Jul-25',
                'strike': 23500,
                'buy_sell': 's'
            },
        ],
        'settings': {
            'margin_benefit': True,
        }
    }
)

print(r)
# <Response [200 OK]>

print(r.http_version)
# HTTP/1.1

print(r.json())
  1. pip install httpx[http2]
Python
if __name__ == '__main__':
    r = asyncio.run(
        quantsapp_http3_request(  # (1)!
            url='https://tradeapi.quantsapp.com/v1/order/place_order',
            method='POST',
            headers={
                'X-API-Token': '<JWT_TOKEN>',
                'X-Mac-Address': '<MAC_ADDRESS>',
            },
            data={
                'accounts': {
                    'mstock,MA6215631': 1
                },
                'exchange': 'NSE-FO',
                'product': 'nrml',
                'order_type': 'limit',
                'validity': 'day',
                'legs': [
                    {
                        'qty': 75,
                        'price': 1.1,
                        'symbol': 'NIFTY',
                        'segment': 'o',
                        'opt_type': 'c',
                        'expiry': '31-Jul-25',
                        'strike': 25500,
                        'buy_sell': 'b'
                    },
                    {
                        'qty': 75,
                        'price': 1.1,
                        'symbol': 'NIFTY',
                        'segment': 'o',
                        'opt_type': 'p',
                        'expiry': '31-Jul-25',
                        'strike': 23500,
                        'buy_sell': 's'
                    },
                ],
                'settings': {
                    'margin_benefit': True,
                }
            }
        )
    )

    print(r)
    # <Response [200 OK]>

    print(r.http_version)
    # HTTP/3

    print(r.json())
  1. Use custom function quantsapp_http3_request 3

Response

200 HTTP Code

    {
        "has_failed": true,  //(1)!
        "q_ref_id": 8,
        "q_usec": 1747905016476938,  //(2)!
        "orders": {
            "choice,X123354": {
                "placed": {
                    "NIFTY:31-Jul-25:c:25500": [
                            {
                            "b_orderid": "ATQOU00005F5", //(3)!
                            "qty": 75,
                            "buy_sell": "b",  //(4)!
                            "price": 0.05
                        }
                    ]
                },
                "failed": {
                    "NIFTY:26-Jun-25:p:23500": [
                        {
                            "qty": 75,
                            "buy_sell": "b",
                            "price": 0.01
                        }
                    ]
                }
            }
        }
    }
  1. If true then some or all leg orders got failed, the detailed info available on orders key with BrokerClient wise
  2. Order placed time in Micro seconds (µsec)
  3. Present only if order successfully placed
  4. Indicated Buy or Sell BuySell

4XX HTTP code

Returned with proper response message

Modify Order

Type Endpoint Query Params Body
PUT /order/modify_order

Payload

Name Description Default Allowed Values
broker_client
str
Broker Account required BrokerClient
b_orderid
str
Broker OrderID required str
e_orderid
str
Exchange OrderID required str
order
dict
Order data to Modify required dict
order.qty
int
Order Quantity to Modify required int
order.price
int|float
Order Price to Modify required int | float
order.stop_price
int|float
Order Stop Loss Price to Modify NA int | float
Sample Payload
Bash
curl -X 'PUT' \
    'https://tradeapi.quantsapp.com/v1/order/modify_order' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: asd' \
    -H 'X-API-Token: asd' \
    -H 'Content-Type: application/json' \
    -d '{
        "broker_client": "mstock,MA6215631",
        "b_orderid": "ATQOU00005F5",
        "e_orderid": "1500000155868129",
        "order": {
            "qty": 75,
            "price": 1.1,
            "stop_price": 0.1,
        }
    }'
Bash
curl -X --http2 'PUT' \
    'https://tradeapi.quantsapp.com/v1/order/modify_order' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: asd' \
    -H 'X-API-Token: asd' \
    -H 'Content-Type: application/json' \
    -d '{
        "broker_client": "mstock,MA6215631",
        "b_orderid": "ATQOU00005F5",
        "e_orderid": "1500000155868129",
        "order": {
            "qty": 75,
            "price": 1.1,
            "stop_price": 0.1,
        }
    }'
Bash
curl -X --http3 'PUT' \
    'https://tradeapi.quantsapp.com/v1/order/modify_order' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: asd' \
    -H 'X-API-Token: asd' \
    -H 'Content-Type: application/json' \
    -d '{
        "broker_client": "mstock,MA6215631",
        "b_orderid": "ATQOU00005F5",
        "e_orderid": "1500000155868129",
        "order": {
            "qty": 75,
            "price": 1.1,
            "stop_price": 0.1,
        }
    }'
Python
import httpx  # (1)!

client = httpx.Client()

r = client.put(
    url='https://tradeapi.quantsapp.com/v1/order/modify_order',
    headers={
        'X-API-Token': '<JWT_TOKEN>',
        'X-Mac-Address': '<MAC_ADDRESS>',
    },
    data={
        'broker_client': 'mstock,MA6215631',
        'b_orderid': 'ATQOU00005F5',
        'e_orderid': '1500000155868129',
        'order': {
            'qty': 75,
            'price': 1.1,
            'stop_price': 0.1,
        }
    }
)

print(r)
# <Response [200 OK]>

print(r.http_version)
# HTTP/1.1

print(r.json())
  1. pip install httpx
Python
import httpx  # (1)!

client = httpx.Client(http2=True)

r = client.put(
    url='https://tradeapi.quantsapp.com/v1/order/modify_order',
    headers={
        'X-API-Token': '<JWT_TOKEN>',
        'X-Mac-Address': '<MAC_ADDRESS>',
    },
    data={
        'broker_client': 'mstock,MA6215631',
        'b_orderid': 'ATQOU00005F5',
        'e_orderid': '1500000155868129',
        'order': {
            'qty': 75,
            'price': 1.1,
            'stop_price': 0.1,
        }
    }
)

print(r)
# <Response [200 OK]>

print(r.http_version)
# HTTP/1.1

print(r.json())
  1. pip install httpx[http2]
Python
if __name__ == '__main__':
    r = asyncio.run(
        quantsapp_http3_request(  # (1)!
            url='https://tradeapi.quantsapp.com/v1/order/modify_order',
            method='PUT',
            headers={
                'X-API-Token': '<JWT_TOKEN>',
                'X-Mac-Address': '<MAC_ADDRESS>',
            },
            data={
                'broker_client': 'mstock,MA6215631',
                'b_orderid': 'ATQOU00005F5',
                'e_orderid': '1500000155868129',
                'order': {
                    'qty': 75,
                    'price': 1.1,
                    'stop_price': 0.1,
                }
            }
        )
    )

    print(r)
    # <Response [200 OK]>

    print(r.http_version)
    # HTTP/3

    print(r.json())
  1. Use custom function quantsapp_http3_request 3

Response

200 HTTP Code

    {
        "msg": "Modified",
    }

4XX HTTP code

Returned with proper response message

Cancel Order

Type Endpoint Query Params Body
DELETE /order/cancel_order

Payload

Name Description Default Allowed Values
order
dict
Order data to Modify required OrderCancelData
Sample Payload
Bash
curl -X 'DELETE' \
    'https://tradeapi.quantsapp.com/v1/order/cancel_order' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: asd' \
    -H 'X-API-Token: asd' \
    -H 'Content-Type: application/json' \
    -d '{
        "order": {
            "choice,X123354": [
                {
                    "b_orderid": "ATQOU00001K5",
                    "e_orderid": "1200000164137820",
                },
                {
                    "b_orderid": "ATQOU00001K1",
                    "e_orderid": "1200000164137821",
                },
            ],
            "dhan,423354": [
                {
                    "b_orderid": "ATQOU00001K2",
                    "e_orderid": "1200000164137829",
                },
            ],
        }
    }'
Bash
curl -X --http2 'DELETE' \
    'https://tradeapi.quantsapp.com/v1/order/cancel_order' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: asd' \
    -H 'X-API-Token: asd' \
    -H 'Content-Type: application/json' \
    -d '{
        "order": {
            "choice,X123354": [
                {
                    "b_orderid": "ATQOU00001K5",
                    "e_orderid": "1200000164137820",
                },
                {
                    "b_orderid": "ATQOU00001K1",
                    "e_orderid": "1200000164137821",
                },
            ],
            "dhan,423354": [
                {
                    "b_orderid": "ATQOU00001K2",
                    "e_orderid": "1200000164137829",
                },
            ],
        }
    }'
Bash
curl -X --http3 'DELETE' \
    'https://tradeapi.quantsapp.com/v1/order/cancel_order' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: asd' \
    -H 'X-API-Token: asd' \
    -H 'Content-Type: application/json' \
    -d '{
        "order": {
            "choice,X123354": [
                {
                    "b_orderid": "ATQOU00001K5",
                    "e_orderid": "1200000164137820",
                },
                {
                    "b_orderid": "ATQOU00001K1",
                    "e_orderid": "1200000164137821",
                },
            ],
            "dhan,423354": [
                {
                    "b_orderid": "ATQOU00001K2",
                    "e_orderid": "1200000164137829",
                },
            ],
        }
    }'
Python
import httpx  # (1)!

client = httpx.Client()

r = client.delete(
    url='https://tradeapi.quantsapp.com/v1/order/cancel_order',
    headers={
        'X-API-Token': '<JWT_TOKEN>',
        'X-Mac-Address': '<MAC_ADDRESS>',
    },
    data= {
        'order': {
            'choice,X123354': [
                {
                    'b_orderid': 'ATQOU00001K5',
                    'e_orderid': '1200000164137820',
                },
                {
                    'b_orderid': 'ATQOU00001K1',
                    'e_orderid': '1200000164137821',
                },
            ],
            'dhan,423354': [
                {
                    'b_orderid': 'ATQOU00001K2',
                    'e_orderid': '1200000164137829',
                },
            ],
        }
    }
)

print(r)
# <Response [200 OK]>

print(r.http_version)
# HTTP/1.1

print(r.json())
  1. pip install httpx
Python
import httpx  # (1)!

client = httpx.Client(http2=True)

r = client.delete(
    url='https://tradeapi.quantsapp.com/v1/order/cancel_order',
    headers={
        'X-API-Token': '<JWT_TOKEN>',
        'X-Mac-Address': '<MAC_ADDRESS>',
    },
    data={
        'order': {
            'choice,X123354': [
                {
                    'b_orderid': 'ATQOU00001K5',
                    'e_orderid': '1200000164137820',
                },
                {
                    'b_orderid': 'ATQOU00001K1',
                    'e_orderid': '1200000164137821',
                },
            ],
            'dhan,423354': [
                {
                    'b_orderid': 'ATQOU00001K2',
                    'e_orderid': '1200000164137829',
                },
            ],
        }
    }
)

print(r)
# <Response [200 OK]>

print(r.http_version)
# HTTP/1.1

print(r.json())
  1. pip install httpx[http2]
Python
if __name__ == '__main__':
    r = asyncio.run(
        quantsapp_http3_request(  # (1)!
            url='https://tradeapi.quantsapp.com/v1/order/cancel_order',
            method='DELETE',
            headers={
                'X-API-Token': '<JWT_TOKEN>',
                'X-Mac-Address': '<MAC_ADDRESS>',
            },
            data={
                'order': {
                    'choice,X123354': [
                        {
                            'b_orderid': 'ATQOU00001K5',
                            'e_orderid': '1200000164137820',
                        },
                        {
                            'b_orderid': 'ATQOU00001K1',
                            'e_orderid': '1200000164137821',
                        },
                    ],
                    'dhan,423354': [
                        {
                            'b_orderid': 'ATQOU00001K2',
                            'e_orderid': '1200000164137829',
                        },
                    ],
                }
            }
        )
    )

    print(r)
    # <Response [200 OK]>

    print(r.http_version)
    # HTTP/3

    print(r.json())
  1. Use custom function quantsapp_http3_request 3

Response

200 HTTP Code

    {
        "has_failed": false,  //(1)!
        "q_ref_id_c": 15
    }
  1. If true then some or all orders cancellation got failed

4XX HTTP code

Returned with proper response message

Cancel All Orders

Type Endpoint Query Params Body
DELETE /order/cancel_all_orders

Payload

Name Description Default Allowed Values
broker_client
str
Broker Account required BrokerClient
Sample Payload
Bash
curl -X 'DELETE' \
    'https://tradeapi.quantsapp.com/v1/order/cancel_all_orders' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: asd' \
    -H 'X-API-Token: asd' \
    -H 'Content-Type: application/json' \
    -d '{
        "broker_client": "choice,X123354"
    }'
Bash
curl -X --http2 'DELETE' \
    'https://tradeapi.quantsapp.com/v1/order/cancel_all_orders' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: asd' \
    -H 'X-API-Token: asd' \
    -H 'Content-Type: application/json' \
    -d '{
        "broker_client": "choice,X123354"
    }'
Bash
curl -X --http3 'DELETE' \
    'https://tradeapi.quantsapp.com/v1/order/cancel_all_orders' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: asd' \
    -H 'X-API-Token: asd' \
    -H 'Content-Type: application/json' \
    -d '{
        "broker_client": "choice,X123354"
    }'
Python
import httpx  # (1)!

client = httpx.Client()

r = client.delete(
    url='https://tradeapi.quantsapp.com/v1/order/cancel_all_orders',
    headers={
        'X-API-Token': '<JWT_TOKEN>',
        'X-Mac-Address': '<MAC_ADDRESS>',
    },
    data={
        "broker_client": "choice,X123354"
    }
)

print(r)
# <Response [200 OK]>

print(r.http_version)
# HTTP/1.1

print(r.json())
  1. pip install httpx
Python
import httpx  # (1)!

client = httpx.Client(http2=True)

r = client.delete(
    url='https://tradeapi.quantsapp.com/v1/order/cancel_all_orders',
    headers={
        'X-API-Token': '<JWT_TOKEN>',
        'X-Mac-Address': '<MAC_ADDRESS>',
    },
    data={
        "broker_client": "choice,X123354"
    }
)

print(r)
# <Response [200 OK]>

print(r.http_version)
# HTTP/1.1

print(r.json())
  1. pip install httpx[http2]
Python
if __name__ == '__main__':
    r = asyncio.run(
        quantsapp_http3_request(  # (1)!
            url='https://tradeapi.quantsapp.com/v1/order/cancel_all_orders',
            method='DELETE',
            headers={
                'X-API-Token': '<JWT_TOKEN>',
                'X-Mac-Address': '<MAC_ADDRESS>',
            },
            data={
                'broker_client': 'choice,X123354'
            }
        )
    )

    print(r)
    # <Response [200 OK]>

    print(r.http_version)
    # HTTP/3

    print(r.json())
  1. Use custom function quantsapp_http3_request 3

Response

200 HTTP Code

    {
        "msg": "success",
        "has_failed": false,  //(1)!
        "q_ref_id_c": 15
    }
  1. If true then some or all orders cancellation got failed

4XX HTTP code

Returned with proper response message

Position Management

Section Description
Get Positions Get Positions on specific Broker accounts wise
Get Positions Combined Get Positions on all Broker accounts combined

Get Positions

Type Endpoint Query Params Body
GET /position/positions

Query Params

Name Description Default Allowed Values
broker_clientids
list[str]
Broker accounts to get Positions Account wise data required list[BrokerClient]
Sample Code
Bash
curl -X 'GET' \
    'https://tradeapi.quantsapp.com/v1/position/positions?broker_clientids=choice,123&broker_clientids=choice,456' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: <MAC_ADDRESS>' \
    -H 'X-API-Token: <JWT_TOKEN>'
Bash
curl --http2 -X 'GET' \
    'https://tradeapi.quantsapp.com/v1/position/positions?broker_clientids=choice,123&broker_clientids=choice,456' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: <MAC_ADDRESS>' \
    -H 'X-API-Token: <JWT_TOKEN>'
Bash
curl --http3 -X 'GET' \
    'https://tradeapi.quantsapp.com/v1/position/positions?broker_clientids=choice,123&broker_clientids=choice,456' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: <MAC_ADDRESS>' \
    -H 'X-API-Token: <JWT_TOKEN>'
Python
import httpx  # (1)!

client = httpx.Client()

r = client.get(
    url='https://tradeapi.quantsapp.com/v1/position/positions',
    headers={
        'X-API-Token': '<JWT_TOKEN>',
        'X-Mac-Address': '<MAC_ADDRESS>',
    },
    params={
        'broker_clientids': ['choice,123', 'choice,456'],
    },
)

print(r)
# <Response [200 OK]>

print(r.http_version)
# HTTP/1.1

print(r.json())
  1. pip install httpx
Python
import httpx  # (1)!

client = httpx.Client(http2=True)

r = client.get(
    url='https://tradeapi.quantsapp.com/v1/position/positions',
    headers={
        'X-API-Token': '<JWT_TOKEN>',
        'X-Mac-Address': '<MAC_ADDRESS>',
    },
    params={
        'broker_clientids': ['choice,123', 'choice,456'],
    },
)

print(r)
# <Response [200 OK]>

print(r.http_version)
# HTTP/2

print(r.json())
  1. pip install httpx[http2]
Python
if __name__ == "__main__":
    r = asyncio.run(
        quantsapp_http3_request(  # (1)!
            url='https://tradeapi.quantsapp.com/v1/position/positions',
            method='GET',
            headers={
                'X-API-Token': '<JWT_TOKEN>',
                'X-Mac-Address': '<MAC_ADDRESS>',
            },
            params={
                'broker_clientids': ['choice,123', 'choice,456'],
            },
        )
    )

    print(r)
    # <Response [200 OK]>

    print(r.http_version)
    # HTTP/3

    print(r.json())
  1. Use custom function quantsapp_http3_request 3

Response

200 HTTP Code

Gzip Compressed Response
{
    "gzip": true,
    "positions":  "H4sIAJhISmgC/03KwQrCIByA8VcZnrfhFLfmAww61KlLRIg5ocCZub+BjL17OoI6fj++BY13aUvW0I6QFiNeXBb0sDP4MGkLqdFxP5zOvGHVQcaKMK44YT3GqCyQ888xKBAQnc6r9ZPJfgtRvCAm6tg3QbylCfnqab3prI35v7b+bbu2JpmdUOBT0/W6fgAlzkEYrgAAAA=="
}

If gzip is true, then decode the positions data with below logic

orders decompress logic
Python
import json, gzip, base64

def decompress_gzip_json_data(positions_data: str) -> list | dict:
    return json.loads(gzip.decompress(base64.b64decode(positions_data)))
JavaScript
// For Node.js environments
const pako = require('pako');  // npm install pako

/**
* Decompresses Base64-encoded, gzipped JSON data.
*
* @param {string} positions_data - The Base64-encoded, gzipped string.
* @returns {Array | Object} The decompressed JSON data.
* @throws {Error} If decompression or JSON parsing fails.
*/
function decompressGzipJsonData(positions_data) {
try {
    // 1. Base64 decode the string
    const decoded = Buffer.from(positions_data, 'base64');

    // 2. Gzip decompress the decoded buffer
    // pako.inflate returns a Uint8Array, which we convert to a Buffer for consistency
    const decompressed = Buffer.from(pako.inflate(decoded));

    // 3. Parse the decompressed data as JSON
    const jsonData = JSON.parse(decompressed.toString('utf8'));

    return jsonData;
} catch (error) {
    console.error("Error decompressing or parsing data:", error);
    throw error; // Re-throw the error for the caller to handle
}
}

// --- Example Usage (Node.js) ---
const compressed_data = "H4sIABvKIWgC/4uuVsrMKy4pKs1NzStRslJQ8vN0C4m0MjTV9U2s1DUytUq2MjI1MjBQ0lFQKijKTylNLokvqSxIBSnNK8rNAYknlVbGF5ZUAoXMTaHckviyxJxSkCpTC0M9I5BwcWpODrIyMB9JnblBbSwAX3B17I4AAAA=";

try {
  const decompressedResult = decompressGzipJsonData(python_compressed_data);
  console.log("Decompressed Data:", decompressedResult);
} catch (e) {
   // Handle error
}
Decompressed 'positions' data
{
    "dhan,51372260": [
        {
            "instrument": "NIFTY:15-May-25:c:25900",
            "product_type": "nrml",
            "buy_qty": 75,
            "buy_t_value": 93.75,
            "sell_qty": 75,
            "sell_t_value": 86.25,
            "p_ctr": 3,
        },
    ]
}

4XX HTTP code

Returned with proper response message

Get Positions Combined

Type Endpoint Query Params Body
GET /position/positions_combined

Query Params

Name Type Description Default Allowed Values
broker_clientids*
list[str]
Broker accounts to get Positions Combined data required list[BrokerClient]

* broker_clientids - only one broker_client allowed right now

Sample Code
Bash
curl -X 'GET' \
    'https://tradeapi.quantsapp.com/v1/position/positions_combined?broker_clientids=choice,123' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: <MAC_ADDRESS>' \
    -H 'X-API-Token: <JWT_TOKEN>'
Bash
curl --http2 -X 'GET' \
    'https://tradeapi.quantsapp.com/v1/position/positions_combined?broker_clientids=choice,123' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: <MAC_ADDRESS>' \
    -H 'X-API-Token: <JWT_TOKEN>'
Bash
curl --http3 -X 'GET' \
    'https://tradeapi.quantsapp.com/v1/position/positions_combined?broker_clientids=choice,123' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: <MAC_ADDRESS>' \
    -H 'X-API-Token: <JWT_TOKEN>'
Python
import httpx  # (1)!

client = httpx.Client()

r = client.get(
    url='https://tradeapi.quantsapp.com/v1/position/positions_combined',
    headers={
        'X-API-Token': '<JWT_TOKEN>',
        'X-Mac-Address': '<MAC_ADDRESS>',
    },
    params={
        'broker_clientids': ['choice,123'],
    },
)

print(r)
# <Response [200 OK]>

print(r.http_version)
# HTTP/1.1

print(r.json())
  1. pip install httpx
Python
import httpx  # (1)!

client = httpx.Client(http2=True)

r = client.get(
    url='https://tradeapi.quantsapp.com/v1/position/positions_combined',
    headers={
        'X-API-Token': '<JWT_TOKEN>',
        'X-Mac-Address': '<MAC_ADDRESS>',
    },
    params={
        'broker_clientids': ['choice,123'],
    },
)

print(r)
# <Response [200 OK]>

print(r.http_version)
# HTTP/2

print(r.json())
  1. pip install httpx[http2]
Python
if __name__ == "__main__":
    r = asyncio.run(
        quantsapp_http3_request(  # (1)!
            url='https://tradeapi.quantsapp.com/v1/position/positions_combined',
            method='GET',
            headers={
                'X-API-Token': '<JWT_TOKEN>',
                'X-Mac-Address': '<MAC_ADDRESS>',
            },
            params={
                'broker_clientids': ['choice,123'],
            },
        )
    )

    print(r)
    # <Response [200 OK]>

    print(r.http_version)
    # HTTP/3

    print(r.json())
  1. Use custom function quantsapp_http3_request 3

Response

200 HTTP Code

Gzip Compressed Response
{
    "gzip": true,
    "positions":  "H4sIABvKIWgC/4uuVsrMKy4pKs1NzStRslJQ8vN0C4m0MjTV9U2s1DUytUq2MjI1MjBQ0lFQKijKTylNLokvqSxIBSnNK8rNAYknlVbGF5ZUAoXMTaHckviyxJxSkCpTC0M9I5BwcWpODrIyMB9JnblBbSwAX3B17I4AAAA="
}

If gzip is true, then decode the positions data with below logic

orders decompress logic
Python
import json, gzip, base64

def decompress_gzip_json_data(positions_data: str) -> list | dict:
    return json.loads(gzip.decompress(base64.b64decode(positions_data)))
JavaScript
// For Node.js environments
const pako = require('pako');  // npm install pako

/**
* Decompresses Base64-encoded, gzipped JSON data.
*
* @param {string} positions_data - The Base64-encoded, gzipped string.
* @returns {Array | Object} The decompressed JSON data.
* @throws {Error} If decompression or JSON parsing fails.
*/
function decompressGzipJsonData(positions_data) {
try {
    // 1. Base64 decode the string
    const decoded = Buffer.from(positions_data, 'base64');

    // 2. Gzip decompress the decoded buffer
    // pako.inflate returns a Uint8Array, which we convert to a Buffer for consistency
    const decompressed = Buffer.from(pako.inflate(decoded));

    // 3. Parse the decompressed data as JSON
    const jsonData = JSON.parse(decompressed.toString('utf8'));

    return jsonData;
} catch (error) {
    console.error("Error decompressing or parsing data:", error);
    throw error; // Re-throw the error for the caller to handle
}
}

// --- Example Usage (Node.js) ---
const compressed_data = "H4sIABvKIWgC/4uuVsrMKy4pKs1NzStRslJQ8vN0C4m0MjTV9U2s1DUytUq2MjI1MjBQ0lFQKijKTylNLokvqSxIBSnNK8rNAYknlVbGF5ZUAoXMTaHckviyxJxSkCpTC0M9I5BwcWpODrIyMB9JnblBbSwAX3B17I4AAAA=";

try {
  const decompressedResult = decompressGzipJsonData(python_compressed_data);
  console.log("Decompressed Data:", decompressedResult);
} catch (e) {
   // Handle error
}
Decompressed 'positions' data
[
    {
        "instrument": "NIFTY:15-May-25:c:25200",
        "product_type": "nrml",
        "buy_qty": 75,
        "buy_t_value": 581.25,
        "sell_qty": 75,
        "sell_t_value": 570
    }
]

4XX HTTP code

Returned with proper response message

Broker Websocket Management

Section Description
Get Broker Websocket Status Get the connection status of Broker Websocket
Broker Websocket Reconnect Reconnect to Broker Websocket

Get Broker Websocket Status

Type Endpoint Query Params Body
GET /broker_websocket/connection_status

Query Params

Name Description Default Allowed Values
broker_client
str
Broker account to get Websocket Connection Status required BrokerClient
Sample Code
Bash
curl -X 'GET' \
    'https://tradeapi.quantsapp.com/v1/broker_websocket/connection_status?broker_client=choice,123' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: <MAC_ADDRESS>' \
    -H 'X-API-Token: <JWT_TOKEN>'
Bash
curl --http2 -X 'GET' \
    'https://tradeapi.quantsapp.com/v1/broker_websocket/connection_status?broker_client=choice,123' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: <MAC_ADDRESS>' \
    -H 'X-API-Token: <JWT_TOKEN>'
Bash
curl --http3 -X 'GET' \
    'https://tradeapi.quantsapp.com/v1/broker_websocket/connection_status?broker_client=choice,123' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: <MAC_ADDRESS>' \
    -H 'X-API-Token: <JWT_TOKEN>'
Python
import httpx  # (1)!

client = httpx.Client()

r = client.get(
    url='https://tradeapi.quantsapp.com/v1/broker_websocket/connection_status',
    headers={
        'X-API-Token': '<JWT_TOKEN>',
        'X-Mac-Address': '<MAC_ADDRESS>',
    },
    params={
        'broker_client': 'choice,123',
    },
)

print(r)
# <Response [200 OK]>

print(r.http_version)
# HTTP/1.1

print(r.json())
  1. pip install httpx
Python
import httpx  # (1)!

client = httpx.Client(http2=True)

r = client.get(
    url='https://tradeapi.quantsapp.com/v1/broker_websocket/connection_status',
    headers={
        'X-API-Token': '<JWT_TOKEN>',
        'X-Mac-Address': '<MAC_ADDRESS>',
    },
    params={
        'broker_client': 'choice,123',
    },
)

print(r)
# <Response [200 OK]>

print(r.http_version)
# HTTP/2

print(r.json())
  1. pip install httpx[http2]
Python
if __name__ == "__main__":
    r = asyncio.run(
        quantsapp_http3_request(  # (1)!
            url='https://tradeapi.quantsapp.com/v1/broker_websocket/connection_status',
            method='GET',
            headers={
                'X-API-Token': '<JWT_TOKEN>',
                'X-Mac-Address': '<MAC_ADDRESS>',
            },
            params={
                'broker_client': 'choice,123',
            },
        )
    )

    print(r)
    # <Response [200 OK]>

    print(r.http_version)
    # HTTP/3

    print(r.json())
  1. Use custom function quantsapp_http3_request 3

Response

200 HTTP Code

{
    "msg": "Connected",
    "ts_ping": 1747129266,
    "ts_msg": 1747126860,
    "ts_conn": 1747126860
}

4XX HTTP code

Returned with proper response message

Broker Websocket Reconnect

Type Endpoint Query Params Body
PUT /broker_websocket/reconnect

Query Params

Name Description Default Allowed Values
broker_client
str
Broker account to reconnect Websocket Connection required BrokerClient
Sample Code
Bash
curl -X 'PUT' \
    'https://tradeapi.quantsapp.com/v1/broker_websocket/reconnect?broker_client=choice,123' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: <MAC_ADDRESS>' \
    -H 'X-API-Token: <JWT_TOKEN>'
Bash
curl --http2 -X 'PUT' \
    'https://tradeapi.quantsapp.com/v1/broker_websocket/reconnect?broker_client=choice,123' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: <MAC_ADDRESS>' \
    -H 'X-API-Token: <JWT_TOKEN>'
Bash
curl --http3 -X 'PUT' \
    'https://tradeapi.quantsapp.com/v1/broker_websocket/reconnect?broker_client=choice,123' \
    -H 'accept: application/json' \
    -H 'X-Mac-Address: <MAC_ADDRESS>' \
    -H 'X-API-Token: <JWT_TOKEN>'
Python
import httpx  # (1)!

client = httpx.Client()

r = client.put(
    url='https://tradeapi.quantsapp.com/v1/broker_websocket/reconnect',
    headers={
        'X-API-Token': '<JWT_TOKEN>',
        'X-Mac-Address': '<MAC_ADDRESS>',
    },
    params={
        'broker_client': 'choice,123',
    },
)

print(r)
# <Response [200 OK]>

print(r.http_version)
# HTTP/1.1

print(r.json())
  1. pip install httpx
Python
import httpx  # (1)!

client = httpx.Client(http2=True)

r = client.put(
    url='https://tradeapi.quantsapp.com/v1/broker_websocket/reconnect',
    headers={
        'X-API-Token': '<JWT_TOKEN>',
        'X-Mac-Address': '<MAC_ADDRESS>',
    },
    params={
        'broker_client': 'choice,123',
    },
)

print(r)
# <Response [200 OK]>

print(r.http_version)
# HTTP/2

print(r.json())
  1. pip install httpx[http2]
Python
if __name__ == "__main__":
    r = asyncio.run(
        quantsapp_http3_request(  # (1)!
            url='https://tradeapi.quantsapp.com/v1/broker_websocket/reconnect',
            method='PUT',
            headers={
                'X-API-Token': '<JWT_TOKEN>',
                'X-Mac-Address': '<MAC_ADDRESS>',
            },
            params={
                'broker_client': 'choice,123',
            },
        )
    )

    print(r)
    # <Response [200 OK]>

    print(r.http_version)
    # HTTP/3

    print(r.json())
  1. Use custom function quantsapp_http3_request 3

Response

200 HTTP Code

{
    "msg": "Connected",
}

4XX HTTP code

Returned with proper response message


  1. JWT Token received from Login Process 

  2. MAC Address Retrieval Code
    Python
    import uuid
    
    def get_mac_address() -> str:
        """Retreive the mac address of the connected network interface"""
    
        # Get the hardware address as a 48-bit positive integer
        mac_num = uuid.getnode()
    
        # 1. Convert the number to hex
        # 2. Pad it to 12 chars
        # 3. Convert it to a series of two char strings
        # 4. Join them with colons
        # 5. convert to uppercase
        return ':'.join(f"{b:02x}" for b in mac_num.to_bytes(6)).upper()
    
    print(get_mac_address)
    # 15:A2:C8:DD:31:11
    
    JavaScript
    const os = require('os');
    
    /**
    * Retrieves the MAC address of a connected non-internal network interface.
    * Prioritizes non-internal (e.g., Ethernet, Wi-Fi) interfaces with a MAC address.
    *
    * @returns {string | null} The MAC address in 'XX:XX:XX:XX:XX:XX' format, or null if not found.
    */
    function getMacAddress() {
        const interfaces = os.networkInterfaces();
        let macAddress = null;
    
        // Iterate over all network interfaces
        for (const interfaceName in interfaces) {
            const networkInterface = interfaces[interfaceName];
    
            for (const iface of networkInterface) {
                // Filter out internal (loopback) interfaces and ensure it has a MAC address
                if (!iface.internal && iface.mac && iface.mac !== '00:00:00:00:00:00') {
                    macAddress = iface.mac.toUpperCase();
                    // Found a valid MAC address, you might want to return the first one found
                    // or continue iterating if you have a specific interface in mind.
                    // For simplicity, we return the first valid one here.
                    return macAddress;
                }
            }
        }
    
        return macAddress; // Return null if no suitable MAC address was found
    }
    
    // --- Usage Example ---
    const mac = getMacAddress();
    
    if (mac) {
        console.log(`MAC Address: ${mac}`);
    } else {
        console.log("No MAC address found for a non-internal interface.");
    }
    
    // MAC Address: 15:A2:C8:DD:31:11
    

  3. Python HTTP3 BaseCode

    This code is based on asynchronous logic

    Python
    import asyncio
    from collections import deque
    from typing import Any, AsyncIterator, Deque, Dict, Optional, Tuple, cast
    from urllib.parse import urlparse
    
    import httpx
    from aioquic.asyncio.client import connect
    from aioquic.asyncio.protocol import QuicConnectionProtocol
    from aioquic.h3.connection import H3_ALPN, H3Connection
    from aioquic.h3.events import DataReceived, H3Event, Headers, HeadersReceived
    from aioquic.quic.configuration import QuicConfiguration
    from aioquic.quic.events import QuicEvent
    
    
    
    class H3ResponseStream(httpx.AsyncByteStream):
        def __init__(self, aiterator: AsyncIterator[bytes]):
            self._aiterator = aiterator
    
        async def __aiter__(self) -> AsyncIterator[bytes]:
            async for part in self._aiterator:
                yield part
    
    
    class H3Transport(QuicConnectionProtocol, httpx.AsyncBaseTransport):
        def __init__(self, *args, **kwargs) -> None:
            super().__init__(*args, **kwargs)
    
            self._http = H3Connection(self._quic)
            self._read_queue: Dict[int, Deque[H3Event]] = {}
            self._read_ready: Dict[int, asyncio.Event] = {}
    
        async def handle_async_request(self, request: httpx.Request) -> httpx.Response:
            assert isinstance(request.stream, httpx.AsyncByteStream)
    
            stream_id = self._quic.get_next_available_stream_id()
            self._read_queue[stream_id] = deque()
            self._read_ready[stream_id] = asyncio.Event()
    
            # prepare request
            self._http.send_headers(
                stream_id=stream_id,
                headers=[
                    (b":method", request.method.encode()),
                    (b":scheme", request.url.raw_scheme),
                    (b":authority", request.url.netloc),
                    (b":path", request.url.raw_path),
                ]
                + [
                    (k.lower(), v)
                    for (k, v) in request.headers.raw
                    if k.lower() not in (b"connection", b"host")
                ],
            )
            async for data in request.stream:
                self._http.send_data(stream_id=stream_id, data=data, end_stream=False)
            self._http.send_data(stream_id=stream_id, data=b"", end_stream=True)
    
            # transmit request
            self.transmit()
    
            # process response
            status_code, headers, stream_ended = await self._receive_response(stream_id)
    
            return httpx.Response(
                status_code=status_code,
                headers=headers,
                stream=H3ResponseStream(
                    self._receive_response_data(stream_id, stream_ended)
                ),
                extensions={
                    "http_version": b"HTTP/3",
                },
            )
    
        def http_event_received(self, event: H3Event):
            if isinstance(event, (HeadersReceived, DataReceived)):
                stream_id = event.stream_id
                if stream_id in self._read_queue:
                    self._read_queue[event.stream_id].append(event)
                    self._read_ready[event.stream_id].set()
    
        def quic_event_received(self, event: QuicEvent):
            #  pass event to the HTTP layer
            if self._http is not None:
                for http_event in self._http.handle_event(event):
                    self.http_event_received(http_event)
    
        async def _receive_response(self, stream_id: int) -> Tuple[int, Headers, bool]:
            """
            Read the response status and headers.
            """
            stream_ended = False
            while True:
                event = await self._wait_for_http_event(stream_id)
                if isinstance(event, HeadersReceived):
                    stream_ended = event.stream_ended
                    break
    
            headers = []
            status_code = 0
            for header, value in event.headers:
                if header == b":status":
                    status_code = int(value.decode())
                else:
                    headers.append((header, value))
            return status_code, headers, stream_ended
    
        async def _receive_response_data(
            self, stream_id: int, stream_ended: bool
        ) -> AsyncIterator[bytes]:
            """
            Read the response data.
            """
            while not stream_ended:
                event = await self._wait_for_http_event(stream_id)
                if isinstance(event, DataReceived):
                    stream_ended = event.stream_ended
                    yield event.data
                elif isinstance(event, HeadersReceived):
                    stream_ended = event.stream_ended
    
        async def _wait_for_http_event(self, stream_id: int) -> H3Event:
            """
            Returns the next HTTP/3 event for the given stream.
            """
            if not self._read_queue[stream_id]:
                await self._read_ready[stream_id].wait()
            event = self._read_queue[stream_id].popleft()
            if not self._read_queue[stream_id]:
                self._read_ready[stream_id].clear()
            return event
    
    
    
    async def quantsapp_http3_request(
        url: str,
        method: str,
        headers: Optional[dict[str, Any]] = None,
        query_params: Optional[dict[str, Any]] = None,
        data: Optional[dict[str, Any]] = None,
    ) -> None:
    
        # parse URL
        parsed_url = urlparse(url)
        assert parsed_url.scheme == "https", "Only https:// URLs are supported."
    
    
        async with connect(
            host=parsed_url.hostname,
            port=parsed_url.port or 443,
            configuration=QuicConfiguration(is_client=True, alpn_protocols=H3_ALPN),
            create_protocol=H3Transport,
        ) as transport:
    
            async with httpx.AsyncClient(
                transport=cast(httpx.AsyncBaseTransport, transport)
            ) as client:
    
    
                _params = {
                    'method': method,
                    'url': url,
                    'headers': headers or {},
                }
    
                if (method.lower() != 'get') \
                        and (data is not None):
                    _params['data'] = data
    
                if query_params is not None:
                    _params['params'] = query_params
    
                return await client.request(**_params)