Search in sources :

Example 11 with Offer

use of io.bitsquare.trade.offer.Offer in project bitsquare by bitsquare.

the class OfferBookViewModel method applyFilterPredicate.

///////////////////////////////////////////////////////////////////////////////////////////
// Filters
///////////////////////////////////////////////////////////////////////////////////////////
private void applyFilterPredicate() {
    filteredItems.setPredicate(offerBookListItem -> {
        Offer offer = offerBookListItem.getOffer();
        boolean directionResult = offer.getDirection() != direction;
        boolean currencyResult;
        final String currencyCode = offer.getCurrencyCode();
        if (showAllTradeCurrenciesProperty.get()) {
            currencyResult = tradeCurrencyCodes.contains(currencyCode);
        } else
            currencyResult = currencyCode.equals(selectedTradeCurrency.getCode());
        boolean paymentMethodResult = showAllPaymentMethods || offer.getPaymentMethod().equals(selectedPaymentMethod);
        boolean notMyOfferOrShowMyOffersActivated = !isMyOffer(offerBookListItem.getOffer()) || preferences.getShowOwnOffersInOfferBook();
        return directionResult && currencyResult && paymentMethodResult && notMyOfferOrShowMyOffersActivated;
    });
}
Also used : Offer(io.bitsquare.trade.offer.Offer)

Example 12 with Offer

use of io.bitsquare.trade.offer.Offer in project bitsquare by bitsquare.

the class TradesChartsViewModelTest method testGetCandleData.

@Test
public void testGetCandleData() {
    TradesChartsViewModel model = new TradesChartsViewModel();
    long low = Fiat.parseFiat("EUR", "500").value;
    long open = Fiat.parseFiat("EUR", "520").value;
    long close = Fiat.parseFiat("EUR", "580").value;
    long high = Fiat.parseFiat("EUR", "600").value;
    long average = Fiat.parseFiat("EUR", "550").value;
    long amount = Coin.parseCoin("4").value;
    long volume = Fiat.parseFiat("EUR", "2200").value;
    boolean isBullish = true;
    Set<TradeStatistics> set = new HashSet<>();
    final Date now = new Date();
    Offer offer = new Offer(null, null, null, null, 0, 0, false, 0, 0, "EUR", null, null, null, null, null, null, null, null);
    set.add(new TradeStatistics(offer, Fiat.parseFiat("EUR", "520"), Coin.parseCoin("1"), new Date(now.getTime()), null, null));
    set.add(new TradeStatistics(offer, Fiat.parseFiat("EUR", "500"), Coin.parseCoin("1"), new Date(now.getTime() + 100), null, null));
    set.add(new TradeStatistics(offer, Fiat.parseFiat("EUR", "600"), Coin.parseCoin("1"), new Date(now.getTime() + 200), null, null));
    set.add(new TradeStatistics(offer, Fiat.parseFiat("EUR", "580"), Coin.parseCoin("1"), new Date(now.getTime() + 300), null, null));
    CandleData candleData = model.getCandleData(model.getTickFromTime(now.getTime(), TradesChartsViewModel.TickUnit.DAY), set);
    assertEquals(open, candleData.open);
    assertEquals(close, candleData.close);
    assertEquals(high, candleData.high);
    assertEquals(low, candleData.low);
    assertEquals(average, candleData.average);
    assertEquals(amount, candleData.accumulatedAmount);
    assertEquals(volume, candleData.accumulatedVolume);
    assertEquals(isBullish, candleData.isBullish);
}
Also used : TradeStatistics(io.bitsquare.trade.statistics.TradeStatistics) Offer(io.bitsquare.trade.offer.Offer) CandleData(io.bitsquare.gui.main.market.trades.charts.CandleData) Date(java.util.Date) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 13 with Offer

use of io.bitsquare.trade.offer.Offer in project bitsquare by bitsquare.

the class OfferBookViewModelTest method testIsAnyPaymentAccountValidForOffer.

