Search in sources :

Example 1 with IdexCurrencyMeta

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);
}
Also used : CurrencyPairMetaData(org.knowm.xchange.dto.meta.CurrencyPairMetaData) CurrencyMetaData(org.knowm.xchange.dto.meta.CurrencyMetaData) IdexCurrencyMeta(org.knowm.xchange.idex.IdexExchange.Companion.IdexCurrencyMeta) ReturnCurrenciesResponse(org.knowm.xchange.idex.dto.ReturnCurrenciesResponse) IOException(java.io.IOException) ReturnTickerRequestedWithNull(org.knowm.xchange.idex.dto.ReturnTickerRequestedWithNull) LinkedHashMap(java.util.LinkedHashMap) RateLimit(org.knowm.xchange.dto.meta.RateLimit) ExchangeMetaData(org.knowm.xchange.dto.meta.ExchangeMetaData) Currency(org.knowm.xchange.currency.Currency) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 2 with IdexCurrencyMeta

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;
}
Also used : SignatureData(org.web3j.crypto.Sign.SignatureData) Currency(org.knowm.xchange.currency.Currency) IdexCurrencyMeta(org.knowm.xchange.idex.IdexExchange.Companion.IdexCurrencyMeta) Arrays.asList(java.util.Arrays.asList) List(java.util.List) OrderReq(org.knowm.xchange.idex.dto.OrderReq) BigDecimal(java.math.BigDecimal)

Aggregations

Currency (org.knowm.xchange.currency.Currency)2 IdexCurrencyMeta (org.knowm.xchange.idex.IdexExchange.Companion.IdexCurrencyMeta)2 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 Arrays.asList (java.util.Arrays.asList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)1 CurrencyMetaData (org.knowm.xchange.dto.meta.CurrencyMetaData)1 CurrencyPairMetaData (org.knowm.xchange.dto.meta.CurrencyPairMetaData)1 ExchangeMetaData (org.knowm.xchange.dto.meta.ExchangeMetaData)1 RateLimit (org.knowm.xchange.dto.meta.RateLimit)1 OrderReq (org.knowm.xchange.idex.dto.OrderReq)1 ReturnCurrenciesResponse (org.knowm.xchange.idex.dto.ReturnCurrenciesResponse)1 ReturnTickerRequestedWithNull (org.knowm.xchange.idex.dto.ReturnTickerRequestedWithNull)1 SignatureData (org.web3j.crypto.Sign.SignatureData)1