Class GenericCassandreStrategy

    • Field Detail

      • currencyMapper

        protected final CurrencyMapper currencyMapper
        Currency mapper.
      • orderMapper

        protected final OrderMapper orderMapper
        Order mapper.
      • tradeMapper

        protected final TradeMapper tradeMapper
        Trade mapper.
      • positionMapper

        protected final PositionMapper positionMapper
        Position mapper.
      • tickerMapper

        protected final TickerMapper tickerMapper
        Ticker mapper.
      • logger

        protected final org.slf4j.Logger logger
        Logger.
      • positionFlux

        protected PositionFlux positionFlux
        Position flux.
      • orderRepository

        protected OrderRepository orderRepository
        Order repository.
      • tradeRepository

        protected TradeRepository tradeRepository
        Trade repository.
      • positionRepository

        protected PositionRepository positionRepository
        Position repository.
      • exchangeService

        protected ExchangeService exchangeService
        Exchange service.
      • tradeService

        protected TradeService tradeService
        Trade service.
      • positionService

        protected PositionService positionService
        Position service.
    • Constructor Detail

      • GenericCassandreStrategy

        public GenericCassandreStrategy()
    • Method Detail

      • getStrategyDTO

        public final StrategyDTO getStrategyDTO()
        Getter strategyDTO.
        Returns:
        strategyDTO
      • getExchangeService

        public final ExchangeService getExchangeService()
        Getter exchangeService.
        Returns:
        exchangeService
      • getAccounts

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

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

        public final Map<Long,​CurrencyAmountDTO> getAmountsLockedByPosition()
        Getter amountsLockedByPosition.
        Returns:
        amountsLockedByPosition
      • getAmountsLockedByCurrency

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

        public final Optional<TickerDTO> getLastTickerByCurrencyPair​(CurrencyPairDTO currencyPair)
        Return the last ticker for a currency pair.
        Parameters:
        currencyPair - currency pair
        Returns:
        last ticker received
      • getLastPriceForCurrencyPair

        public final BigDecimal getLastPriceForCurrencyPair​(CurrencyPairDTO currencyPair)
        Returns the last price received for a currency pair.
        Parameters:
        currencyPair - currency pair
        Returns:
        last price
      • getImportedTickers

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

        public final List<TickerDTO> getImportedTickers​(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.
        Returns:
        orders
      • getOrderByOrderId

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

        public final Map<String,​TradeDTO> getTrades()
        Returns list of trades.
        Returns:
        trades
      • getTradeByTradeId

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

        public final Map<Long,​PositionDTO> getPositions()
        Returns list of positions.
        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.
        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 id,
                                        PositionRulesDTO newRules)
        Update position rules.
        Parameters:
        id - position id
        newRules - new rules
      • closePosition

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

        public final Optional<BigDecimal> getEstimatedBuyableAmount​(CurrencyAmountDTO amountToUse,
                                                                    CurrencyDTO currencyWanted)
        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
        currencyWanted - 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 minimumBalanceAfter)
        Returns true if we have enough assets to buy.
        Parameters:
        currencyPair - currency pair
        amount - amount
        minimumBalanceAfter - 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 minimumBalanceAfter)
        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
        minimumBalanceAfter - 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 minimumBalanceAfter)
        Returns true if we have enough assets to sell.
        Parameters:
        currency - currency
        amount - amount
        minimumBalanceAfter - 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 minimumBalanceAfter)
        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
        minimumBalanceAfter - minimum balance that should be left after selling
        Returns:
        true if we have enough assets to sell