@Test
public void testIsAnyPaymentAccountValidForOffer() {
    Offer offer;
    Collection<PaymentAccount> paymentAccounts;
    paymentAccounts = new ArrayList<>(Arrays.asList(getSepaAccount("EUR", "DE", "1212324", new ArrayList<>(Arrays.asList("AT", "DE")))));
    assertTrue(PaymentAccountUtil.isAnyPaymentAccountValidForOffer(getSEPAPaymentMethod("EUR", "AT", new ArrayList<>(Arrays.asList("AT", "DE")), "PSK"), paymentAccounts));
    // empty paymentAccounts
    paymentAccounts = new ArrayList<>();
    assertFalse(PaymentAccountUtil.isAnyPaymentAccountValidForOffer(getSEPAPaymentMethod("EUR", "AT", new ArrayList<>(Arrays.asList("AT", "DE")), "PSK"), paymentAccounts));
    // simple cases: same payment methods
    // offer: okpay paymentAccount: okpay - same country, same currency
    paymentAccounts = new ArrayList<>(Arrays.asList(getOKPayAccount("EUR")));
    assertTrue(PaymentAccountUtil.isAnyPaymentAccountValidForOffer(getOKPayPaymentMethod("EUR"), paymentAccounts));
    // offer: ether paymentAccount: ether - same country, same currency
    paymentAccounts = new ArrayList<>(Arrays.asList(getCryptoAccount("ETH")));
    assertTrue(PaymentAccountUtil.isAnyPaymentAccountValidForOffer(getBlockChainsPaymentMethod("ETH"), paymentAccounts));
    // offer: sepa paymentAccount: sepa - same country, same currency
    paymentAccounts = new ArrayList<>(Arrays.asList(getSepaAccount("EUR", "AT", "1212324", new ArrayList<>(Arrays.asList("AT", "DE")))));
    assertTrue(PaymentAccountUtil.isAnyPaymentAccountValidForOffer(getSEPAPaymentMethod("EUR", "AT", new ArrayList<>(Arrays.asList("AT", "DE")), "PSK"), paymentAccounts));
    // offer: nationalBank paymentAccount: nationalBank - same country, same currency
    paymentAccounts = new ArrayList<>(Arrays.asList(getNationalBankAccount("EUR", "AT", "PSK")));
    assertTrue(PaymentAccountUtil.isAnyPaymentAccountValidForOffer(getNationalBankPaymentMethod("EUR", "AT", "PSK"), paymentAccounts));
    // offer: SameBank paymentAccount: SameBank - same country, same currency
    paymentAccounts = new ArrayList<>(Arrays.asList(getSameBankAccount("EUR", "AT", "PSK")));
    assertTrue(PaymentAccountUtil.isAnyPaymentAccountValidForOffer(getSameBankPaymentMethod("EUR", "AT", "PSK"), paymentAccounts));
    // offer: sepa paymentAccount: sepa - diff. country, same currency
    paymentAccounts = new ArrayList<>(Arrays.asList(getSepaAccount("EUR", "DE", "1212324", new ArrayList<>(Arrays.asList("AT", "DE")))));
    assertTrue(PaymentAccountUtil.isAnyPaymentAccountValidForOffer(getSEPAPaymentMethod("EUR", "AT", new ArrayList<>(Arrays.asList("AT", "DE")), "PSK"), paymentAccounts));
    //////
    // offer: sepa paymentAccount: sepa - same country, same currency
    paymentAccounts = new ArrayList<>(Arrays.asList(getSepaAccount("EUR", "AT", "1212324", new ArrayList<>(Arrays.asList("AT", "DE")))));
    assertTrue(PaymentAccountUtil.isAnyPaymentAccountValidForOffer(getSEPAPaymentMethod("EUR", "AT", new ArrayList<>(Arrays.asList("AT", "DE")), "PSK"), paymentAccounts));
    // offer: sepa paymentAccount: nationalBank - same country, same currency
    // wrong method
    paymentAccounts = new ArrayList<>(Arrays.asList(getNationalBankAccount("EUR", "AT", "PSK")));
    assertFalse(PaymentAccountUtil.isAnyPaymentAccountValidForOffer(getSEPAPaymentMethod("EUR", "AT", new ArrayList<>(Arrays.asList("AT", "DE")), "PSK"), paymentAccounts));
    // wrong currency
    paymentAccounts = new ArrayList<>(Arrays.asList(getNationalBankAccount("USD", "US", "XXX")));
    assertFalse(PaymentAccountUtil.isAnyPaymentAccountValidForOffer(getNationalBankPaymentMethod("EUR", "AT", "PSK"), paymentAccounts));
    // wrong country
    paymentAccounts = new ArrayList<>(Arrays.asList(getNationalBankAccount("EUR", "FR", "PSK")));
    assertFalse(PaymentAccountUtil.isAnyPaymentAccountValidForOffer(getNationalBankPaymentMethod("EUR", "AT", "PSK"), paymentAccounts));
    // sepa wrong country
    paymentAccounts = new ArrayList<>(Arrays.asList(getNationalBankAccount("EUR", "CH", "PSK")));
    assertFalse(PaymentAccountUtil.isAnyPaymentAccountValidForOffer(getSEPAPaymentMethod("EUR", "AT", new ArrayList<>(Arrays.asList("AT", "DE")), "PSK"), paymentAccounts));
    // sepa wrong currency
    paymentAccounts = new ArrayList<>(Arrays.asList(getNationalBankAccount("CHF", "DE", "PSK")));
    assertFalse(PaymentAccountUtil.isAnyPaymentAccountValidForOffer(getSEPAPaymentMethod("EUR", "AT", new ArrayList<>(Arrays.asList("AT", "DE")), "PSK"), paymentAccounts));
    // same bank 
    paymentAccounts = new ArrayList<>(Arrays.asList(getSameBankAccount("EUR", "AT", "PSK")));
    assertTrue(PaymentAccountUtil.isAnyPaymentAccountValidForOffer(getNationalBankPaymentMethod("EUR", "AT", "PSK"), paymentAccounts));
    // not same bank
    paymentAccounts = new ArrayList<>(Arrays.asList(getSameBankAccount("EUR", "AT", "Raika")));
    assertFalse(PaymentAccountUtil.isAnyPaymentAccountValidForOffer(getNationalBankPaymentMethod("EUR", "AT", "PSK"), paymentAccounts));
    // same bank, wrong country
    paymentAccounts = new ArrayList<>(Arrays.asList(getSameBankAccount("EUR", "DE", "PSK")));
    assertFalse(PaymentAccountUtil.isAnyPaymentAccountValidForOffer(getNationalBankPaymentMethod("EUR", "AT", "PSK"), paymentAccounts));
    // same bank, wrong currency
    paymentAccounts = new ArrayList<>(Arrays.asList(getSameBankAccount("USD", "AT", "PSK")));
    assertFalse(PaymentAccountUtil.isAnyPaymentAccountValidForOffer(getNationalBankPaymentMethod("EUR", "AT", "PSK"), paymentAccounts));
    // spec. bank
    paymentAccounts = new ArrayList<>(Arrays.asList(getSpecificBanksAccount("EUR", "AT", "PSK", new ArrayList<>(Arrays.asList("PSK", "Raika")))));
    assertTrue(PaymentAccountUtil.isAnyPaymentAccountValidForOffer(getNationalBankPaymentMethod("EUR", "AT", "PSK"), paymentAccounts));
    // spec. bank, missing bank
    paymentAccounts = new ArrayList<>(Arrays.asList(getSpecificBanksAccount("EUR", "AT", "PSK", new ArrayList<>(Arrays.asList("Raika")))));
    assertFalse(PaymentAccountUtil.isAnyPaymentAccountValidForOffer(getNationalBankPaymentMethod("EUR", "AT", "PSK"), paymentAccounts));
    // spec. bank, wrong country
    paymentAccounts = new ArrayList<>(Arrays.asList(getSpecificBanksAccount("EUR", "FR", "PSK", new ArrayList<>(Arrays.asList("PSK", "Raika")))));
    assertFalse(PaymentAccountUtil.isAnyPaymentAccountValidForOffer(getNationalBankPaymentMethod("EUR", "AT", "PSK"), paymentAccounts));
    // spec. bank, wrong currency
    paymentAccounts = new ArrayList<>(Arrays.asList(getSpecificBanksAccount("USD", "AT", "PSK", new ArrayList<>(Arrays.asList("PSK", "Raika")))));
    assertFalse(PaymentAccountUtil.isAnyPaymentAccountValidForOffer(getNationalBankPaymentMethod("EUR", "AT", "PSK"), paymentAccounts));
//TODO add more tests
}
Also used : Offer(io.bitsquare.trade.offer.Offer) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 14 with Offer

