Open-Trader/opentrader

Check enough funds before starting the bot

Ouverte

#105 ouverte le 30 janv. 2025

 (0 commentaire) (0 réaction) (0 personne assignée)TypeScript (319 forks)auto 404
enhancementgood first issuehelp wanted

Métriques du dépôt

Stars
 (2 749 étoiles)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

Description

We need a mechanism for a strategy to indicate how much funding it does require to operate.

Proposed solution

Add fundsRequired property to the strategy template:

function* myStrategy() {
  if (Math.random() > 0.5) {
    yield buy({ quantity: 1 })
  } else {
    yield sell({ quantity: 1 })
  }
}

myStrategy.fundsRequired = {
  ETH: 1
}

We should also be able to calculate the required funds based on bot settings:

function* myStrategy(ctx) {
  const { settings } = ctx;

  if (Math.random() > 0.5) {
    yield buy({ quantity: settings.ETH.quantity })
  } else {
    yield sell({ quantity: settings.ETH.quantity })
  }
}

myStrategy.fundsRequired = (bot) => {
  return {
    ETH: bot.settings.quantity
  }
}

Flow

When invoking start command in tRPC we need to:

  1. Fetch portfolio of the current exchange.
  2. Parse the fundsRequired of the strategy. If it's not defined, we skip everything below.
  3. Check if there are enough funds to run the strategy. If not, throw an error: "Not enough funds to run the strategy. Your portfolio: 0 USDT, 0 ETH. Required: 100 USDT, 1 ETH"
  4. Start the bot.

Guide contributeur