Skip to content
This repository has been archived by the owner on Jan 29, 2019. It is now read-only.

Commit

Permalink
prevent division by zero
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentin Stavetski authored and hleb-albau committed Apr 27, 2018
1 parent c59e2d1 commit 4397270
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}

Expand All @@ -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]

Expand All @@ -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) {
Expand Down

0 comments on commit 4397270

Please sign in to comment.