bbgo icon indicating copy to clipboard operation
bbgo copied to clipboard

Strategy metric panel

Open c9s opened this issue 3 years ago • 6 comments

Requirement

In this panel, we will render the metrics of each running strategy. There are some common metrics we are interested in:

  1. total net profit (gross profit - gross loss - trading fee)
  2. gross profit (total profit)
  3. gross loss (total loss)
  4. trading volume
  5. running time

Some panel could be different if the strategy is not a position-based strategy, for example, the grid strategy.

For grid strategy, we're interested in:

  1. How many grids are placed.
  2. Upper price and lower price. (the top of the grid and the bottom of the grid)
  3. The number of arbitrages.
  4. Total arbitrage profits

Implementation

Hence, we need to add a new interface for strategies to export their metrics.

type MetricsExporter interface {
    Metrics() interface{}
}

And each strategy can export their own metrics structs that could be marshalled into JSON format for the front-end application to render.

And the metrics could be fetched from an endpoint like:

https://localhost:3000/exchangeStrategies/metrics

And the response structure could be something like:

[
    { "instanceID": "....", "strategy": "grid", "symbol": "BTCUSDT", "stats": {....}, "status": "RUNNING" },
    { "instanceID": "....", "strategy": "bollmaker", "symbol": "BNBUSDT", "stats": {....}, "status": "STOPPED" },
]

c9s avatar May 31 '22 05:05 c9s

I’m interested in this task and will contribute the frontend part.

jundesu avatar May 31 '22 09:05 jundesu

@jundesu thank you!

c9s avatar May 31 '22 09:05 c9s

Here’s my draft. Please review it. image

  1. The grid strategy algorithm is easier than other strategies, so I want to implement it first.
  2. I study other similar products. They all provide the information on my draft. I think the information is necessary for the grid strategy.

If you agree with the draft, I will design the desired json response. Thank you.

jundesu avatar Jun 10 '22 10:06 jundesu

@c9s According to my draft, could bbgo server provide the api response for grid strategy?

[
  {
    "id":"uuid",
    "instanceID": "....",
    "strategy": "grid",
    "symbol": "BTCUSDT",
    "metrics": {
      "oneDayArbs": 0,
      "totalArbs": 3,
      "investment": 100,
      "totalProfits": 5.6,
      "gridProfits": 2.5,
      "floatingPNL": 3.1, 
      "currentPrice": 29000,
      "lowestPrice": 25000,
      "highestPrice": 35000
    },
    "status": "RUNNING",
    "startTime": 1654938187102
  }
]

jundesu avatar Jun 11 '22 09:06 jundesu

yes, It's something similar: (I renamed the metrics to stats)

[
  {
    "id":"uuid",
    "instanceID": "....",
    "strategy": "grid",
    "grid": {
         "symbol": "BTCUSDT",
         ..... other grid strategy settings
    },
    "stats": {
      "oneDayArbs": 0,
      "totalArbs": 3,
      "investment": 100,
      "totalProfits": 5.6,
      "gridProfits": 2.5,
      "floatingPNL": 3.1, 
      "currentPrice": 29000,
      "lowestPrice": 25000,
      "highestPrice": 35000
    },
    "status": "RUNNING",
    "startTime": 1654938187102
  }
]

c9s avatar Jun 11 '22 09:06 c9s

our grid strategy config looks like:

exchangeStrategies:

- on: binance
  grid:
    symbol: BTCUSDT
    quantity: 0.001
    # scaleQuantity:
    #   byPrice:
    #     exp:
    #       domain: [20_000, 30_000]
    #       range: [0.2, 0.001]
    gridNumber: 20
    profitSpread: 1000.0  # The profit price spread that you want to add to your sell order when your buy order is executed
    upperPrice: 30_000.0
    lowerPrice: 28_000.0
    # long: true  # The sell order is submitted in the same order amount as the filled corresponding buy order, rather than the same quantity.

c9s avatar Jun 11 '22 09:06 c9s