/
MarketServiceTest.java
112 lines (102 loc) · 4.46 KB
/
MarketServiceTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package tech.cassandre.trading.bot.integration.binance;
import io.qase.api.annotation.CaseId;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
import tech.cassandre.trading.bot.batch.TickerFlux;
import tech.cassandre.trading.bot.dto.market.TickerDTO;
import tech.cassandre.trading.bot.dto.util.CurrencyPairDTO;
import tech.cassandre.trading.bot.service.MarketService;
import tech.cassandre.trading.bot.test.strategy.basic.TestableCassandreStrategy;
import tech.cassandre.trading.bot.test.util.junit.BaseTest;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import static java.math.BigDecimal.ZERO;
import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static tech.cassandre.trading.bot.dto.util.CurrencyDTO.BTC;
import static tech.cassandre.trading.bot.dto.util.CurrencyDTO.ETH;
@SpringBootTest
@ActiveProfiles("schedule-disabled")
@TestPropertySource(properties = {
"cassandre.trading.bot.exchange.name=${BINANCE_NAME}",
"cassandre.trading.bot.exchange.modes.sandbox=false",
"cassandre.trading.bot.exchange.modes.dry=false",
"cassandre.trading.bot.exchange.username=${BINANCE_USERNAME}",
"cassandre.trading.bot.exchange.passphrase=${BINANCE_PASSPHRASE}",
"cassandre.trading.bot.exchange.key=${BINANCE_KEY}",
"cassandre.trading.bot.exchange.secret=${BINANCE_SECRET}",
"cassandre.trading.bot.exchange.rates.account=100",
"cassandre.trading.bot.exchange.rates.ticker=101",
"cassandre.trading.bot.exchange.rates.trade=102",
"cassandre.trading.bot.database.datasource.driver-class-name=org.hsqldb.jdbc.JDBCDriver",
"cassandre.trading.bot.database.datasource.url=jdbc:hsqldb:mem:cassandre-database;shutdown=true",
"cassandre.trading.bot.database.datasource.username=sa",
"cassandre.trading.bot.database.datasource.password=",
"testableStrategy.enabled=true",
"invalidStrategy.enabled=false"
})
@DisplayName("Binance - Market service")
public class MarketServiceTest extends BaseTest {
@Autowired
private TickerFlux tickerFlux;
@Autowired
private MarketService marketService;
@Autowired
private TestableCassandreStrategy strategy;
@Test
@CaseId(114)
@Tag("integration")
@DisplayName("Check get ticker")
public void checkGetTicker() {
CurrencyPairDTO cp = new CurrencyPairDTO(ETH, BTC);
Optional<TickerDTO> t = marketService.getTicker(cp);
assertTrue(t.isPresent());
// currencyPair.
assertNotNull(t.get().getCurrencyPair());
assertEquals(t.get().getCurrencyPair(), cp);
// open.
assertNotNull(t.get().getOpen());
assertTrue(t.get().getOpen().compareTo(ZERO) > 0);
// last.
assertNotNull(t.get().getLast());
assertTrue(t.get().getLast().compareTo(ZERO) > 0);
// bid.
assertNotNull(t.get().getBid());
assertTrue(t.get().getBid().compareTo(ZERO) > 0);
// ask.
assertNotNull(t.get().getAsk());
assertTrue(t.get().getAsk().compareTo(ZERO) > 0);
// high.
assertNotNull(t.get().getHigh());
assertTrue(t.get().getHigh().compareTo(ZERO) > 0);
// low.
assertNotNull(t.get().getLow());
assertTrue(t.get().getLow().compareTo(ZERO) > 0);
// volume.
assertNotNull(t.get().getVolume());
assertTrue(t.get().getVolume().compareTo(ZERO) > 0);
// quote volume.
assertNotNull(t.get().getQuoteVolume());
assertTrue(t.get().getQuoteVolume().compareTo(ZERO) > 0);
// timestamp.
assertNotNull(t.get().getTimestamp());
}
@Test
@CaseId(115)
@Tag("integration")
@DisplayName("Check ticker flux")
public void checkTickerFlux() throws InterruptedException {
tickerFlux.update();
TimeUnit.SECONDS.sleep(WAITING_TIME_IN_SECONDS);
tickerFlux.update();
// We should have two tickers received by the strategy
await().untilAsserted(() -> assertEquals(2, strategy.getTickersUpdateReceived().size()));
}
}