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

Commit b488abc

Browse files
Valentin Stavetskihleb-albau
Valentin Stavetski
authored andcommitted
#173 update isAlive implementation for etherdelta
1 parent 1f3e846 commit b488abc

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
@@ -40,6 +40,7 @@ import java.util.concurrent.TimeUnit
4040

4141
private const val ETHERDELTA_CONTRACT_ADDRESS = "0x8d12a197cb00d4747a1fe03395095ce2a5cc6819"
4242
private const val ETH_SYMBOL = "ETH"
43+
private const val ETHERDELTA_CONNECTION_TIMEOUT_MS: Long = 5 * 60 * 1000
4344

4445
@Component
4546
class EtherdeltaTradeConnector : Connector {
@@ -48,6 +49,7 @@ class EtherdeltaTradeConnector : Connector {
4849
private val exchangeName = "ETHERDELTA"
4950
private val tradesTopicName by lazy { TRADES_TOPIC_PREFIX + exchangeName }
5051
private lateinit var etherdeltaContract: EtherdeltaContract
52+
private var lastTradeTimestamp: Long? = null
5153

5254
@Autowired
5355
private lateinit var web3j: Web3j
@@ -86,15 +88,11 @@ class EtherdeltaTradeConnector : Connector {
8688
}
8789

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

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

97-
return test != null
9896
}
9997

10098
/**
@@ -180,6 +178,7 @@ class EtherdeltaTradeConnector : Connector {
180178
}
181179

182180
val timestamp = Numeric.toBigInt(block.block.timestampRaw).multiply(BigInteger.valueOf(1000)).toLong()
181+
lastTradeTimestamp = timestamp
183182

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

0 commit comments

Comments
 (0)