Created
July 26, 2019 10:48
-
-
Save talfco/13ac48bf03a488be16a73f36e2ff181e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void eth2token(String tokenSymbol, String tokenQuantity) { | |
Kyber3j kyber3j = Kyber3j.build(new KyberService(KyberService.KYBER_ROPSTEN)); | |
log.info("Connected to Kyber Network: "+KyberService.KYBER_ROPSTEN); | |
// ETH2<Token> Swap | |
try { | |
// Check if token is supported | |
Currencies currencies = kyber3j.currencies().send(); | |
log.info("Exists Currency"+tokenSymbol+": " + currencies.existsCurreny(tokenSymbol)); | |
if (!checkForError(currencies) && currencies.existsCurreny(tokenSymbol)) { | |
// Get buy rates | |
BuyRate buyRate = kyber3j.buyRate(currencies.getCurrency(tokenSymbol).getId(),tokenQuantity, | |
false).send(); | |
if (!checkForError(buyRate)) { | |
Rates rates = buyRate.getData().get(0); | |
SingleRate singleRate = rates.getSingleRate(0); | |
log.info("Conversion Rate: " + singleRate.getSrc_qty()); | |
// Get tradeData | |
// Adjust conversion rates to 97% | |
singleRate.approximateReceivableToken(0.97); | |
TradeData tradeData = kyber3j.tradeData(credentials.getAddress(), singleRate, GasPriceRange.medium,nonce).send(); | |
if (!checkForError(tradeData)) { | |
executeEthereumTransaction(tradeData.getData().get(0)); | |
} | |
} | |
} | |
} catch (Exception e) { e.printStackTrace(); } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment