Skip to content

Commit

Permalink
Merge pull request #6057 from ghubstan/3-change-grpc-proto-triggerpri…
Browse files Browse the repository at this point in the history
…ce-to-string

Change API grpc.proto triggerPrice field to string [#3]
  • Loading branch information
ripcurlx authored Feb 28, 2022
2 parents c471936 + 2af3ac2 commit 068fedb
Show file tree
Hide file tree
Showing 22 changed files with 158 additions and 186 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

import java.util.ArrayList;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Function;

import lombok.Setter;
Expand Down Expand Up @@ -63,7 +62,7 @@ public abstract class AbstractOfferTest extends MethodTest {

protected static final int ACTIVATE_OFFER = 1;
protected static final int DEACTIVATE_OFFER = 0;
protected static final long NO_TRIGGER_PRICE = 0;
protected static final String NO_TRIGGER_PRICE = "0";

@Setter
protected static boolean isLongRunningTest;
Expand Down Expand Up @@ -95,22 +94,6 @@ public static void setUp() {
protected final Function<Double, Double> scaledDownMktPriceMargin = (mktPriceMargin) ->
exactMultiply(mktPriceMargin, 0.01);

// Price value of fiat offer returned from server will be scaled up by 10^4.
protected final Function<BigDecimal, Long> scaledUpFiatOfferPrice = (price) -> {
BigDecimal factor = new BigDecimal(10).pow(4);
return price.multiply(factor).longValue();
};

protected final BiFunction<Double, Double, Long> calcFiatTriggerPriceAsLong = (base, delta) -> {
var priceAsDouble = new BigDecimal(base).add(new BigDecimal(delta)).doubleValue();
return Double.valueOf(exactMultiply(priceAsDouble, 10_000)).longValue();
};

protected final BiFunction<Double, Double, Long> calcAltcoinTriggerPriceAsLong = (base, delta) -> {
var priceAsDouble = new BigDecimal(base).add(new BigDecimal(delta)).doubleValue();
return Double.valueOf(exactMultiply(priceAsDouble, 100_000_000)).longValue();
};

protected final Function<OfferInfo, String> toOfferTable = (offer) ->
new TableBuilder(OFFER_TBL, offer).build().toString();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package bisq.apitest.method.offer;

import bisq.core.monetary.Price;
import bisq.core.payment.PaymentAccount;

import bisq.proto.grpc.OfferInfo;
Expand Down Expand Up @@ -255,10 +254,7 @@ public void testCreateBRLBTCSellOffer6Point55PctPriceMargin() {
public void testCreateUSDBTCBuyOfferWithTriggerPrice() {
PaymentAccount usdAccount = createDummyF2FAccount(aliceClient, "US");
double mktPriceAsDouble = aliceClient.getBtcPrice("usd");
BigDecimal mktPrice = new BigDecimal(Double.toString(mktPriceAsDouble));
BigDecimal triggerPrice = mktPrice.add(new BigDecimal("1000.9999"));
long triggerPriceAsLong = Price.parse(USD, triggerPrice.toString()).getValue();

String triggerPrice = calcPriceAsString(mktPriceAsDouble, Double.parseDouble("1000.9999"), 4);
var newOffer = aliceClient.createMarketBasedPricedOffer(BUY.name(),
"usd",
10_000_000L,
Expand All @@ -267,7 +263,7 @@ public void testCreateUSDBTCBuyOfferWithTriggerPrice() {
getDefaultBuyerSecurityDepositAsPercent(),
usdAccount.getId(),
MAKER_FEE_CURRENCY_CODE,
triggerPriceAsLong);
triggerPrice);
assertTrue(newOffer.getIsMyOffer());
assertTrue(newOffer.getIsMyPendingOffer());

Expand All @@ -276,7 +272,7 @@ public void testCreateUSDBTCBuyOfferWithTriggerPrice() {
log.debug("OFFER #5:\n{}", toOfferTable.apply(newOffer));
assertTrue(newOffer.getIsMyOffer());
assertFalse(newOffer.getIsMyPendingOffer());
assertEquals(triggerPriceAsLong, newOffer.getTriggerPrice());
assertEquals(triggerPrice, newOffer.getTriggerPrice());
}

private void assertCalculatedPriceIsCorrect(OfferInfo offer, double priceMarginPctInput) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public void testCreateFixedPriceSell1BTCFor200KXMROffer() {
public void testCreatePriceMarginBasedBuy1BTCOfferWithTriggerPrice() {
double priceMarginPctInput = 1.00;
double mktPriceAsDouble = aliceClient.getBtcPrice(XMR);
long triggerPriceAsLong = calcAltcoinTriggerPriceAsLong.apply(mktPriceAsDouble, -0.001);
String triggerPrice = calcPriceAsString(mktPriceAsDouble, Double.parseDouble("-0.001"), 8);
var newOffer = aliceClient.createMarketBasedPricedOffer(BUY.name(),
XMR,
100_000_000L,
Expand All @@ -165,7 +165,7 @@ public void testCreatePriceMarginBasedBuy1BTCOfferWithTriggerPrice() {
getDefaultBuyerSecurityDepositAsPercent(),
alicesXmrAcct.getId(),
MAKER_FEE_CURRENCY_CODE,
triggerPriceAsLong);
triggerPrice);
log.debug("Pending Sell XMR (Buy BTC) offer:\n{}", toOfferTable.apply(newOffer));
assertTrue(newOffer.getIsMyOffer());
assertTrue(newOffer.getIsMyPendingOffer());
Expand All @@ -176,7 +176,7 @@ public void testCreatePriceMarginBasedBuy1BTCOfferWithTriggerPrice() {
assertTrue(newOffer.getUseMarketBasedPrice());

// There is no trigger price while offer is pending.
assertEquals(0, newOffer.getTriggerPrice());
assertEquals(NO_TRIGGER_PRICE, newOffer.getTriggerPrice());

assertEquals(100_000_000L, newOffer.getAmount());
assertEquals(75_000_000L, newOffer.getMinAmount());
Expand All @@ -197,7 +197,7 @@ public void testCreatePriceMarginBasedBuy1BTCOfferWithTriggerPrice() {
assertTrue(newOffer.getUseMarketBasedPrice());

// The trigger price should exist on the prepared offer.
assertEquals(triggerPriceAsLong, newOffer.getTriggerPrice());
assertEquals(triggerPrice, newOffer.getTriggerPrice());

assertEquals(100_000_000L, newOffer.getAmount());
assertEquals(75_000_000L, newOffer.getMinAmount());
Expand Down
Loading

0 comments on commit 068fedb

Please sign in to comment.