From 4397270347508dd36d3f5445bd96821cc4da90e7 Mon Sep 17 00:00:00 2001 From: Valentin Stavetski Date: Fri, 27 Apr 2018 12:46:49 +0300 Subject: [PATCH] prevent division by zero --- .../markets/connector/EtherdeltaConnector.kt | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/exchanges-connector/src/main/kotlin/fund/cyber/markets/connector/EtherdeltaConnector.kt b/exchanges-connector/src/main/kotlin/fund/cyber/markets/connector/EtherdeltaConnector.kt index fd88c46d..f1dd2c91 100644 --- a/exchanges-connector/src/main/kotlin/fund/cyber/markets/connector/EtherdeltaConnector.kt +++ b/exchanges-connector/src/main/kotlin/fund/cyber/markets/connector/EtherdeltaConnector.kt @@ -151,13 +151,15 @@ class EtherdeltaConnector : ExchangeConnector { val trade = convertTrade(tradeEvent, block) - val exchangePairTag = exchangeTag.and(Tags.of(TOKENS_PAIR_TAG, trade.pair.base + "_" + trade.pair.quote)) - val tradeCountMonitor = monitoring.counter(TRADE_COUNT_METRIC, exchangePairTag) - tradeLatencyMonitor.record(System.currentTimeMillis() - trade.timestamp.time, TimeUnit.MILLISECONDS) - tradeCountMonitor.increment() - - kafkaTemplate.send(tradesTopicName, trade) - log.debug("Trade from $exchangeName: $trade") + if (trade != null) { + val exchangePairTag = exchangeTag.and(Tags.of(TOKENS_PAIR_TAG, trade.pair.base + "_" + trade.pair.quote)) + val tradeCountMonitor = monitoring.counter(TRADE_COUNT_METRIC, exchangePairTag) + tradeLatencyMonitor.record(System.currentTimeMillis() - trade.timestamp.time, TimeUnit.MILLISECONDS) + tradeCountMonitor.increment() + + kafkaTemplate.send(tradesTopicName, trade) + log.debug("Trade from $exchangeName: $trade") + } } } @@ -172,7 +174,7 @@ class EtherdeltaConnector : ExchangeConnector { * @return trade object * @see Trade */ - private fun convertTrade(tradeEvent: EtherdeltaContract.TradeEventResponse, block: EthBlock): Trade { + private fun convertTrade(tradeEvent: EtherdeltaContract.TradeEventResponse, block: EthBlock): Trade? { val tokenGet = exchangeTokensPairs[tradeEvent.tokenGet] val tokenGive = exchangeTokensPairs[tradeEvent.tokenGive] @@ -188,6 +190,10 @@ class EtherdeltaConnector : ExchangeConnector { BigDecimal(tradeEvent.amountGive) } + if (amountGet == BigDecimal.ZERO || amountGive == BigDecimal.ZERO) { + return null + } + val timestamp = Numeric.toBigInt(block.block.timestampRaw).multiply(BigInteger.valueOf(1000)).toLong() if (tokenGive.symbol == ETH_SYMBOL) {