use of org.knowm.xchange.idex.IdexExchange.Companion.IdexCurrencyMeta in project XChange by knowm.
the class IdexExchange method getExchangeMetaData.
@Override
public final ExchangeMetaData getExchangeMetaData() {
ReturnCurrenciesResponse allCurrenciesStatic = null;
try {
allCurrenciesStatic = allCurrenciesStatic();
} catch (IOException e) {
e.printStackTrace();
}
LinkedHashMap<CurrencyPair, CurrencyPairMetaData> currencyPairs = new LinkedHashMap<>();
ReturnTickerRequestedWithNull allTickers = IdexMarketDataService.Companion.allTickers;
allTickers.keySet().forEach(s -> currencyPairs.put(IdexExchange.Companion.getCurrencyPair(s), unavailableCPMeta));
LinkedHashMap<Currency, CurrencyMetaData> linkedHashMap = new LinkedHashMap<>();
allCurrenciesStatic.forEach((key, value) -> linkedHashMap.put(Currency.getInstance(key), new IdexCurrencyMeta(0, ZERO, value.getAddress(), value.getName(), value.getDecimals())));
RateLimit[] publicRateLimits = {};
return new ExchangeMetaData(currencyPairs, linkedHashMap, publicRateLimits, publicRateLimits, Boolean.FALSE);
}
use of org.knowm.xchange.idex.IdexExchange.Companion.IdexCurrencyMeta in project XChange by knowm.
the class IdexTradeService method createNormalizedLimitOrderReq.
public final OrderReq createNormalizedLimitOrderReq(Currency baseCurrency, Currency counterCurrency, OrderType type, BigDecimal limitPrice, BigDecimal originalAmount, String contractAddress, BigInteger nonce, BigInteger expires) {
nonce = nonce == null ? BigInteger.valueOf(exchange.getNonceFactory().createValue()) : nonce;
contractAddress = contractAddress == null ? contractAddress().getAddress() : contractAddress;
expires = expires == null ? BigInteger.valueOf(100000) : expires;
exchange.getExchangeMetaData().getCurrencies().get(baseCurrency);
exchange.getExchangeMetaData().getCurrencies().get(counterCurrency);
OrderReq orderReq = null;
boolean untested = true;
if (untested) {
List<Currency> listOfCurrencies = asList(baseCurrency, /*OMG*/
counterCurrency);
if (type == BID)
Collections.reverse(listOfCurrencies);
IdexCurrencyMeta buy_currency = (IdexCurrencyMeta) exchange.getExchangeMetaData().getCurrencies().get(listOfCurrencies.get(0));
IdexCurrencyMeta sell_currency = (IdexCurrencyMeta) exchange.getExchangeMetaData().getCurrencies().get(listOfCurrencies.get(1));
BigDecimal divide = originalAmount.divide(limitPrice, MathContext.DECIMAL128);
BigDecimal amount_buy = divide.multiply(new BigDecimal("1e" + buy_currency.getDecimals()), MathContext.DECIMAL128);
BigDecimal amount_sell = originalAmount.multiply(new BigDecimal("1e" + sell_currency.getDecimals()), MathContext.DECIMAL128);
String buyc = buy_currency.getAddress();
String sellc = sell_currency.getAddress();
List<List<String>> hash_data = asList(asList("contractAddress", contractAddress, "address"), asList("tokenBuy", buyc, "address"), asList("amountBuy", amount_buy.toString(), "uint256"), asList("tokenSell", sellc, "address"), asList("amountSell", amount_sell.toString(), "uint256"), asList("expires", "" + expires, "uint256"), asList("nonce", "" + nonce, "uint256"), asList("address", "" + getApiKey(), "address"));
SignatureData sig = generateSignature(exchange.getExchangeSpecification().getSecretKey(), hash_data);
byte[] v = sig.getV();
byte[] r = sig.getR();
byte[] s = sig.getS();
orderReq = new OrderReq().address(getApiKey()).nonce(nonce).tokenBuy(buyc).amountBuy(amount_buy.toString()).tokenSell(sellc).amountSell(amount_sell.toString()).expires(expires).r("0x" + new String(Hex.toHexString(r))).s("0x" + new String(Hex.toHexString(s))).v(BigInteger.valueOf(v[0] & 0xffl));
}
return orderReq;
}
Aggregations