use of io.bitsquare.trade.offer.Offer in project bitsquare by bitsquare.

the class OffererCreatesAndSignsDepositTxAsBuyer method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        checkNotNull(trade.getTradeAmount(), "trade.getTradeAmount() must not be null");
        Offer offer = trade.getOffer();
        Coin securityDeposit = FeePolicy.getSecurityDeposit(offer);
        Coin buyerInputAmount = securityDeposit.add(FeePolicy.getFixedTxFeeForTrades(offer));
        Coin msOutputAmount = buyerInputAmount.add(securityDeposit).add(trade.getTradeAmount());
        log.debug("\n\n------------------------------------------------------------\n" + "Contract as json\n" + trade.getContractAsJson() + "\n------------------------------------------------------------\n");
        byte[] contractHash = Hash.getHash(trade.getContractAsJson());
        trade.setContractHash(contractHash);
        WalletService walletService = processModel.getWalletService();
        String id = processModel.getOffer().getId();
        AddressEntry offererAddressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.RESERVED_FOR_TRADE);
        AddressEntry buyerMultiSigAddressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.MULTI_SIG);
        buyerMultiSigAddressEntry.setCoinLockedInMultiSig(buyerInputAmount.subtract(FeePolicy.getFixedTxFeeForTrades(offer)));
        Address changeAddress = walletService.getOrCreateAddressEntry(AddressEntry.Context.AVAILABLE).getAddress();
        PreparedDepositTxAndOffererInputs result = processModel.getTradeWalletService().offererCreatesAndSignsDepositTx(true, contractHash, buyerInputAmount, msOutputAmount, processModel.tradingPeer.getRawTransactionInputs(), processModel.tradingPeer.getChangeOutputValue(), processModel.tradingPeer.getChangeOutputAddress(), offererAddressEntry.getAddress(), changeAddress, buyerMultiSigAddressEntry.getPubKey(), processModel.tradingPeer.getMultiSigPubKey(), trade.getArbitratorPubKey());
        processModel.setPreparedDepositTx(result.depositTransaction);
        processModel.setRawTransactionInputs(result.rawOffererInputs);
        complete();
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : Coin(org.bitcoinj.core.Coin) Address(org.bitcoinj.core.Address) Offer(io.bitsquare.trade.offer.Offer) AddressEntry(io.bitsquare.btc.AddressEntry) PreparedDepositTxAndOffererInputs(io.bitsquare.btc.data.PreparedDepositTxAndOffererInputs) WalletService(io.bitsquare.btc.WalletService)

