-
-
Notifications
You must be signed in to change notification settings - Fork 164
/
MarketServiceTest.java
89 lines (81 loc) · 3.94 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
package tech.cassandre.trading.bot.test.integration.coinbasepro;
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.dto.market.TickerDTO;
import tech.cassandre.trading.bot.dto.util.CurrencyPairDTO;
import tech.cassandre.trading.bot.service.MarketService;
import java.util.Collections;
import java.util.Optional;
import java.util.Set;
import static java.math.BigDecimal.ZERO;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
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.driver-class-name=${COINBASE_PRO_NAME}",
"cassandre.trading.bot.exchange.modes.sandbox=true",
"cassandre.trading.bot.exchange.modes.dry=false",
"cassandre.trading.bot.exchange.username=${COINBASE_PRO_USERNAME}",
"cassandre.trading.bot.exchange.passphrase=${COINBASE_PRO_PASSPHRASE}",
"cassandre.trading.bot.exchange.key=${COINBASE_PRO_KEY}",
"cassandre.trading.bot.exchange.secret=${COINBASE_PRO_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("Coinbase pro - Market service")
public class MarketServiceTest {
@Autowired
private MarketService marketService;
@Test
@Tag("integration")
@DisplayName("Check get ticker")
public void checkGetTicker() {
CurrencyPairDTO cp = new CurrencyPairDTO(ETH, BTC);
Set<TickerDTO> tickers = marketService.getTickers(Collections.singleton(cp));
assertEquals(7, tickers.size());
final Optional<TickerDTO> ethBtcTicker = tickers.stream().filter(tickerDTO -> tickerDTO.getCurrencyPair().equals(cp)).findFirst();
assertTrue(ethBtcTicker.isPresent());
System.out.println(ethBtcTicker);
// currencyPair.
assertNotNull(ethBtcTicker.get().getCurrencyPair());
assertEquals(cp, ethBtcTicker.get().getCurrencyPair());
// last.
assertNotNull(ethBtcTicker.get().getLast());
assertTrue(ethBtcTicker.get().getLast().compareTo(ZERO) > 0);
// high.
assertNotNull(ethBtcTicker.get().getHigh());
assertTrue(ethBtcTicker.get().getHigh().compareTo(ZERO) > 0);
// low.
assertNotNull(ethBtcTicker.get().getLow());
assertTrue(ethBtcTicker.get().getLow().compareTo(ZERO) > 0);
// volume.
assertNotNull(ethBtcTicker.get().getVolume());
assertTrue(ethBtcTicker.get().getVolume().compareTo(ZERO) > 0);
// quote volume.
assertNotNull(ethBtcTicker.get().getQuoteVolume());
assertTrue(ethBtcTicker.get().getQuoteVolume().compareTo(ZERO) > 0);
// bidSize.
assertNull(ethBtcTicker.get().getBidSize());
// askSize.
assertNull(ethBtcTicker.get().getAskSize());
// timestamp.
assertNotNull(ethBtcTicker.get().getTimestamp());
}
}