Exchange API

API Endpoint

https://tronpulse.io/api/exchange

Headers

Exchange - Create Order

POST /create_order

Body

Response

{
    "status_code": "order_created",
    "data": {
        "order_id": "5527691da5524a45bb4bf268b87adc81"
    }
}

Code Example

// TronWeb library to interact with TRON blockchain
const tronweb = window.tronWeb;

const order = {
    "receiver": tronweb.defaultAddress.base58, // address to receiver energy
    "resource_type": "energy",
    "amount": 1000000, // amount of resource to purchase
    "duration": "3d", // allowed values are 1h, 6h, 1d, 3d to 30d
    "price": 55 // unit price in SUN
}

// API endpoint
const url = 'https://tronpulse.io/api/exchange';

const options = {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        "Api-Key": "your-api-key"
    }
};

// Request API to compute order price
options.body = JSON.stringify({"order": order});
fetch(url + "/get_quote", options)
    .then(async response => {
        if (response.ok) {
            const quote = await response.json();
            // Build and sign payment transaction
            const tx = await tronweb.transactionBuilder.sendTrx(quote.data.payment_address, quote.data.order_total_price);
            const signed_tx = await tronweb.trx.sign(tx, private_key);
            // Request API to create order
            options.body = JSON.stringify({"order": order, "signed_tx": signed_tx});
            fetch(url + "/create_order", options)
                .then(async response => {
                    if (response.ok) {
                        // order successfuly created
                        const data = await response.json()
                        console.log(data)
                    }
                    else {
                        // request failed, display error
                        const data = await response.json()
                        console.log(data)
                    }
                })
        }
    })

Exchange - Get Order

POST /get_order

Body

Response

{
    "data": {
        "orders": [
            {
                "created_timestamp": 1713631199000,
                "order_id": "5527691da5524a45bb4bf268b87adc81",
                "status": "open",
                "receiver": "********",
                "duration": "3d",
                "resource_type": "energy",
                "amount": 1000000,
                "filled_amount": 0
            }
        ]
    }
}

Code Example

// TronWeb library to interact with TRON blockchain
const tronweb = window.tronWeb;

const order_id = "5527691da5524a45bb4bf268b87adc81" // or use 'open' to get all open orders

const url = 'https://tronpulse.io/api/exchange';

const options = {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        "Api-Key": "your-api-key"
    },
    body: JSON.stringify({"order_id": order_id})
};

// Request API to get orders
fetch(url + "/get_order", options)
    .then(async response => {
        if (response.ok) {
            // display orders
            const data = await response.json();
            console.log(data)
        }
        else {
            // request failed, display error
            const data = await response.json();
            console.log(data)
        }
    })

Exchange - Cancel Order

POST /cancel_order

Body

Response

{
    "status_code": "order_cancelled",
    "data": {
        "order_id": "5527691da5524a45bb4bf268b87adc81",
        "refund_tx": "******",
        "refund_amount": 164.0
    }
}

Code Example

// TronWeb library to interact with TRON blockchain
const tronweb = window.tronWeb;

const order_id = "5527691da5524a45bb4bf268b87adc81"

const url = 'https://tronpulse.io/api/exchange';

const options = {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        "Api-Key": "your-api-key"
    },
    body: JSON.stringify({"order_id": order_id})
};

// Request API to cancel order
fetch(url + "/cancel_order", options)
    .then(async response => {
        if (response.ok) {
            // order successfully cancelled 
            const data = await response.json();
            console.log(data)
        }
        else {
            // request failed, display error
            const data = await response.json();
            console.log(data)
        }
    })

Last updated