public static BigDecimal of(final BigDecimal amount, final Currency currency) { final CurrencyUnit currencyUnit = CurrencyUnit.getInstance(currency.toString()); return amount.setScale(currencyUnit.getDecimalPlaces(), ROUNDING_METHOD); } }
@Override public CurrencyUnit deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { CurrencyUnit result = null; try { result = CurrencyUnit.getInstance(jp.getText()); } catch (IllegalCurrencyException ex) {} return result; }
@Override public CurrencyUnit deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { CurrencyUnit result = null; try { result = CurrencyUnit.getInstance(jp.getText()); } catch (IllegalCurrencyException ex) {} return result; }
private ArbitrageEngine(String exchangeName) { this.exchangeName = exchangeName; log = LoggerFactory.getLogger(ArbitrageEngine.class); quit = false; disableTrendTradeFlag = false; lastTickMap = new HashMap<CurrencyUnit, ATPTicker>(); baseCurrency = CurrencyUnit.getInstance(Application.getInstance().getConfig("LocalCurrency")); } @Override
public static BigDecimal of(final BigDecimal amount, final Currency currency) { final CurrencyUnit currencyUnit = CurrencyUnit.getInstance(currency.toString()); return amount.setScale(currencyUnit.getDecimalPlaces(), ROUNDING_METHOD); } }
@Override public List<CurrencyUnit> getSupportedCurrencies() throws IOException, CoinbaseException { URL currenciesUrl; try { currenciesUrl = new URL(_baseApiUrl, "currencies"); } catch (MalformedURLException ex) { throw new AssertionError(ex); } List<List<String>> rawResponse = deserialize(doHttp(currenciesUrl, "GET", null), new TypeReference<List<List<String>>>() {}); List<CurrencyUnit> result = new ArrayList<CurrencyUnit>(); for (List<String> currency : rawResponse) { try { result.add(CurrencyUnit.getInstance(currency.get(1))); } catch (IllegalCurrencyException ex) {} } return result; }
@Override public List<CurrencyUnit> getSupportedCurrencies() throws IOException, CoinbaseException { URL currenciesUrl; try { currenciesUrl = new URL(_baseApiUrl, "currencies"); } catch (MalformedURLException ex) { throw new AssertionError(ex); } List<List<String>> rawResponse = deserialize(doHttp(currenciesUrl, "GET", null), new TypeReference<List<List<String>>>() {}); List<CurrencyUnit> result = new ArrayList<CurrencyUnit>(); for (List<String> currency : rawResponse) { try { result.add(CurrencyUnit.getInstance(currency.get(1))); } catch (IllegalCurrencyException ex) {} } return result; }
public static BigDecimal of(final BigDecimal amount, final Currency currency) { final CurrencyUnit currencyUnit = CurrencyUnit.getInstance(currency.toString()); return amount.setScale(currencyUnit.getDecimalPlaces(), BigDecimal.ROUND_HALF_UP); }
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 Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException { BigDecimal amount = BigDecimalType.INSTANCE.nullSafeGet(rs, names[0], session); String currencyCode = StringType.INSTANCE.nullSafeGet(rs, names[1], session); return amount == null && currencyCode == null ? null : Money.of(CurrencyUnit.getInstance(currencyCode), amount); }
/** * Adapts a BitfloorBalance to a AccountInfo * * @param bitfloorBalance@return */ public static AccountInfo adaptAccountInfo(BitfloorBalance[] bitfloorBalance, String userName) { // Adapt to XChange DTOs List<Wallet> wallets = new ArrayList<Wallet>(); for (BitfloorBalance balance : bitfloorBalance) { wallets.add(new Wallet(balance.getCurrency(), BigMoney.of(CurrencyUnit.getInstance(balance.getCurrency()), balance.getAmount()))); } return new AccountInfo(userName, wallets); }
public static List<LimitOrder> adaptActive(BitcoinCentralMyOrder[] accountTradeOrders) { List<LimitOrder> orders = new ArrayList<LimitOrder>(); for (BitcoinCentralMyOrder order : accountTradeOrders) { if (order.isPendingExecution()) { orders.add(new LimitOrder(order.getCategory().type, order.getAmount(), "BTC", order.getCurrency(), Integer.toString(order.getId()), BigMoney.of(CurrencyUnit.getInstance(order.getCurrency()), order.getPpc()))); } } return orders; } }
/** * Adapts a BitcoinCentralAccountInfo to a AccountInfo */ public static AccountInfo adaptAccountInfo(BitcoinCentralAccountInfo accountInfo, String userName) { Wallet eurWallet = new Wallet("EUR", BigMoney.of(CurrencyUnit.EUR, accountInfo.getEur())); Wallet btcWallet = Wallet.createInstance("BTC", accountInfo.getBtc()); Wallet usdWallet = new Wallet("GBP", BigMoney.of(CurrencyUnit.CAD, accountInfo.getGbp())); Wallet inrWallet = new Wallet("USD", BigMoney.of(CurrencyUnit.getInstance("INR"), accountInfo.getUsd())); return new AccountInfo(userName, Arrays.asList(btcWallet, usdWallet, eurWallet, inrWallet)); }