mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-24 23:18:17 +01:00
further offer work
This commit is contained in:
parent
5ce77ebc3f
commit
c846eb9dbe
8 changed files with 60 additions and 38 deletions
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<artifactId>parent</artifactId>
|
||||
<groupId>io.bitsquare</groupId>
|
||||
<version>0.4.9.2</version>
|
||||
<version>0.4.9.6</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
@ -11,11 +11,13 @@ import io.bitsquare.locale.CurrencyUtil;
|
|||
import io.bitsquare.p2p.NodeAddress;
|
||||
import io.bitsquare.p2p.P2PService;
|
||||
import io.bitsquare.payment.CryptoCurrencyAccount;
|
||||
import io.bitsquare.payment.PaymentAccount;
|
||||
import io.bitsquare.payment.SameBankAccount;
|
||||
import io.bitsquare.payment.SpecificBanksAccount;
|
||||
import io.bitsquare.trade.TradeManager;
|
||||
import io.bitsquare.trade.offer.Offer;
|
||||
import io.bitsquare.trade.offer.OfferBookService;
|
||||
import io.bitsquare.user.User;
|
||||
import jersey.repackaged.com.google.common.collect.Lists;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bitcoinj.core.Coin;
|
||||
import org.bitcoinj.core.Transaction;
|
||||
|
@ -25,6 +27,8 @@ import java.math.BigDecimal;
|
|||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
/**
|
||||
* This class is a proxy for all bitsquare features the api will use.
|
||||
* <p>
|
||||
|
@ -70,9 +74,9 @@ public class BitsquareProxy {
|
|||
MarketList marketList = new MarketList();
|
||||
CurrencyList currencyList = getCurrencyList(); // we calculate this twice but only at startup
|
||||
//currencyList.getCurrencies().stream().flatMap(currency -> marketList.getMarkets().forEach(currency1 -> cur))
|
||||
List<Market> btc = CurrencyUtil.getAllSortedCryptoCurrencies().stream().filter(cryptoCurrency -> !(cryptoCurrency.getCode().equals("BTC"))).map(cryptoCurrency -> new Market(cryptoCurrency.getCode(), "BTC")).collect(Collectors.toList());
|
||||
List<Market> btc = CurrencyUtil.getAllSortedCryptoCurrencies().stream().filter(cryptoCurrency -> !(cryptoCurrency.getCode().equals("BTC"))).map(cryptoCurrency -> new Market(cryptoCurrency.getCode(), "BTC")).collect(toList());
|
||||
marketList.markets.addAll(btc);
|
||||
btc = CurrencyUtil.getAllSortedFiatCurrencies().stream().map(cryptoCurrency -> new Market("BTC", cryptoCurrency.getCode())).collect(Collectors.toList());
|
||||
btc = CurrencyUtil.getAllSortedFiatCurrencies().stream().map(cryptoCurrency -> new Market("BTC", cryptoCurrency.getCode())).collect(toList());
|
||||
marketList.markets.addAll(btc);
|
||||
Collections.sort(currencyList.currencies, (Currency p1, Currency p2) -> p1.name.compareTo(p2.name));
|
||||
return marketList;
|
||||
|
@ -111,35 +115,52 @@ public class BitsquareProxy {
|
|||
}
|
||||
|
||||
public List<OfferData> getOfferList() {
|
||||
List<OfferData> offer = offerBookService.getOffers().stream().map(offer1 -> new OfferData(offer1)).collect(Collectors.toList());
|
||||
List<OfferData> offer = offerBookService.getOffers().stream().map(offer1 -> new OfferData(offer1)).collect(toList());
|
||||
return offer;
|
||||
|
||||
}
|
||||
|
||||
public void offerMake(String market, String accountId, String direction, BigDecimal amount, BigDecimal minAmount,
|
||||
String fixed, String price) {
|
||||
public boolean offerMake(String market, String accountId, String direction, BigDecimal amount, BigDecimal minAmount,
|
||||
boolean marketPriceMargin, double marketPriceMarginParam, String currencyCode, String fiatPrice) {
|
||||
// TODO: detect bad direction, bad market, no paymentaccount for user
|
||||
// PaymentAccountUtil.isPaymentAccountValidForOffer
|
||||
Optional<Account> optionalAccount = getAccountList().getPaymentAccounts().stream()
|
||||
.filter(account1 -> account1.getPayment_account_id().equals(accountId)).findFirst();
|
||||
if(!optionalAccount.isPresent()) {
|
||||
// return an error
|
||||
return false;
|
||||
}
|
||||
Account account = optionalAccount.get();
|
||||
PaymentAccount paymentAccount = user.getPaymentAccount(account.getPayment_account_id());
|
||||
ArrayList<String> acceptedBanks = null;
|
||||
if (paymentAccount instanceof SpecificBanksAccount) {
|
||||
acceptedBanks = new ArrayList<>(((SpecificBanksAccount) paymentAccount).getAcceptedBanks());
|
||||
} else if (paymentAccount instanceof SameBankAccount) {
|
||||
acceptedBanks = new ArrayList<>();
|
||||
acceptedBanks.add(((SameBankAccount) paymentAccount).getBankId());
|
||||
}
|
||||
|
||||
Offer offer = new Offer(UUID.randomUUID().toString(),
|
||||
p2PService.getAddress(),
|
||||
keyRing.getPubKeyRing(),
|
||||
Offer.Direction.valueOf(direction),
|
||||
Long.valueOf(price),
|
||||
1, //marketPriceMarginParam,
|
||||
true, //useMarketBasedPrice.get(),
|
||||
Long.valueOf(fiatPrice),
|
||||
marketPriceMarginParam, //marketPriceMarginParam,
|
||||
marketPriceMargin, //useMarketBasedPrice.get(),
|
||||
amount.longValueExact(),
|
||||
minAmount.longValueExact(),
|
||||
"MR", // currencycode
|
||||
currencyCode, // currencycode
|
||||
(ArrayList<NodeAddress>) user.getAcceptedArbitratorAddresses(),
|
||||
getAccountList().getPaymentAccounts().stream().findAny().get().getPayment_method().toString(), //paymentAccount.getPaymentMethod().getId(),
|
||||
getAccountList().getPaymentAccounts().stream().findAny().get().getAccount_id(), //paymentAccount.getId(),
|
||||
null, //countryCode,
|
||||
null, //acceptedCountryCodes,
|
||||
null, //bankId,
|
||||
null, // acceptedBanks,
|
||||
account.getContract_data().getPayment_method_id(),
|
||||
account.getPayment_account_id(), //paymentAccount.getId(),
|
||||
account.getCountry().toString(), //countryCode,
|
||||
account.getAccepted_country_codes(), //acceptedCountryCodes,
|
||||
account.getBank_id(), //bankId,
|
||||
acceptedBanks, // acceptedBanks,
|
||||
priceFeedService); // priceFeedService);
|
||||
|
||||
offerBookService.addOffer(offer, () -> log.info("offer removed"), (err) -> log.error("Error removing offer: " + err));
|
||||
return true;
|
||||
}
|
||||
|
||||
public WalletDetails getWalletDetails() {
|
||||
|
@ -169,6 +190,6 @@ public class BitsquareProxy {
|
|||
.filter(paymentAccount -> paymentAccount instanceof CryptoCurrencyAccount)
|
||||
.map(paymentAccount -> (CryptoCurrencyAccount) paymentAccount)
|
||||
.map(paymentAccount -> new WalletAddress(((CryptoCurrencyAccount) paymentAccount).getId(), paymentAccount.getPaymentMethod().toString(), ((CryptoCurrencyAccount) paymentAccount).getAddress()))
|
||||
.collect(Collectors.toList());
|
||||
.collect(toList());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import java.util.stream.Collectors;
|
|||
/**
|
||||
* [
|
||||
* {
|
||||
* "account_id": "c4e4645a-18e6-45be-8853-c7ebac68f0a4",
|
||||
* "payment_account_id": "c4e4645a-18e6-45be-8853-c7ebac68f0a4",
|
||||
* "created": 1473010076100,
|
||||
* "payment_method": {
|
||||
* "payment_method_id": "SEPA",
|
||||
|
@ -68,7 +68,7 @@ import java.util.stream.Collectors;
|
|||
@Data
|
||||
public class Account {
|
||||
@JsonProperty
|
||||
public String account_id;
|
||||
public String payment_account_id;
|
||||
@JsonProperty
|
||||
long created;
|
||||
@JsonProperty
|
||||
|
@ -98,7 +98,7 @@ public class Account {
|
|||
|
||||
|
||||
public Account(PaymentAccount bitsquarePaymentAccount) {
|
||||
this.account_id = bitsquarePaymentAccount.getId();
|
||||
this.payment_account_id = bitsquarePaymentAccount.getId();
|
||||
this.created = bitsquarePaymentAccount.getCreationDate().toInstant().toEpochMilli();
|
||||
this.payment_method = new AccountPaymentMethod(bitsquarePaymentAccount.getPaymentMethod());
|
||||
this.account_name = bitsquarePaymentAccount.getAccountName();
|
||||
|
@ -107,5 +107,7 @@ public class Account {
|
|||
.map(tradeCurrency -> tradeCurrency.getCode()).collect(Collectors.toList());
|
||||
}
|
||||
this.contract_data = new ContractData(bitsquarePaymentAccount);
|
||||
this.bank_id = contract_data.getBank_id();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
|||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import io.bitsquare.payment.*;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -22,6 +23,7 @@ import java.util.List;
|
|||
},
|
||||
*/
|
||||
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||
@Data
|
||||
public class ContractData {
|
||||
PaymentAccountContractData contractData;
|
||||
@JsonProperty
|
||||
|
|
|
@ -121,7 +121,7 @@ public class ApiResource {
|
|||
/**
|
||||
* param type desc required values default
|
||||
* market string identifies the market this offer will be placed in 1
|
||||
* account_id string identifies the account to which funds will be received once offer is executed. 1
|
||||
* payment_account_id string identifies the account to which funds will be received once offer is executed. 1
|
||||
* direction string defines if this is an offer to buy or sell 1 sell | buy
|
||||
* amount real amount to buy or sell, in terms of left side of market pair 1
|
||||
* min_amount real minimum amount to buy or sell, in terms of left side of market pair 1
|
||||
|
@ -132,27 +132,27 @@ public class ApiResource {
|
|||
@GET
|
||||
@Timed
|
||||
@Path("/offer_make")
|
||||
public void offerMake(@QueryParam("market") String market,
|
||||
@QueryParam("account_id") String accountId,
|
||||
public boolean offerMake(@QueryParam("market") String market,
|
||||
@QueryParam("payment_account_id") String accountId,
|
||||
@QueryParam("direction") String direction,
|
||||
@QueryParam("amount") BigDecimal amount,
|
||||
@QueryParam("min_amount") BigDecimal minAmount,
|
||||
@DefaultValue("fixed") @QueryParam("price_type") String fixed,
|
||||
@DefaultValue("100") @QueryParam("price") String price) {
|
||||
bitsquareProxy.offerMake(market, accountId, direction, amount, minAmount, fixed, price);
|
||||
return bitsquareProxy.offerMake(market, accountId, direction, amount, minAmount, false, 100, "XMR", price);
|
||||
}
|
||||
|
||||
/**
|
||||
* param type desc required values default
|
||||
* offer_id string Identifies the offer to accept 1
|
||||
* account_id string Identifies the payment account to receive funds into 1
|
||||
* payment_account_id string Identifies the payment account to receive funds into 1
|
||||
* amount string amount to spend 1
|
||||
*/
|
||||
@GET
|
||||
@Timed
|
||||
@Path("/offer_take")
|
||||
public void offerTake(@QueryParam("offer_id") String offerId,
|
||||
@QueryParam("account_id") String accountId,
|
||||
@QueryParam("payment_account_id") String accountId,
|
||||
@QueryParam("amount") String amount) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -48,7 +48,6 @@ import javax.annotation.Nullable;
|
|||
import java.io.IOException;
|
||||
import java.security.PublicKey;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -102,14 +101,14 @@ public final class Offer implements StoragePayload, RequiresOwnerIsOnlinePayload
|
|||
@Nullable
|
||||
private final String countryCode;
|
||||
@Nullable
|
||||
private final ArrayList<String> acceptedCountryCodes;
|
||||
private final List<String> acceptedCountryCodes;
|
||||
|
||||
@Nullable
|
||||
private final String bankId;
|
||||
@Nullable
|
||||
private final ArrayList<String> acceptedBankIds;
|
||||
private final List<String> acceptedBankIds;
|
||||
|
||||
private final ArrayList<NodeAddress> arbitratorNodeAddresses;
|
||||
private final List<NodeAddress> arbitratorNodeAddresses;
|
||||
|
||||
|
||||
private final String id;
|
||||
|
@ -168,13 +167,13 @@ public final class Offer implements StoragePayload, RequiresOwnerIsOnlinePayload
|
|||
long amount,
|
||||
long minAmount,
|
||||
String currencyCode,
|
||||
ArrayList<NodeAddress> arbitratorNodeAddresses,
|
||||
List<NodeAddress> arbitratorNodeAddresses,
|
||||
String paymentMethodName,
|
||||
String offererPaymentAccountId,
|
||||
@Nullable String countryCode,
|
||||
@Nullable ArrayList<String> acceptedCountryCodes,
|
||||
@Nullable List<String> acceptedCountryCodes,
|
||||
@Nullable String bankId,
|
||||
@Nullable ArrayList<String> acceptedBankIds,
|
||||
@Nullable List<String> acceptedBankIds,
|
||||
PriceFeedService priceFeedService) {
|
||||
this.id = id;
|
||||
this.offererNodeAddress = offererNodeAddress;
|
||||
|
|
|
@ -22,7 +22,6 @@ import ch.qos.logback.classic.Logger;
|
|||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import io.bitsquare.alert.AlertManager;
|
||||
import io.bitsquare.api.service.DropwizardApplication;
|
||||
import io.bitsquare.arbitration.ArbitratorManager;
|
||||
import io.bitsquare.btc.WalletService;
|
||||
import io.bitsquare.common.CommonOptionKeys;
|
||||
|
|
|
@ -19,7 +19,6 @@ package io.bitsquare.app;
|
|||
|
||||
import com.google.inject.Singleton;
|
||||
import io.bitsquare.alert.AlertModule;
|
||||
import io.bitsquare.api.app.ApiModule;
|
||||
import io.bitsquare.arbitration.ArbitratorModule;
|
||||
import io.bitsquare.btc.BitcoinModule;
|
||||
import io.bitsquare.common.Clock;
|
||||
|
@ -119,6 +118,6 @@ class BitsquareAppModule extends AppModule {
|
|||
private GuiModule guiModule() {
|
||||
return new GuiModule(env, primaryStage);
|
||||
}
|
||||
private ApiModule apiModule() { return new ApiModule(env);
|
||||
}
|
||||
// private ApiModule apiModule() { return new ApiModule(env);
|
||||
// }
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue