/
downloadOperationsHistoryCSV

downloadOperationsHistoryCSV

Auth: true

params:

params: { currencyId: { type: 'string', optional: true, }, type: { type: 'string', optional: true, }, from: { type: 'string', optional: false, }, to: { type: 'string', optional: false, }, },

Responce:

A string is returned in Base64 format with the following encoded fields

For trading (columns):

  1. Timestamp - standart date format

Example: Mon May 13 2024 14:24:31 GMT+0000 (Coordinated Universal Time)

  1. Market pair - string with base and quotation currency take from trade

Example: BNB-BTC

  1. Side - Selects one of the values "buy", "sell" values according to the following rule

ctx.meta.user.id === trade?.buyUserId ? 'buy' : 'sell';

Example: sell OR buy

  1. Price - take from trade

Example: 0.112

  1. Amount - take from trade

Example: 0.101

  1. Total - take from trade

Example: 0.011312

  1. Fee - The value and accuracy are taken by the following formula

const fee = side === trade?.makerOrderSide ? side === 'buy' ? trade.maker_fee.toFixed(currenciesMap[base_currency]) : trade.maker_fee.toFixed(currenciesMap[quote_currency]) : side === 'buy' ? trade.taker_fee.toFixed(currenciesMap[base_currency]) : trade.taker_fee.toFixed(currenciesMap[quote_currency])

Example: 0.00022624

  1. Role - The value is taken by the following formula

Example: Maker OR Taker

For Trasactions (columns): in work

 

Logic:

Steps:

  1. We check whether the specified date from which to take data does not exceed 3 months from today

  2. We check what type of operations is being sought, trading or transactions. type === 'trading' OR else

  3. Depending on the required data, we form requests for trades or for operations to receive them based on a time interval.

  4. Form an array of objects with keys that correspond to the column names and values for them.

  5. Passing an array through a converter from an array of objects to a csv string

  6. We convert the CSV string to base64 and return it to the front end to create a file and send it to the client

The frontend can generate text for a file in this way:

Trading

A query is formed to the Trade table and, based on the data, an array of objects with data in the following form is formed:

currenciesMap - designed to take currency parameters and not make unnecessary queries to the database

Converting to CSV

To convert to CSV format, there is a function that takes an array of objects of the same type. At the beginning, it forms the name of the columns taking the keys of the object, after which it searches through all objects taking the key values and writing them to a string in the format for csv

Related content

2.4.1 Backend Changelog (20 May 2024)
2.4.1 Backend Changelog (20 May 2024)
Read with this
Queries Mutations Subscriptions - Frontend v2.10.0+
Queries Mutations Subscriptions - Frontend v2.10.0+
More like this
WhiteBit
More like this
2.5.0 Frontend Changelog (16 May 2024)
2.5.0 Frontend Changelog (16 May 2024)
More like this
Using GraphQL API for trading from third-party application
Using GraphQL API for trading from third-party application
More like this
6.4.2. Add New Market
6.4.2. Add New Market
More like this