use of org.knowm.xchange.idex.dto.OrderReq in project XChange by knowm.
the class IdexTradeService method placeLimitOrder.
/**
* returns OrderHash so you can fetch it and cancel it... but there is a OrderNumber that you can
* intercept if you need to.
*/
@Override
public String placeLimitOrder(LimitOrder placeOrder) {
OrderType type = placeOrder.getType();
Currency baseCurrency = placeOrder.getCurrencyPair().base;
Currency counterCurrency = placeOrder.getCurrencyPair().counter;
BigDecimal originalAmount = placeOrder.getOriginalAmount();
BigDecimal limitPrice = placeOrder.getLimitPrice();
OrderReq orderReq = createNormalizedLimitOrderReq(baseCurrency, counterCurrency, type, limitPrice, originalAmount, null, null, null);
try {
orderApi.order(orderReq).getOrderHash();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of org.knowm.xchange.idex.dto.OrderReq 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