Example 15 with Offer

use of io.bitsquare.trade.offer.Offer in project bitsquare by bitsquare.

the class OffererCreatesAndSignsDepositTxAsSeller method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        checkNotNull(trade.getTradeAmount(), "trade.getTradeAmount() must not be null");
        Offer offer = trade.getOffer();
        Coin sellerInputAmount = FeePolicy.getSecurityDeposit(offer).add(FeePolicy.getFixedTxFeeForTrades(offer)).add(trade.getTradeAmount());
        Coin msOutputAmount = sellerInputAmount.add(FeePolicy.getSecurityDeposit(offer));
        log.debug("\n\n------------------------------------------------------------\n" + "Contract as json\n" + trade.getContractAsJson() + "\n------------------------------------------------------------\n");
        byte[] contractHash = Hash.getHash(trade.getContractAsJson());
        trade.setContractHash(contractHash);
        WalletService walletService = processModel.getWalletService();
        String id = processModel.getOffer().getId();
        AddressEntry offererAddressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.RESERVED_FOR_TRADE);
        AddressEntry sellerMultiSigAddressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.MULTI_SIG);
        sellerMultiSigAddressEntry.setCoinLockedInMultiSig(sellerInputAmount.subtract(FeePolicy.getFixedTxFeeForTrades(offer)));
        Address changeAddress = walletService.getOrCreateAddressEntry(AddressEntry.Context.AVAILABLE).getAddress();
        PreparedDepositTxAndOffererInputs result = processModel.getTradeWalletService().offererCreatesAndSignsDepositTx(false, contractHash, sellerInputAmount, msOutputAmount, processModel.tradingPeer.getRawTransactionInputs(), processModel.tradingPeer.getChangeOutputValue(), processModel.tradingPeer.getChangeOutputAddress(), offererAddressEntry.getAddress(), changeAddress, processModel.tradingPeer.getMultiSigPubKey(), sellerMultiSigAddressEntry.getPubKey(), trade.getArbitratorPubKey());
        processModel.setPreparedDepositTx(result.depositTransaction);
        processModel.setRawTransactionInputs(result.rawOffererInputs);
        complete();
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : Coin(org.bitcoinj.core.Coin) Address(org.bitcoinj.core.Address) Offer(io.bitsquare.trade.offer.Offer) AddressEntry(io.bitsquare.btc.AddressEntry) PreparedDepositTxAndOffererInputs(io.bitsquare.btc.data.PreparedDepositTxAndOffererInputs) WalletService(io.bitsquare.btc.WalletService)

Aggregations

Offer (io.bitsquare.trade.offer.Offer)27 Fiat (org.bitcoinj.utils.Fiat)8 Coin (org.bitcoinj.core.Coin)7 MainView (io.bitsquare.gui.main.MainView)5 Popup (io.bitsquare.gui.main.overlays.popups.Popup)5 BSFormatter (io.bitsquare.gui.util.BSFormatter)5 ImageView (javafx.scene.image.ImageView)5 AddressEntry (io.bitsquare.btc.AddressEntry)4 WalletService (io.bitsquare.btc.WalletService)4 Navigation (io.bitsquare.gui.Navigation)4 TradeCurrency (io.bitsquare.locale.TradeCurrency)4 ListChangeListener (javafx.collections.ListChangeListener)4 FeePolicy (io.bitsquare.btc.FeePolicy)3 ActivatableViewAndModel (io.bitsquare.gui.common.view.ActivatableViewAndModel)3 FxmlView (io.bitsquare.gui.common.view.FxmlView)3 AccountView (io.bitsquare.gui.main.account.AccountView)3 ArbitratorSelectionView (io.bitsquare.gui.main.account.content.arbitratorselection.ArbitratorSelectionView)3 AccountSettingsView (io.bitsquare.gui.main.account.settings.AccountSettingsView)3 GUIUtil (io.bitsquare.gui.util.GUIUtil)3 FiatCurrency (io.bitsquare.locale.FiatCurrency)3