FINTERACTIONS.COM RESTAPI
  • OVERVIEW
  • VERIFICATION
  • SECURITIES
  • TRANSACTIONS
  • ORDERS
  • SIMPLIFIED ORDERS
  • BOOK SNAPSHOT
Powered by GitBook
On this page

TRANSACTIONS

This section provides an overview of the REST API endpoint for retrieving trades for a specific user. The endpoint allows subscribers to get a list of trades, with an optional parameter to specify the starting time.

Endpoint

1. Get User Trades

  • HTTP Request Type: GET

  • Route: /firestapi/transactions/trades/:userid

  • URL / Body Parameters:

    • :userid - The user ID for whom the trades are being retrieved.

    • fromtime (optional) - The starting time in milliseconds since the epoch (January 1, 1970).

  • Info: This endpoint returns trades for a specific user. It will return a maximum of 1000 records.

  • HTTPS Body Example: N/A

  • WS Example:

json

{
  "type": "get_trades",
  "userid": "12345",
  "fromtime": 1671195975792
}

Example Implementation in Express.js

Here's an example of how you might implement this endpoint in an Express.js application:

javascript

const express = require('express');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const session = require('express-session');

const app = express();

app.use(bodyParser.json());
app.use(cookieParser());
app.use(session({
  secret: 'your_secret_key',
  resave: false,
  saveUninitialized: true,
  cookie: { secure: true } // Use secure cookies in production
}));

// Dummy trade data for demonstration purposes
const trades = [
  { userid: '12345', tradeid: '1', symbol: 'BTCUSD', timestamp: 1671195975792, amount: 1, price: 50000 },
  // Add more trades as needed
];

// Get User Trades
app.get('/firestapi/transactions/trades/:userid', (req, res) => {
  const { userid } = req.params;
  const { fromtime } = req.query;

  let userTrades = trades.filter(trade => trade.userid === userid);

  if (fromtime) {
    const fromTimeNum = parseInt(fromtime, 10);
    userTrades = userTrades.filter(trade => trade.timestamp >= fromTimeNum);
  }

  userTrades = userTrades.slice(0, 1000); // Return a maximum of 1000 records

  res.status(200).json(userTrades);
});

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
  console.log(`Server is running on port ${PORT}`);
});

This example sets up the specified route using Express.js and handles retrieving trades for a specific user, with optional filtering by starting time. It includes necessary validations and error handling for the endpoint.

PreviousSECURITIESNextORDERS

Last updated 9 months ago