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

Commit 6271b7b

Browse files
author
Valentin Stavetski
committed
#173 update isAlive implementation for etherdelta
1 parent af02233 commit 6271b7b

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

exchanges-connector/src/main/kotlin/fund/cyber/markets/connector/trade/EtherdeltaTradeConnector.kt

+6-7
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import java.util.concurrent.TimeUnit
3838

3939
private const val ETHERDELTA_CONTRACT_ADDRESS = "0x8d12a197cb00d4747a1fe03395095ce2a5cc6819"
4040
private const val ETH_SYMBOL = "ETH"
41+
private const val ETHERDELTA_CONNECTION_TIMEOUT_MS: Long = 5 * 60 * 1000
4142

4243
@Component
4344
class EtherdeltaTradeConnector : Connector {
@@ -46,6 +47,7 @@ class EtherdeltaTradeConnector : Connector {
4647
private val exchangeName = "ETHERDELTA"
4748
private val tradesTopicName by lazy { TRADES_TOPIC_PREFIX + exchangeName }
4849
private lateinit var etherdeltaContract: EtherdeltaContract
50+
private var lastTradeTimestamp: Long? = null
4951

5052
@Autowired
5153
private lateinit var web3j: Web3j
@@ -84,15 +86,11 @@ class EtherdeltaTradeConnector : Connector {
8486
}
8587

8688
override fun isAlive(): Boolean {
87-
val test: String?
89+
val currentTimestamp = Date().time
8890

89-
try {
90-
test = etherdeltaContract.accountLevelsAddr().send()
91-
} catch (e: Throwable) {
92-
return false
93-
}
91+
return lastTradeTimestamp != null &&
92+
currentTimestamp - lastTradeTimestamp!! < ETHERDELTA_CONNECTION_TIMEOUT_MS
9493

95-
return test != null
9694
}
9795

9896
/**
@@ -170,6 +168,7 @@ class EtherdeltaTradeConnector : Connector {
170168
}
171169

172170
val timestamp = Numeric.toBigInt(block.block.timestampRaw).multiply(BigInteger.valueOf(1000)).toLong()
171+
lastTradeTimestamp = timestamp
173172

174173
if (tokenGive.symbol == ETH_SYMBOL) {
175174
val price = amountGive.divide(amountGet, tokenGive.decimals, RoundingMode.HALF_EVEN)

0 commit comments

Comments
 (0)