Class CassandreStrategy

All Implemented Interfaces:
CassandreStrategyInterface
Direct Known Subclasses:
BasicCassandreStrategy

public abstract class CassandreStrategy extends CassandreStrategyImplementation
CassandreStrategy is the class that every strategy used by user (BasicCassandreStrategy must extend. It contains methods to access data and manage orders, trades, positions.

These are the classes used by Cassandre to manage a position. - CassandreStrategyInterface list the methods a strategy type must implement to be able to interact with the Cassandre framework. - CassandreStrategyConfiguration contains the configuration of the strategy. - CassandreStrategyDependencies contains all the dependencies required by a strategy and provided by the Cassandre framework. - CassandreStrategyImplementation is the default implementation of CassandreStrategyInterface, this code manages the interaction between Cassandre framework and a strategy. - CassandreStrategy (class) is the class that every strategy used by user (BasicCassandreStrategy must extend. It contains methods to access data and manage orders, trades, positions. There are the classes used by the developer. - CassandreStrategy (interface) is the annotation allowing you Cassandre to recognize a user strategy. - BasicCassandreStrategy - User inherits this class this one to make a basic strategy.

  • Constructor Details

    • CassandreStrategy

      public CassandreStrategy()
  • Method Details

    • getTradeAccount

      public final Optional<AccountDTO> getTradeAccount()
      Returns the trade account selected by the strategy developer.
      Returns:
      trade account
    • getTradeAccountBalances

      public final Map<CurrencyDTO,BalanceDTO> getTradeAccountBalances()
      Returns trade account balances.
      Returns:
      trade account balances
    • getAccounts

      public final Map<String,AccountDTO> getAccounts()
      Returns list of accounts.
      Returns:
      accounts
    • getAccountByAccountId

      public final Optional<AccountDTO> getAccountByAccountId(String accountId)
      Search and return an account by its id.
      Parameters:
      accountId - account id
      Returns:
      account
    • getAmountsLockedByPosition

      public final Map<Long,CurrencyAmountDTO> getAmountsLockedByPosition()
      Returns the amounts locked by position.
      Returns:
      amounts locked
    • getAmountsLockedByCurrency

      public final BigDecimal getAmountsLockedByCurrency(CurrencyDTO currency)
      Returns the amounts locked for a specific currency.
      Parameters:
      currency - currency
      Returns:
      amounts locked
    • getLastTickers

      public final Map<CurrencyPairDTO,TickerDTO> getLastTickers()
      Return last received tickers.
      Returns:
      ticker
    • getImportedCandles

      public final List<CandleDTO> getImportedCandles()
      Return the list of imported candles (ordered by timestamp).
      Returns:
      imported candles
    • getImportedCandles

      public final List<CandleDTO> getImportedCandles(@NonNull @NonNull CurrencyPairDTO currencyPair)
      Return the list of imported candles for a specific currency pair (ordered by timestamp).
      Parameters:
      currencyPair - currency pair
      Returns:
      imported candles
    • getImportedTickers

      public final List<TickerDTO> getImportedTickers()
      Return the list of imported tickers (ordered by timestamp).
      Returns:
      imported tickers
    • getImportedTickers

      public final List<TickerDTO> getImportedTickers(@NonNull @NonNull CurrencyPairDTO currencyPair)
      Return the list of imported tickers for a specific currency pair (ordered by timestamp).
      Parameters:
      currencyPair - currency pair
      Returns:
      imported tickers
    • getOrders

      public final Map<String,OrderDTO> getOrders()
      Returns list of orders (order id is key).
      Returns:
      orders
    • getOrderByOrderId

      public final Optional<OrderDTO> getOrderByOrderId(String orderId)
      Get an order by its order id.
      Parameters:
      orderId - order id
      Returns:
      order
    • getTrades

      public final Map<String,TradeDTO> getTrades()
      Returns list of trades (trade id is key).
      Returns:
      trades
    • getTradeByTradeId

      public final Optional<TradeDTO> getTradeByTradeId(String tradeId)
      Get a trade by its trade id.
      Parameters:
      tradeId - trade id
      Returns:
      trade
    • getPositions

      public final Map<Long,PositionDTO> getPositions()
      Returns list of positions (position id the key).
      Returns:
      positions
    • getPositionByPositionId

      public final Optional<PositionDTO> getPositionByPositionId(long positionId)
      Get a position by its id.
      Parameters:
      positionId - position id
      Returns:
      position
    • getGains

      public final Map<CurrencyDTO,GainDTO> getGains()
      Returns gains of all positions of the strategy.
      Returns:
      total gains
    • createBuyMarketOrder

      public OrderCreationResultDTO createBuyMarketOrder(CurrencyPairDTO currencyPair, BigDecimal amount)
      Creates a buy market order.
      Parameters:
      currencyPair - currency pair
      amount - amount
      Returns:
      order result (order id or error)
    • createSellMarketOrder

      public OrderCreationResultDTO createSellMarketOrder(CurrencyPairDTO currencyPair, BigDecimal amount)
      Creates a sell market order.
      Parameters:
      currencyPair - currency pair
      amount - amount
      Returns:
      order result (order id or error)
    • createBuyLimitOrder

      public OrderCreationResultDTO createBuyLimitOrder(CurrencyPairDTO currencyPair, BigDecimal amount, BigDecimal limitPrice)
      Creates a buy limit order.
      Parameters:
      currencyPair - currency pair
      amount - amount
      limitPrice - the highest acceptable price
      Returns:
      order result (order id or error)
    • createSellLimitOrder

      public OrderCreationResultDTO createSellLimitOrder(CurrencyPairDTO currencyPair, BigDecimal amount, BigDecimal limitPrice)
      Creates a sell limit order.
      Parameters:
      currencyPair - currency pair
      amount - amount
      limitPrice - the lowest acceptable price
      Returns:
      order result (order id or error)
    • createLongPosition

      public PositionCreationResultDTO createLongPosition(CurrencyPairDTO currencyPair, BigDecimal amount, PositionRulesDTO rules)
      Creates a long position with its associated rules. Long position is nothing but buying share. If you are bullish (means you think that price of X share will rise) at that time you buy some amount of Share is called taking Long Position in share.
      Parameters:
      currencyPair - currency pair
      amount - amount
      rules - rules
      Returns:
      position creation result
    • createShortPosition

      public PositionCreationResultDTO createShortPosition(CurrencyPairDTO currencyPair, BigDecimal amount, PositionRulesDTO rules)
      Creates a short position with its associated rules. Short position is nothing but selling share. If you are bearish (means you think that price of xyz share are going to fall) at that time you sell some amount of share is called taking Short Position in share.
      Parameters:
      currencyPair - currency pair
      amount - amount
      rules - rules
      Returns:
      position creation result
    • updatePositionRules

      public void updatePositionRules(long positionUid, PositionRulesDTO newRules)
      Update position rules.
      Parameters:
      positionUid - position uid
      newRules - new rules
    • setAutoClose

      public void setAutoClose(long positionUid, boolean value)
      Set auto close value on a specific position. If true, Cassandre will close the position according to rules. if false, Cassandre will never close the position.
      Parameters:
      positionUid - position uid
      value - auto close value
    • closePosition

      public void closePosition(long positionUid)
      Close position (no matter the rules). The closing will happen when the next ticker arrives.
      Parameters:
      positionUid - position uid
    • getEstimatedBuyableAmount

      public final Optional<BigDecimal> getEstimatedBuyableAmount(CurrencyAmountDTO amountToUse, CurrencyDTO targetCurrency)
      Returns the amount of a currency I can buy with a certain amount of another currency.
      Parameters:
      amountToUse - amount you want to use buy the currency you want
      targetCurrency - the currency you want to buy
      Returns:
      amount of currencyWanted you can buy with amountToUse
    • getEstimatedBuyingCost

      public final Optional<CurrencyAmountDTO> getEstimatedBuyingCost(CurrencyPairDTO currencyPair, BigDecimal amount)
      Returns the cost of buying an amount of a currency pair.
      Parameters:
      currencyPair - currency pair
      amount - amount
      Returns:
      cost
    • canBuy

      public final boolean canBuy(CurrencyPairDTO currencyPair, BigDecimal amount)
      Returns true if we have enough assets to buy.
      Parameters:
      currencyPair - currency pair
      amount - amount
      Returns:
      true if we have enough assets to buy
    • canBuy

      public final boolean canBuy(CurrencyPairDTO currencyPair, BigDecimal amount, BigDecimal minimumBalanceLeftAfter)
      Returns true if we have enough assets to buy.
      Parameters:
      currencyPair - currency pair
      amount - amount
      minimumBalanceLeftAfter - minimum balance that should be left after buying
      Returns:
      true if we have enough assets to buy
    • canBuy

      public final boolean canBuy(AccountDTO account, CurrencyPairDTO currencyPair, BigDecimal amount)
      Returns true if we have enough assets to buy.
      Parameters:
      account - account
      currencyPair - currency pair
      amount - amount
      Returns:
      true if we have enough assets to buy
    • canBuy

      public final boolean canBuy(AccountDTO account, CurrencyPairDTO currencyPair, BigDecimal amount, BigDecimal minimumBalanceLeftAfter)
      Returns true if we have enough assets to buy and if minimumBalanceAfter is left on the account after.
      Parameters:
      account - account
      currencyPair - currency pair
      amount - amount
      minimumBalanceLeftAfter - minimum balance that should be left after buying
      Returns:
      true if we have enough assets to buy
    • canSell

      public final boolean canSell(CurrencyDTO currency, BigDecimal amount)
      Returns true if we have enough assets to sell.
      Parameters:
      currency - currency
      amount - amount
      Returns:
      true if we have enough assets to sell
    • canSell

      public final boolean canSell(CurrencyDTO currency, BigDecimal amount, BigDecimal minimumBalanceLeftAfter)
      Returns true if we have enough assets to sell.
      Parameters:
      currency - currency
      amount - amount
      minimumBalanceLeftAfter - minimum balance that should be left after selling
      Returns:
      true if we have enough assets to sell
    • canSell

      public final boolean canSell(AccountDTO account, CurrencyDTO currency, BigDecimal amount)
      Returns true if we have enough assets to sell.
      Parameters:
      account - account
      currency - currency pair
      amount - amount
      Returns:
      true if we have enough assets to sell
    • canSell

      public final boolean canSell(AccountDTO account, CurrencyDTO currency, BigDecimal amount, BigDecimal minimumBalanceLeftAfter)
      Returns true if we have enough assets to sell and if minimumBalanceAfter is left on the account after.
      Parameters:
      account - account
      currency - currency
      amount - amount
      minimumBalanceLeftAfter - minimum balance that should be left after selling
      Returns:
      true if we have enough assets to sell