|
|
|
@ -35,7 +35,7 @@ processing and are a very natural way to delineate success and failure cleanly.
|
|
|
|
|
of throwing exceptions on errors, and allows exceptions to be reserved for truly exceptional behavior as intended. |
|
|
|
|
|
|
|
|
|
By convention I adapted the Haskell Either type style to this code. What this means is that the Either type's Right |
|
|
|
|
value is the correct one (mnemonic: "right" as in correct) and the Left value is the serviceError. |
|
|
|
|
value is the correct one (mnemonic: "right" as in correct) and the Left value is the `ServiceError`. |
|
|
|
|
|
|
|
|
|
### How do I extract the raw value from the Either type? |
|
|
|
|
|
|
|
|
@ -73,7 +73,7 @@ if(res.isRight()) {
|
|
|
|
|
GeneralUtilities generalUtilities = GeneralUtilities.builder().apiKey("KEY").secretKey("KEY").build(); |
|
|
|
|
Either<ServiceError, ServerTime> res = generalUtilities.getServerTime(); |
|
|
|
|
|
|
|
|
|
if(res.isRight() { |
|
|
|
|
if(res.isRight()) { |
|
|
|
|
ServerTime response = Helpers.extractEitherValueSafely(res.right()); |
|
|
|
|
//... |
|
|
|
|
} |
|
|
|
@ -85,7 +85,7 @@ if(res.isRight() {
|
|
|
|
|
GeneralUtilities generalUtilities = GeneralUtilities.builder().apiKey("KEY").secretKey("KEY").build(); |
|
|
|
|
Either<ServiceError, ExchangeInfo> res = generalUtilities.getExchangeInfo(); |
|
|
|
|
|
|
|
|
|
if(res.isRight() { |
|
|
|
|
if(res.isRight()) { |
|
|
|
|
ExchangeInfo response = Helpers.extractEitherValueSafely(res.right()); |
|
|
|
|
//... |
|
|
|
|
} |
|
|
|
@ -97,7 +97,7 @@ if(res.isRight() {
|
|
|
|
|
MarketData marketData = MarketData.builder().apiKey("KEY").secretKey("KEY").build(); |
|
|
|
|
Either<ServiceError, List<Candlestick>> res = marketData.getCandlestickData("ETHBTC", Interval.ONE_MINUTE); |
|
|
|
|
|
|
|
|
|
if(res.isRight() { |
|
|
|
|
if(res.isRight()) { |
|
|
|
|
List<Candlestick> data = Helpers.extractEitherValueSafely(res.right()); |
|
|
|
|
//... |
|
|
|
|
} |
|
|
|
@ -109,7 +109,7 @@ if(res.isRight() {
|
|
|
|
|
MarketData marketData = MarketData.builder().apiKey("KEY").secretKey("KEY").build(); |
|
|
|
|
Either<ServiceError, OrderBookDepth> res = marketData.getOrderBookDepth("ETHBTC", 1000); |
|
|
|
|
|
|
|
|
|
if(res.isRight() { |
|
|
|
|
if(res.isRight()) { |
|
|
|
|
OrderBookDepth orderBookDepth = Helpers.extractEitherValueSafely(res.right()); |
|
|
|
|
//... |
|
|
|
|
} |
|
|
|
@ -121,7 +121,7 @@ if(res.isRight() {
|
|
|
|
|
MarketData marketData = MarketData.builder().apiKey("KEY").secretKey("KEY").build(); |
|
|
|
|
Either<ServiceError, TickerPrice> res = marketData.getTickerPriceForSymbol("ETHBTC"); |
|
|
|
|
|
|
|
|
|
if(res.isRight() { |
|
|
|
|
if(res.isRight()) { |
|
|
|
|
TickerPrice tickerPrice = Helpers.extractEitherValueSafely(res.right()); |
|
|
|
|
//... |
|
|
|
|
} |
|
|
|
|