/** * Constructor. * * @param firstCurrency the first currency, may be null * @param secondCurrency the second currency, not null */ public CurrencyMismatchException(CurrencyUnit firstCurrency, CurrencyUnit secondCurrency) { super("Currencies differ: " + (firstCurrency != null ? firstCurrency.getCode() : "null") + '/' + (secondCurrency != null ? secondCurrency.getCode() : "null")); this.firstCurrency = firstCurrency; this.secondCurrency = secondCurrency; }
@Override public void print(MoneyPrintContext context, Appendable appendable, BigMoney money) throws IOException { appendable.append(money.getCurrencyUnit().getCode()); } @Override
public void startTickers() { ThreadGroup tickerThreadGroup = new ThreadGroup("Tickers"); for(Wallet wallet : wallets) { CurrencyUnit currency = wallet.getBalance().getCurrencyUnit(); if(!currency.getCode().equals("BTC") && !currency.getCode().equals("NMC") && !currency.getCode().equals("LTC") && !currency.getCode().equals("PPC") && !currency.getCode().equals("TRC") && !currency.getCode().equals("NVC") && !currency.getCode().equals("FTC") && !currency.getCode().equals("CNC") ) { if (Application.getInstance().getConfig("UseLocalOnly").equals("1")) { if (currency.getCode().equals(Application.getInstance().getConfig("LocalCurrency"))) { Thread tickermanagerManagerThread = new Thread(tickerThreadGroup,TickerManager.getInstance(exchangeName,currency)); tickermanagerManagerThread.start(); } } else { Thread tickermanagerManagerThread = new Thread(tickerThreadGroup,TickerManager.getInstance(exchangeName,currency)); tickermanagerManagerThread.start(); } } } } }
/** * Gets this monetary value as a string. * <p> * The format is the 3 letter ISO currency code, followed by a space, * followed by the amount as per {@link BigDecimal#toPlainString()}. * * @return the string representation of this monetary value, never null */ @Override @ToString public String toString() { return new StringBuilder() .append(currency.getCode()) .append(' ') .append(amount.toPlainString()) .toString(); }
public static void main(String[] args) { List<CurrencyUnit> currencyUnits = CurrencyUnit.registeredCurrencies(); for (CurrencyUnit currencyUnit : currencyUnits) { System.out.println( currencyUnit.getCode() +" " + currencyUnit.getNumericCode() + " "+ currencyUnit.getNumeric3Code()+ " "+ currencyUnit.getCountryCodes()); }
public void addTick(ATPTicker tick) { CurrencyUnit currency = CurrencyUnit.getInstance(tick.getLast().getCurrencyUnit().getCurrencyCode()); if(!currency.getCode().equals("BTC")) { synchronized(lastTickMap) { lastTickMap.put(currency, tick); } } }
@Override public Quote getSellQuote(Money amount, String paymentMethodId) throws IOException, CoinbaseException { String qtyParam; if(amount.getCurrencyUnit().getCode().equals("BTC")) { qtyParam = "qty"; } else { qtyParam = "native_qty"; } URL sellPriceUrl; try { sellPriceUrl = new URL( _baseApiUrl, "prices/sell?" + qtyParam + "=" + URLEncoder.encode(amount.getAmount().toPlainString(), "UTF-8") + (_accountId != null ? "&account_id=" + _accountId : "") + (paymentMethodId != null ? "&payment_method_id=" + paymentMethodId : "") ); } catch (MalformedURLException ex) { throw new AssertionError(ex); } return deserialize(doHttp(sellPriceUrl, "GET", null), Quote.class); }
@Override public Quote getBuyQuote(Money amount, String paymentMethodId) throws IOException, CoinbaseException { String qtyParam; if(amount.getCurrencyUnit().getCode().equals("BTC")) { qtyParam = "qty"; } else { qtyParam = "native_qty"; } URL buyPriceUrl; try { buyPriceUrl = new URL( _baseApiUrl, "prices/buy?" + qtyParam +"=" + URLEncoder.encode(amount.getAmount().toPlainString(), "UTF-8") + (_accountId != null ? "&account_id=" + _accountId : "") + (paymentMethodId != null ? "&payment_method_id=" + paymentMethodId : "") ); } catch (MalformedURLException ex) { throw new AssertionError(ex); } return deserialize(doHttp(buyPriceUrl, "GET", null), Quote.class); }
@Override public Quote getSellQuote(Money amount, String paymentMethodId) throws IOException, CoinbaseException { String qtyParam; if(amount.getCurrencyUnit().getCode().equals("BTC")) { qtyParam = "qty"; } else { qtyParam = "native_qty"; } URL sellPriceUrl; try { sellPriceUrl = new URL( _baseApiUrl, "prices/sell?" + qtyParam + "=" + URLEncoder.encode(amount.getAmount().toPlainString(), "UTF-8") + (_accountId != null ? "&account_id=" + _accountId : "") + (paymentMethodId != null ? "&payment_method_id=" + paymentMethodId : "") ); } catch (MalformedURLException ex) { throw new AssertionError(ex); } return deserialize(doHttp(sellPriceUrl, "GET", null), Quote.class); }
@Override public Quote getBuyQuote(Money amount, String paymentMethodId) throws IOException, CoinbaseException { String qtyParam; if(amount.getCurrencyUnit().getCode().equals("BTC")) { qtyParam = "qty"; } else { qtyParam = "native_qty"; } URL buyPriceUrl; try { buyPriceUrl = new URL( _baseApiUrl, "prices/buy?" + qtyParam +"=" + URLEncoder.encode(amount.getAmount().toPlainString(), "UTF-8") + (_accountId != null ? "&account_id=" + _accountId : "") + (paymentMethodId != null ? "&payment_method_id=" + paymentMethodId : "") ); } catch (MalformedURLException ex) { throw new AssertionError(ex); } return deserialize(doHttp(buyPriceUrl, "GET", null), Quote.class); }
private void writeCurrency(ObjectOutput out, CurrencyUnit obj) throws IOException { out.writeUTF(obj.getCode()); out.writeShort(obj.getNumericCode()); out.writeShort(obj.getDecimalPlaces()); }
ExchangeManager.getInstance(exchangeName).setBidsInARow(bidsInARow); log.debug(exchangeName + " {} Asks in a row : {}",localCurrency.getCode(),asksInARow.get(localCurrency).toString()); log.debug(exchangeName + " {} Bids in a row : {}",localCurrency.getCode(),bidsInARow.get(localCurrency).toString());
log.info(exchangeName + " {} Ticker Size: {}",localCurrency.getCode(), tickerSize); StringBuilder str = new StringBuilder(); str.append(exchangeName + " " + localCurrency.getCode()); str.append(" Trend Arrow: "); str.append(trendArrow); str.append(" | "); str.append(localCurrency.getCode()); str.append(" Bid Arrow: "); str.append(bidArrow); str.append(" | "); str.append(localCurrency.getCode()); str.append(" Ask Arrow: "); str.append(askArrow); str.append(localCurrency.getCode()); str.append(" market is trending"); if(trendArrow > 0) { str.append(exchangeName + ":- "); str.append("Long EMA: "); str.append(localCurrency.getCode()); str.append(" "); str.append(numberFormat.format(emaLong.getAmount())); str.append(" | "); str.append("Short EMA: "); str.append(localCurrency.getCode()); str.append(" "); str.append(numberFormat.format(emaShort.getAmount()));
log.info("Trend following trade agent has decided that there is not enough {} momentum to trade at this time.",localCurrency.getCode()); } else if (Application.getInstance().getArbMode()) { if (ArbitrageEngine.getInstance(exchangeName).getDisableTrendTrade()) {
equivBTCEndBal = equivBTCEndBal.plus(endBal.convertedTo(CurrencyUnit.of("BTC"),BigDecimal.ONE.divide(endRate,16,RoundingMode.HALF_EVEN))); } else { log.info("Not enough "+currency.getCode()+" ticker data collected yet to calculate profit/loss"); return; log.info("No "+currency.getCode()+" ticker data collected yet, cannot calculate profit/loss"); return;
log.info("{} Trend following trade agent has decided that there is not enough {} momentum to trade at this time.",exchangeName,localCurrency.getCode()); } else if (Application.getInstance().getArbMode()) { if (ArbitrageEngine.getInstance(exchangeName).getDisableTrendTrade()) { if(qtyBTCToBuy.isLessThan(minBTC)) { log.info("{} was less than the configured limit of {}",qtyBTCToBuy.withScale(8,RoundingMode.HALF_EVEN).toString(),minBTC.toString()); log.info("{} Trend following trade agent has decided that there is not enough {} momentum to trade at this time.",exchangeName,localCurrency.getCode()); } else { log.info(exchangeName + " Trend following trade agent is attempting to buy {} at current {} market price.",qtyBTCToBuy.withScale(8,RoundingMode.HALF_EVEN).toString(),localCurrency.getCurrencyCode());