Class CassandreStrategy
- All Implemented Interfaces:
CassandreStrategyInterface
- Direct Known Subclasses:
BasicCassandreStrategy
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.
-
Field Summary
Fields inherited from class tech.cassandre.trading.bot.strategy.internal.CassandreStrategyImplementation
configuration, dependencies, lastTickers, userAccounts
Fields inherited from class tech.cassandre.trading.bot.util.base.Base
ACCOUNT_MAPPER, CANDLE_MAPPER, CURRENCY_MAPPER, logger, ORDER_MAPPER, POSITION_MAPPER, STRATEGY_MAPPER, TICKER_MAPPER, TRADE_MAPPER, UTIL_MAPPER
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
canBuy
(AccountDTO account, CurrencyPairDTO currencyPair, BigDecimal amount) Returns true if we have enough assets to buy.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.final boolean
canBuy
(CurrencyPairDTO currencyPair, BigDecimal amount) Returns true if we have enough assets to buy.final boolean
canBuy
(CurrencyPairDTO currencyPair, BigDecimal amount, BigDecimal minimumBalanceLeftAfter) Returns true if we have enough assets to buy.final boolean
canSell
(AccountDTO account, CurrencyDTO currency, BigDecimal amount) Returns true if we have enough assets to sell.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.final boolean
canSell
(CurrencyDTO currency, BigDecimal amount) Returns true if we have enough assets to sell.final boolean
canSell
(CurrencyDTO currency, BigDecimal amount, BigDecimal minimumBalanceLeftAfter) Returns true if we have enough assets to sell.void
closePosition
(long positionUid) Close position (no matter the rules).createBuyLimitOrder
(CurrencyPairDTO currencyPair, BigDecimal amount, BigDecimal limitPrice) Creates a buy limit order.createBuyMarketOrder
(CurrencyPairDTO currencyPair, BigDecimal amount) Creates a buy market order.createLongPosition
(CurrencyPairDTO currencyPair, BigDecimal amount, PositionRulesDTO rules) Creates a long position with its associated rules.createSellLimitOrder
(CurrencyPairDTO currencyPair, BigDecimal amount, BigDecimal limitPrice) Creates a sell limit order.createSellMarketOrder
(CurrencyPairDTO currencyPair, BigDecimal amount) Creates a sell market order.createShortPosition
(CurrencyPairDTO currencyPair, BigDecimal amount, PositionRulesDTO rules) Creates a short position with its associated rules.final Optional<AccountDTO>
getAccountByAccountId
(String accountId) Search and return an account by its id.final Map<String,
AccountDTO> Returns list of accounts.final BigDecimal
getAmountsLockedByCurrency
(CurrencyDTO currency) Returns the amounts locked for a specific currency.final Map<Long,
CurrencyAmountDTO> Returns the amounts locked by position.final Optional<BigDecimal>
getEstimatedBuyableAmount
(CurrencyAmountDTO amountToUse, CurrencyDTO targetCurrency) Returns the amount of a currency I can buy with a certain amount of another currency.final Optional<CurrencyAmountDTO>
getEstimatedBuyingCost
(CurrencyPairDTO currencyPair, BigDecimal amount) Returns the cost of buying an amount of a currency pair.final Map<CurrencyDTO,
GainDTO> getGains()
Returns gains of all positions of the strategy.Return the list of imported candles (ordered by timestamp).getImportedCandles
(@NonNull CurrencyPairDTO currencyPair) Return the list of imported candles for a specific currency pair (ordered by timestamp).Return the list of imported tickers (ordered by timestamp).getImportedTickers
(@NonNull CurrencyPairDTO currencyPair) Return the list of imported tickers for a specific currency pair (ordered by timestamp).final Map<CurrencyPairDTO,
TickerDTO> Return last received tickers.getOrderByOrderId
(String orderId) Get an order by its order id.Returns list of orders (order id is key).final Optional<PositionDTO>
getPositionByPositionId
(long positionId) Get a position by its id.final Map<Long,
PositionDTO> Returns list of positions (position id the key).final Optional<AccountDTO>
Returns the trade account selected by the strategy developer.final Map<CurrencyDTO,
BalanceDTO> Returns trade account balances.getTradeByTradeId
(String tradeId) Get a trade by its trade id.Returns list of trades (trade id is key).void
setAutoClose
(long positionUid, boolean value) Set auto close value on a specific position.void
updatePositionRules
(long positionUid, PositionRulesDTO newRules) Update position rules.Methods inherited from class tech.cassandre.trading.bot.strategy.internal.CassandreStrategyImplementation
accountsUpdates, getConfiguration, getLastPriceForCurrencyPair, getLastTickerByCurrencyPair, initializeAccounts, ordersUpdates, positionsUpdates, setConfiguration, setDependencies, tickersUpdates, tradesUpdates, updatePositionsWithTickersUpdates
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface tech.cassandre.trading.bot.strategy.internal.CassandreStrategyInterface
getRequestedCurrencyPairs, getTradeAccount, initialize, onAccountsUpdates, onOrdersUpdates, onPositionsStatusUpdates, onPositionsUpdates, onTickersUpdates, onTradesUpdates
-
Constructor Details
-
CassandreStrategy
public CassandreStrategy()
-
-
Method Details
-
getTradeAccount
Returns the trade account selected by the strategy developer.- Returns:
- trade account
-
getTradeAccountBalances
Returns trade account balances.- Returns:
- trade account balances
-
getAccounts
Returns list of accounts.- Returns:
- accounts
-
getAccountByAccountId
Search and return an account by its id.- Parameters:
accountId
- account id- Returns:
- account
-
getAmountsLockedByPosition
Returns the amounts locked by position.- Returns:
- amounts locked
-
getAmountsLockedByCurrency
Returns the amounts locked for a specific currency.- Parameters:
currency
- currency- Returns:
- amounts locked
-
getLastTickers
Return last received tickers.- Returns:
- ticker
-
getImportedCandles
Return the list of imported candles (ordered by timestamp).- Returns:
- imported candles
-
getImportedCandles
Return the list of imported candles for a specific currency pair (ordered by timestamp).- Parameters:
currencyPair
- currency pair- Returns:
- imported candles
-
getImportedTickers
Return the list of imported tickers (ordered by timestamp).- Returns:
- imported tickers
-
getImportedTickers
Return the list of imported tickers for a specific currency pair (ordered by timestamp).- Parameters:
currencyPair
- currency pair- Returns:
- imported tickers
-
getOrders
Returns list of orders (order id is key).- Returns:
- orders
-
getOrderByOrderId
Get an order by its order id.- Parameters:
orderId
- order id- Returns:
- order
-
getTrades
Returns list of trades (trade id is key).- Returns:
- trades
-
getTradeByTradeId
Get a trade by its trade id.- Parameters:
tradeId
- trade id- Returns:
- trade
-
getPositions
Returns list of positions (position id the key).- Returns:
- positions
-
getPositionByPositionId
Get a position by its id.- Parameters:
positionId
- position id- Returns:
- position
-
getGains
Returns gains of all positions of the strategy.- Returns:
- total gains
-
createBuyMarketOrder
Creates a buy market order.- Parameters:
currencyPair
- currency pairamount
- amount- Returns:
- order result (order id or error)
-
createSellMarketOrder
public OrderCreationResultDTO createSellMarketOrder(CurrencyPairDTO currencyPair, BigDecimal amount) Creates a sell market order.- Parameters:
currencyPair
- currency pairamount
- 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 pairamount
- amountlimitPrice
- 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 pairamount
- amountlimitPrice
- 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 pairamount
- amountrules
- 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 pairamount
- amountrules
- rules- Returns:
- position creation result
-
updatePositionRules
Update position rules.- Parameters:
positionUid
- position uidnewRules
- 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 uidvalue
- 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 wanttargetCurrency
- 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 pairamount
- amount- Returns:
- cost
-
canBuy
Returns true if we have enough assets to buy.- Parameters:
currencyPair
- currency pairamount
- 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 pairamount
- amountminimumBalanceLeftAfter
- minimum balance that should be left after buying- Returns:
- true if we have enough assets to buy
-
canBuy
Returns true if we have enough assets to buy.- Parameters:
account
- accountcurrencyPair
- currency pairamount
- 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
- accountcurrencyPair
- currency pairamount
- amountminimumBalanceLeftAfter
- minimum balance that should be left after buying- Returns:
- true if we have enough assets to buy
-
canSell
Returns true if we have enough assets to sell.- Parameters:
currency
- currencyamount
- 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
- currencyamount
- amountminimumBalanceLeftAfter
- minimum balance that should be left after selling- Returns:
- true if we have enough assets to sell
-
canSell
Returns true if we have enough assets to sell.- Parameters:
account
- accountcurrency
- currency pairamount
- 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
- accountcurrency
- currencyamount
- amountminimumBalanceLeftAfter
- minimum balance that should be left after selling- Returns:
- true if we have enough assets to sell
-