Here is an article on how to modify an existing Node.js route to return trades from the TRON network instead of Binance:
Modifying the Binance API Route to Return TRON Trades
As a developer working on Ethereum and TRON, you are probably familiar with the public Binance API for returning trades. However, its current implementation returns trades from the Binance platform. To modify this route to return trades from the TRON network, we will need to make some modifications.
Step 1: Identify the Tron API Endpoints
Before we begin, let’s identify the relevant endpoints on the TRON blockchain for returning trades:
- TRC-20 Token Trading API:
GET /api/v2/trades(returns trade data for a specific token and pair)
- TRX Token Trading API

:
GET /api/v1/trades(returns trade data for a specific token and pair)
We will use the TRX token trading API endpoint as a starting point.
Step 2: Modify the Binance API route to return TRON trades
To return TRON trades, we need to make the following changes to your existing route:
- Update the
endpointparameter in theGET /api/v3/tradesresponse to include the new endpoint.
const response = wait client.get(${endpoint}/trades);
- Modify the
paramsobject to pass the relevant query parameters, such as:
from: specifies the token and pair you want to get trades for (e.g. TRX/ETH)
to: specifies the token and pair you are interested in getting trades for
response = wait client.get(${endpoint}/trades?from=TRX&to=ETH);
- Update the `
dataproperty of each negotiation subject to include relevant information, such as the traded value.
Step 3: Update the Node.js routing code
Here is a sample code snippet that shows how you can modify your existing route to return TRON trades:
${process.env.TRX_API_ENDPOINT}/tradesconst express = require('express');
const app = express();
const { Client } = require('@truffle/truffle-client'); // Import the Truffle client library
// Configure a new API client instance with the TRX Token Trading API endpoint and token
const trxClient = new Client({
host: '
token: 'YOUR_TRON_TOKEN'
});
app.get('/trades', async (req, res) => {
try {
const tradesResponse = wait trxClient.get(
);Trade: ${trade.id} - From: TRX, To: ETH, Amount: ${trade.amount}// Loop through each trade and get the relevant information
tradesResponse.data.forEach((trade) => {
// Assuming the trade object has an 'amount' property with an agreed value
console.log(
);Server listening on port ${process.env.PORT}});
res.json(tradesResponse);
} catch (error) {
console.error(error);
res.status(500).json({ message: 'Error getting trades' });
}
});
app.listen(process.env.PORT, () => {
console.log(
);});
In this modified code snippet:
- We create a new API client instance with an endpoint and an API token to trade TRX tokens.
- We define a /trades
route that returns TRON trades by calling thegetmethod on the TRX client endpoint for the specified trade type (in this case TRX/ETH).
- We loop through each trade object and extract relevant information, such as the traded value.
- Finally, we return the extracted data in a JSON response.
This code snippet shows how you can modify your existing route to return TRON trades. Be sure to replaceYOUR_TRON_TOKEN` with the actual symbol of your Tron token (e.g. TRX).