Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add weighted averages report #246

Merged
merged 18 commits into from
Jan 6, 2023

Conversation

ZIMkaRU
Copy link
Member

@ZIMkaRU ZIMkaRU commented Jan 6, 2023

This PR adds the weighted averages report https://www.investopedia.com/terms/w/weightedaverage.asp. The idea is to select a time period for trades and calculates for each specific pair:

  • Buy
    • Weighted average buying price (Only sum up buying trades)
    • Amount bought (Only sum up buying trades)
  • Sell
    • Weighted average Selling price (Only sum up selling trades)
    • Amount Sold (Only sum up selling trades)
  • Cumulative
    • Weighted average price (Both buy and sell trades)
    • Final amount (Amount bought - amount sold)

Basic changes:

  • Adds getWeightedAveragesReport method to the main service
  • Adds getWeightedAveragesReportCsv method to the main service
  • Adds corresponding test coverage

Request example:

{
  "auth": {
    "token": "the-user-token"
  },
  "method": "getWeightedAveragesReport",
  "params": {
    // "symbol": ["tIOTUSD", "tETHUSD"] - we can pass array of pairs for filtering, or skip it param if no necessary
    "start": 1576339450000,
    "end": 1576521468000
  }
}

Response example:

{
  "jsonrpc": "2.0",
  "result": [
    {
      "symbol": "tNEOUSD",
      "buyingWeightedPrice": 8.311941599594718,
      "buyingAmount": 6.70696301,
      "sellingWeightedPrice": 0,
      "sellingAmount": 0,
      "cumulativeWeightedPrice": 8.311941599594718,
      "cumulativeAmount": 6.70696301
    },
    {
      "symbol": "tXRPUSD",
      "buyingWeightedPrice": 0.2119784948940276,
      "buyingAmount": 52.18668382,
      "sellingWeightedPrice": 0.21406,
      "sellingAmount": -25.78324287,
      "cumulativeWeightedPrice": 0.2099458828650097,
      "cumulativeAmount": 26.403440950000004
    },
    {
      "symbol": "tIOTUSD",
      "buyingWeightedPrice": 0.18546723624755995,
      "buyingAmount": 203.9278243,
      "sellingWeightedPrice": 0.18711,
      "sellingAmount": -101.45977508,
      "cumulativeWeightedPrice": 0.18384063710664833,
      "cumulativeAmount": 102.46804922
    },
    {
      "symbol": "tETHUSD",
      "buyingWeightedPrice": 139.93966231409323,
      "buyingAmount": 0.29878416,
      "sellingWeightedPrice": 0,
      "sellingAmount": 0,
      "cumulativeWeightedPrice": 139.93966231409323,
      "cumulativeAmount": 0.29878416
    }
  ],
  "id": null
}

Request example:

{
  "auth": {
    "token": "the-user-token"
  },
  "method": "getMultipleCsv",
  "params": {
    "language": "en",
    "multiExport": [
      {
        "symbol": ["tIOTUSD", "tETHUSD"],
        "start": 1576339450000,
        "end": 1576521468000,
        "timezone": "Etc/UTC",
        "dateFormat": "DD-MM-YY",
        "milliseconds": false,
        "method": "getWeightedAveragesReportCsv"
      }
    ]
  }
}

Response example:

{
  "jsonrpc": "2.0",
  "result": {
    "isSaveLocaly": true,
    "localCsvFolderPath": "/home/vladimir/projects/bitfinex/bfx-reports-framework/csv",
    "remoteCsvUrn": null
  },
  "id": null
}

CSV example:

Screenshot from 2023-01-05 07-37-31

@ZIMkaRU ZIMkaRU force-pushed the feature/add-weighted-averages-report branch from 911f526 to 6ffbfc8 Compare January 6, 2023 12:27
Copy link
Contributor

@ezewer ezewer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants