本文整理汇总了Java中org.knowm.xchange.currency.CurrencyPair类的典型用法代码示例。如果您正苦于以下问题:Java CurrencyPair类的具体用法?Java CurrencyPair怎么用?Java CurrencyPair使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CurrencyPair类属于org.knowm.xchange.currency包,在下文中一共展示了CurrencyPair类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: FreqTradeExchangeServiceImpl
import org.knowm.xchange.currency.CurrencyPair; //导入依赖的package包/类
@Autowired
public FreqTradeExchangeServiceImpl(FreqTradeProperties properties, Exchange exchange) {
this.properties = properties;
this.exchange = exchange;
marketDataService = (BittrexMarketDataService) exchange.getMarketDataService();
accountService = exchange.getAccountService();
tradeService = exchange.getTradeService();
if (properties.isDryRun()) {
LOGGER.info("Instance is running with dry_run enabled");
}
// Check if all pairs are available
List<CurrencyPair> markets = getMarkets();
for (CurrencyPair pair : properties.getPairWhitelist()) {
if (!markets.contains(pair)) {
throw new FreqTradeExchangeInitializationException("Pair: " + pair + " is not available");
}
}
}
开发者ID:jeperon,项目名称:freqtrade-java,代码行数:23,代码来源:FreqTradeExchangeServiceImpl.java
示例2: executeSell
import org.knowm.xchange.currency.CurrencyPair; //导入依赖的package包/类
/**
* Executes a sell for the given trade and current rate
*
* @param trade Trade instance
* @param currentRate current rate
*
* @throws IOException if any I/O error occurs while contacting the exchange
* @throws TelegramApiException if any error occur while using the Telegram API
*/
private void executeSell(TradeEntity trade, BigDecimal currentRate) throws IOException, TelegramApiException {
// Get available balance
String currency = trade.getPair().split("/")[1];
BigDecimal balance = exchangeService.getBalance(Currency.getInstance(currency));
List<CurrencyPair> whitelist = properties.getPairWhitelist();
BigDecimal profit = tradeService.executeSellOrder(trade, currentRate, balance);
whitelist.add(new CurrencyPair(trade.getPair()));
String message = String.format("*%s:* Selling [%s](%s) at rate `%s (profit: %s%%)`",
trade.getExchange(),
trade.getPair(),
exchangeService.getPairDetailUrl(trade.getPair()),
trade.getCloseRate(),
profit.round(new MathContext(2)));
LOGGER.info(message);
telegramService.sendMessage(message);
}
开发者ID:jeperon,项目名称:freqtrade-java,代码行数:27,代码来源:FreqTradeMainRunner.java
示例3: init
import org.knowm.xchange.currency.CurrencyPair; //导入依赖的package包/类
public void init() {
DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
root.removeAllChildren();
for (String availableExchangeName : availableExchangeNames) {
DefaultMutableTreeNode firstChild = new DefaultMutableTreeNode(availableExchangeName);
Collection<CurrencyPair> currencyPairs = IdeaCurrencyApp.getInstance().getCurrencyPairs(availableExchangeName);
for (CurrencyPair currencyPair : currencyPairs) {
CheckedTreeNode secondChild = new CheckedTreeNode(currencyPair.toString());
boolean selected = isSelected(availableExchangeName, currencyPair);
secondChild.setChecked(selected);
firstChild.add(secondChild);
tree.expandPath(new TreePath(secondChild));
}
tree.expandPath(new TreePath(firstChild));
root.add(firstChild);
}
model.reload();
tree.treeDidChange();
Util.expandAll(tree, new TreePath(root), true);
}
开发者ID:semihunaldi,项目名称:IdeaCurrency,代码行数:22,代码来源:IdeaCurrencyConfigUI.java
示例4: apply
import org.knowm.xchange.currency.CurrencyPair; //导入依赖的package包/类
@Override
public void apply() throws ConfigurationException {
Set<SelectedExchangeCurrencyPair> selectedExchangeCurrencyPairs = Sets.newHashSet();
DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
Enumeration rootEnum = root.children();
while (rootEnum.hasMoreElements()) {
DefaultMutableTreeNode rootEnumObject = (DefaultMutableTreeNode) rootEnum.nextElement();
String exchangeName = rootEnumObject.getUserObject().toString();
Enumeration childEnum = rootEnumObject.children();
Set<CurrencyPair> currencyPairs = Sets.newHashSet();
while (childEnum.hasMoreElements()) {
CheckedTreeNode childEnumObject = (CheckedTreeNode) childEnum.nextElement();
if (childEnumObject.isChecked()) {
currencyPairs.add(new CurrencyPair(childEnumObject.getUserObject().toString()));
}
}
SelectedExchangeCurrencyPair selectedExchangeCurrencyPair = new SelectedExchangeCurrencyPair(exchangeName, currencyPairs);
selectedExchangeCurrencyPairs.add(selectedExchangeCurrencyPair);
}
IdeaCurrencyConfig.getInstance().setSelectedExchangeCurrencyPairs(selectedExchangeCurrencyPairs);
IdeaCurrencyConfig.getInstance().setReloadInterval(reloadIntervalSlider.getValue());
IdeaCurrencyConfig.getInstance().setActive(activeCheckBox.isSelected());
isModified = false;
triggerConfigChange();
}
开发者ID:semihunaldi,项目名称:IdeaCurrency,代码行数:27,代码来源:IdeaCurrencyConfigUI.java
示例5: Balance
import org.knowm.xchange.currency.CurrencyPair; //导入依赖的package包/类
public void Balance(ArrayList<ExchangeSpecs> selected, CurrencyPair currencyPair) throws IOException {
String currency1 = currencyPair.base.toString();
String currency2 = currencyPair.counter.toString();
ExchangeGetter exchangeGetter = new ExchangeGetter();
ArrayList<ActivatedExchange> activatedExchanges = exchangeGetter.getAllSelectedExchangeServices(selected, false);
for (ActivatedExchange activatedExchange : activatedExchanges) {
if (activatedExchange.isActivated() && activatedExchange.isTradingMode()) {
Wallet wallet = activatedExchange.getExchange().getAccountService().getAccountInfo().getWallet();
System.out.println();
System.out.println("==========================================================");
System.out.println("==========================================================");
System.out.println();
System.out.println("On "+ " " + activatedExchange.getExchange().getExchangeSpecification().getExchangeName());
System.out.print("you have " + wallet.getBalance(Currency.getInstance(currency1)).getAvailableForWithdrawal() +" " + currency1 + " ");
System.out.print("and " + wallet.getBalance(Currency.getInstance(currency2)).getAvailableForWithdrawal() +" " + currency2 + " ");
System.out.println();
System.out.println("==========================================================");
System.out.println("==========================================================");
System.out.println();
}
}
}
开发者ID:Thleruth,项目名称:bot_arbitrage,代码行数:27,代码来源:BalanceCalc.java
示例6: calculateValue
import org.knowm.xchange.currency.CurrencyPair; //导入依赖的package包/类
public float calculateValue(float baseAmount, Currency targetCurrency) throws ExchangeRateNotAvailableException {
// convert the amount to btc first
float btcAmount = calcBtcAmount(baseAmount);
float targetValue;
// if the target currency is btc we do nothing, otherwise we use the rate
if (targetCurrency.equals(Currency.BTC)) {
targetValue = btcAmount;
} else {
float fiatBtcPrice = exchangeRateProvider.getExchangeRate(new CurrencyPair(Currency.BTC, targetCurrency));
targetValue = btcAmount * fiatBtcPrice;
}
return targetValue;
}
开发者ID:iotaledger,项目名称:android-wallet-app,代码行数:17,代码来源:AlternateValueCalculator.java
示例7: doInBackground
import org.knowm.xchange.currency.CurrencyPair; //导入依赖的package包/类
@Override
protected String doInBackground(ExchangeRateStorage... params) {
try {
ExchangeRateUpdater exchangeRateUpdater = new ExchangeRateUpdater(baseCurrency, params[0]);
if (updateSelective) {
exchangeRateUpdater.updateResourceEfficient(new CurrencyPair(Currency.BTC, preferredCurrency));
if (BuildConfig.DEBUG)
Log.d(getClass().getName(), "Updating price selective");
}else
if (BuildConfig.DEBUG)
Log.d(getClass().getName(), "Updating price");
exchangeRateUpdater.update();
} catch (Exception e) {
networkError = true;
e.printStackTrace();
}
return null;
}
开发者ID:iotaledger,项目名称:android-wallet-app,代码行数:26,代码来源:ExchangeRateUpdateTaskHandler.java
示例8: executeSellOrder
import org.knowm.xchange.currency.CurrencyPair; //导入依赖的package包/类
@Override
public BigDecimal executeSellOrder(TradeEntity trade, BigDecimal rate, BigDecimal amount) throws IOException {
BigDecimal profit = rate.subtract(trade.getOpenRate()).divide(trade.getOpenRate())
.multiply(BigDecimal.valueOf(100));
// Execute sell and update trade record
String orderId = exchangeService.sell(new CurrencyPair(trade.getPair()), rate, amount);
trade.setCloseRate(rate);
trade.setCloseProfit(profit);
trade.setCloseDate(LocalDateTime.now());
trade.setOpenOrderId(orderId);
return profit;
}
开发者ID:jeperon,项目名称:freqtrade-java,代码行数:15,代码来源:TradeServiceImpl.java
示例9: handleInternal
import org.knowm.xchange.currency.CurrencyPair; //导入依赖的package包/类
@Override
protected void handleInternal(String[] params) throws Exception {
if (runner.getState() != State.RUNNING) {
telegramService.sendMessage("`trader is not running`");
return;
}
try {
Long tradeId = Long.parseLong(params[0]);
// Query for trade
Optional<TradeEntity> tradeOptional = tradeService.findOpenTradeById(tradeId);
if (tradeOptional.isPresent()) {
TradeEntity trade = tradeOptional.get();
// Get current rate
BigDecimal currentRate = exchangeService.getTicker(new CurrencyPair(trade.getPair())).getBid();
// Get available balance
String currency = new CurrencyPair(trade.getPair()).toString().split("/")[1];
BigDecimal balance = exchangeService.getBalance(Currency.getInstance(currency));
// Execute sell
BigDecimal profit = tradeService.executeSellOrder(trade, currentRate, balance);
String message = String.format(
"*%s:* Selling [%s](%s) at rate `%s (profit: %s\\%)`",
trade.getExchange(),
trade.getPair(),
exchangeService.getPairDetailUrl(trade.getPair()),
trade.getCloseRate(),
profit.round(new MathContext(2)).toString());
LOGGER.info(message);
telegramService.sendMessage(message);
} else {
telegramService.sendMessage(String.format("There is no open trade with ID: `%l`", tradeId));
}
} catch (NumberFormatException e) {
telegramService.sendMessage("Invalid argument. Usage: `/forcesell <trade_id>`");
LOGGER.warn("/forcesell: Invalid argument received");
}
}
开发者ID:jeperon,项目名称:freqtrade-java,代码行数:40,代码来源:ForceSellCommandHandler.java
示例10: handleInternal
import org.knowm.xchange.currency.CurrencyPair; //导入依赖的package包/类
/**
* Shows a performance statistic from finished trades
*
* @throws TelegramApiException if any error occur while using Telegram API
*/
@Override
protected void handleInternal(String[] params) throws Exception {
if (runner.getState() != State.RUNNING) {
telegramService.sendMessage("`trader is not running`");
return;
}
List<TradeEntity> trades = tradeService.findAllClosedTrade();
Map<CurrencyPair, BigDecimal> pairRates = trades.stream()
.collect(Collectors.toMap(t -> new CurrencyPair(t.getPair()),
TradeEntity::getCloseProfit,
(leftProfit, rightProfit) -> leftProfit.add(rightProfit)));
List<Pair<CurrencyPair, BigDecimal>> pairRatesList = pairRates.entrySet().stream()
.map(entry -> Pair.of(entry.getKey(), entry.getValue()))
.sorted(Comparator.comparing(Pair::getRight))
.sorted(Comparator.reverseOrder())
.collect(Collectors.toList());
StringBuilder messageBuilder = new StringBuilder("<b>Performance:</b>\n");
for (int i = 0; i < pairRatesList.size(); i++) {
Pair<CurrencyPair, BigDecimal> pairProfit = pairRatesList.get(i);
messageBuilder.append(i + 1).append('.');
messageBuilder.append("<code>").append(pairProfit.getLeft()).append('\t');
messageBuilder.append(pairProfit.getRight().round(new MathContext(2)).toString()).append("%</code>\n");
}
messageBuilder.append("\n");
String message = messageBuilder.toString();
LOGGER.debug(message);
telegramService.sendMessage(message, ParseMode.HTML);
}
开发者ID:jeperon,项目名称:freqtrade-java,代码行数:40,代码来源:PerformanceCommandHandler.java
示例11: buy
import org.knowm.xchange.currency.CurrencyPair; //导入依赖的package包/类
@Override
public String buy(CurrencyPair pair, BigDecimal rate, BigDecimal amount) throws IOException {
LOGGER.debug("Placing buy order: pair: {}, rate: {}, amount: {}", pair, rate, amount);
if (properties.isDryRun()) {
return "dry_run";
} else {
LimitOrder limitOrder = new LimitOrder(OrderType.BID, amount, pair, null, null, rate);
return tradeService.placeLimitOrder(limitOrder);
}
}
开发者ID:jeperon,项目名称:freqtrade-java,代码行数:12,代码来源:FreqTradeExchangeServiceImpl.java
示例12: sell
import org.knowm.xchange.currency.CurrencyPair; //导入依赖的package包/类
@Override
public String sell(CurrencyPair pair, BigDecimal rate, BigDecimal amount) throws IOException {
LOGGER.debug("Placing sell order: pair: {}, rate: {}, amount: {}", pair, rate, amount);
if (properties.isDryRun()) {
return "dry_run";
} else {
LimitOrder limitOrder = new LimitOrder(OrderType.ASK, amount, pair, null, null, rate);
return tradeService.placeLimitOrder(limitOrder);
}
}
开发者ID:jeperon,项目名称:freqtrade-java,代码行数:12,代码来源:FreqTradeExchangeServiceImpl.java
示例13: getOpenOrders
import org.knowm.xchange.currency.CurrencyPair; //导入依赖的package包/类
@Override
public List<LimitOrder> getOpenOrders(CurrencyPair pair) throws IOException {
LOGGER.debug("Fetching open orders for pair: {}", pair);
if (properties.isDryRun()) {
return new ArrayList<>();
} else {
OpenOrdersParams params = new DefaultOpenOrdersParamCurrencyPair(pair);
OpenOrders openOrders = tradeService.getOpenOrders(params);
return openOrders.getOpenOrders();
}
}
开发者ID:jeperon,项目名称:freqtrade-java,代码行数:15,代码来源:FreqTradeExchangeServiceImpl.java
示例14: getMarkets
import org.knowm.xchange.currency.CurrencyPair; //导入依赖的package包/类
/**
* Returns all available markets
*
* @return list of all available pairs
*/
private List<CurrencyPair> getMarkets() {
LOGGER.debug("Fetching currency pairs...");
List<CurrencyPair> availablePairs = exchange.getExchangeSymbols();
LOGGER.debug("Available pairs: {}", availablePairs);
return availablePairs;
}
开发者ID:jeperon,项目名称:freqtrade-java,代码行数:12,代码来源:FreqTradeExchangeServiceImpl.java
示例15: main
import org.knowm.xchange.currency.CurrencyPair; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
ApplicationContext context = SpringApplication.run(FreqTradeApplication.class, args);
FreqTradeExchangeService exchangeService = context.getBean(FreqTradeExchangeService.class);
AnalyzeService analyzeService = context.getBean(AnalyzeService.class);
ZonedDateTime minimumDate = ZonedDateTime.now().minusHours(6);
List<BittrexChartData> rawTickers = exchangeService.fetchRawticker(new CurrencyPair("ETH/BTC"), minimumDate);
TimeSeries tickers = new BittrexDataConverter().parseRawTickers(rawTickers);
boolean buySignal = analyzeService.getBuySignal(tickers);
LOGGER.info("buy signal: {}", buySignal);
SpringApplication.exit(context);
}
开发者ID:jeperon,项目名称:freqtrade-java,代码行数:16,代码来源:AnalyzeServiceTester.java
示例16: handleTrade
import org.knowm.xchange.currency.CurrencyPair; //导入依赖的package包/类
/**
* Sells the current pair if the threshold is reached and updates the trade record.
*
* @throws IOException if any I/O error occurs while contacting the exchange
* @throws TelegramApiException if any error occurs while using Telegram API
*/
private void handleTrade(TradeEntity trade) throws IOException, TelegramApiException {
if (!trade.getOpen()) {
LOGGER.warn("attempt to handle closed trade: {}", trade);
return;
}
LOGGER.debug("Handling open trade {} ...", trade);
BigDecimal currentRate = exchangeService.getTicker(new CurrencyPair(trade.getPair())).getBid();
if (shouldSell(trade, currentRate, LocalDateTime.now())) {
executeSell(trade, currentRate);
return;
}
}
开发者ID:jeperon,项目名称:freqtrade-java,代码行数:21,代码来源:FreqTradeMainRunner.java
示例17: isSelected
import org.knowm.xchange.currency.CurrencyPair; //导入依赖的package包/类
private boolean isSelected(String exchangeName, CurrencyPair currencyPair) {
SelectedExchangeCurrencyPair exchangePair = getExchangePair(exchangeName);
if (exchangePair != null) {
return exchangePair.getCurrencyPairList().contains(currencyPair);
}
return false;
}
开发者ID:semihunaldi,项目名称:IdeaCurrency,代码行数:8,代码来源:IdeaCurrencyConfigUI.java
示例18: loadState
import org.knowm.xchange.currency.CurrencyPair; //导入依赖的package包/类
@Override
public void loadState(IdeaCurrencyConfig ideaCurrencyConfig) {
XmlSerializerUtil.copyBean(ideaCurrencyConfig, this);
for (String exchangeName : ideaCurrencyConfig.currencyPairByExchangeMap.keySet()) {
String currencyPairs = currencyPairByExchangeMap.get(exchangeName);
String[] split = currencyPairs.split(",");
Set<CurrencyPair> currencyPairSet = Lists.newArrayList(split).stream().map(CurrencyPair::new).collect(Collectors.toSet());
selectedExchangeCurrencyPairs.add(new SelectedExchangeCurrencyPair(exchangeName, currencyPairSet));
}
checkAndOptimizeReloadInterval(ideaCurrencyConfig.getReloadInterval());
}
开发者ID:semihunaldi,项目名称:IdeaCurrency,代码行数:12,代码来源:IdeaCurrencyConfig.java
示例19: setSelectedExchangeCurrencyPairs
import org.knowm.xchange.currency.CurrencyPair; //导入依赖的package包/类
@Transient
public void setSelectedExchangeCurrencyPairs(Set<SelectedExchangeCurrencyPair> selectedExchangeCurrencyPairs) {
this.selectedExchangeCurrencyPairs = selectedExchangeCurrencyPairs;
for (SelectedExchangeCurrencyPair selectedExchangeCurrencyPair : selectedExchangeCurrencyPairs) {
StringJoiner stringJoiner = new StringJoiner(",");
for (CurrencyPair currencyPair : selectedExchangeCurrencyPair.getCurrencyPairList()) {
stringJoiner.add(currencyPair.toString());
}
if (StringUtils.isNotBlank(stringJoiner.toString())) {
currencyPairByExchangeMap.put(selectedExchangeCurrencyPair.getExchangeName(), stringJoiner.toString());
}
}
}
开发者ID:semihunaldi,项目名称:IdeaCurrency,代码行数:14,代码来源:IdeaCurrencyConfig.java
示例20: getCurrencyPairs
import org.knowm.xchange.currency.CurrencyPair; //导入依赖的package包/类
public Collection<CurrencyPair> getCurrencyPairs(String exchangeName) {
Exchange exchangeByName = getExchangeByName(exchangeName);
if (exchangeByName.getExchangeMetaData() != null) {
return exchangeByName.getExchangeMetaData().getCurrencyPairs().keySet();
} else {
return DEFAULT_CURRENCY_PAIRS;
}
}
开发者ID:semihunaldi,项目名称:IdeaCurrency,代码行数:9,代码来源:IdeaCurrencyApp.java
注:本文中的org.knowm.xchange.currency.CurrencyPair类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论