Test your bot with historic rates

How to quickly retrieve historical rates from Kucoin

Cassandre trading bot allows you to simulate your bots' reaction to historical data during tests.

The first step is to add cassandre-trading-bot-spring-boot-starter-testto your project dependency.

Edit your pom.xml file and add :


Maven Central

Now, we need to generate the data you want to use during your JUnit tests. We can use the Kucoin API, to do so, you can run this on the command line :

startDate=`date --date="3 months ago" +"%s"`
endDate=`date +"%s"`
curl -s "https://api.kucoin.com/api/v1/market/candles?type=1day&symbol=BTC-USDT&startAt=${startDate}&endAt=${endDate}" \
| jq -r -c ".data[] | @tsv" \
| tac $1 > tickers-btc-usdt.tsv

It will create a file named tickers-btc-usdt.tsva that contains the historical rate of btc-usdt from startDate (3 months ago) to endDate (now). Of course, you can change dates and currency pair to choose which data you want to use.

Now place this file in the src/test/resources folder of our project and add this line to your JUnit test class:


Now, instead of receiving tickers from the exchange, you will receive tickers created from the tsv files you put in src/test/resources.