Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build out 'createoffer' API method #4559

Merged
merged 52 commits into from Oct 3, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
9132722
Replace hardcoded version with Version.java value
ghubstan Sep 22, 2020
34cfe95
Remove comment
ghubstan Sep 22, 2020
8896372
Move test dispute agent type constants to core
ghubstan Sep 22, 2020
1f307c8
Fix indentation
ghubstan Sep 22, 2020
6a50402
Add simple create payment acct test
ghubstan Sep 22, 2020
1d88d27
Remove final modifiers
ghubstan Sep 22, 2020
c4dd041
Don't use static boilerplate helpers if not necessary
ghubstan Sep 22, 2020
e63a6c5
Remove comment
ghubstan Sep 22, 2020
92f36ed
Add get default payment acct helper
ghubstan Sep 23, 2020
2b68e57
Stub out createoffer method in CLI
ghubstan Sep 23, 2020
3c0c443
Change API's createoffer return value from bool to Offer
ghubstan Sep 23, 2020
70e3be0
Add API CreateOfferTest case
ghubstan Sep 23, 2020
fc1f0ba
Fix imports
ghubstan Sep 23, 2020
d190d09
Fix unnecessary use of fully qualified name
ghubstan Sep 23, 2020
adb175c
Add options helper for handling negative number CLI params
ghubstan Sep 23, 2020
1431a07
Add license comment
ghubstan Sep 23, 2020
d5b8800
Add license comment and btc-string to satoshi converter
ghubstan Sep 23, 2020
c8a7fe4
Print createoffer's reply in the CLI's console
ghubstan Sep 23, 2020
a6048a4
Add comment to empty catch block for codacy
ghubstan Sep 23, 2020
ec9c1b0
Uppercase direction & ccy-code CLI arguments in core
ghubstan Sep 24, 2020
9999c95
Change 'createoffer' argument order
ghubstan Sep 24, 2020
942a6f2
Scale & convert (double) fixed price input to long
ghubstan Sep 24, 2020
6cdbc13
Move 'createoffer' price arg transform to server & test it
ghubstan Sep 24, 2020
96278b9
Push currencyCode.toUpperCase conversion below CoreApi
ghubstan Sep 25, 2020
995af0d
Convert mktPriceMargin to %, make createAndPlaceOffer private
ghubstan Sep 25, 2020
6cf9bbb
Minor createoffer test changes
ghubstan Sep 25, 2020
3b51824
Do not reassign currencyCode parameter
ghubstan Sep 25, 2020
82ce864
Delete trailing spaces from blank line for codacy
ghubstan Sep 25, 2020
2f3e3a3
Add simple mkt-price service & test calculated offer prices
ghubstan Sep 25, 2020
18df1e2
Fix abs(dbl) comparison
ghubstan Sep 25, 2020
92042d7
Remove unused import
ghubstan Sep 25, 2020
de3105a
Add license comment
ghubstan Sep 25, 2020
96abda4
Tidy up create offer using mkt price margin % test
ghubstan Sep 26, 2020
35a77be
Redefine DisputeAgentType REFUNDAGENT as REFUND_AGENT
ghubstan Sep 27, 2020
7053169
Fix asserts
ghubstan Sep 27, 2020
82b7b79
Factor out duplicated OfferInfo wrapping
ghubstan Sep 27, 2020
50d4b9f
Fix 'switch statements should have a default label' codacy problem
ghubstan Sep 27, 2020
d9ece9f
Revert "Fix 'switch statements should have a default label' codacy pr…
ghubstan Sep 27, 2020
f376153
Codacy requires default label in switch
ghubstan Sep 28, 2020
94996a5
Fix tx result handling in GrpcOffersService
ghubstan Sep 28, 2020
fa5c21c
Fix BitcoinCli wrapper create bug
ghubstan Sep 28, 2020
fc94b97
Throw exception to CLI if attempted offer placement fails
ghubstan Sep 28, 2020
cfe22c3
Make task handler's error msg CLI friendly (needs review)
ghubstan Sep 28, 2020
23a677d
Use list.set, not list.remove, list.add
ghubstan Oct 2, 2020
e09b821
Explain use of args clone index (i-1)
ghubstan Oct 2, 2020
628c557
Revert "Make task handler's error msg CLI friendly (needs review)"
ghubstan Oct 2, 2020
631c3f4
Log provenance of Task error on server, but pass only exception msg t…
ghubstan Oct 2, 2020
0332711
Ignore codacy complaint about (dead) default switch labels
ghubstan Oct 2, 2020
f1693a6
Add switch statement break to make codacy happy
ghubstan Oct 2, 2020
c71ad84
Change 'break' to 'return' at end of switch.
ghubstan Oct 2, 2020
723fc8f
Skip over method name in args loop, start at i=1
ghubstan Oct 2, 2020
d3d6d98
Revert all changes since commit d55114e
ghubstan Oct 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions cli/src/main/java/bisq/cli/CliMain.java
Expand Up @@ -45,6 +45,7 @@

import lombok.extern.slf4j.Slf4j;

import static bisq.cli.CurrencyFormat.fixedPriceToLong;
import static bisq.cli.CurrencyFormat.formatSatoshis;
import static bisq.cli.CurrencyFormat.toSatoshis;
import static bisq.cli.NegativeNumberOptions.hasNegativeNumberOptions;
Expand Down Expand Up @@ -200,12 +201,12 @@ public static void run(String[] args) {
var amount = toSatoshis(nonOptionArgs.get(4));
var minAmount = toSatoshis(nonOptionArgs.get(5));
var useMarketBasedPrice = Boolean.parseBoolean(nonOptionArgs.get(6));
var fixedPrice = ZERO;
var fixedPrice = 0L;
var marketPriceMargin = ZERO;
if (useMarketBasedPrice)
marketPriceMargin = new BigDecimal(nonOptionArgs.get(7));
else
fixedPrice = new BigDecimal(nonOptionArgs.get(7));
else // Scale and convert the (double) fixed price to a long.
fixedPrice = fixedPriceToLong(nonOptionArgs.get(7));
var securityDeposit = new BigDecimal(nonOptionArgs.get(8));

var request = CreateOfferRequest.newBuilder()
Expand All @@ -214,7 +215,7 @@ public static void run(String[] args) {
.setAmount(amount)
.setMinAmount(minAmount)
.setUseMarketBasedPrice(useMarketBasedPrice)
.setPrice(fixedPrice.longValue())
.setPrice(fixedPrice)
.setMarketPriceMargin(marketPriceMargin.doubleValue())
.setBuyerSecurityDeposit(securityDeposit.doubleValue())
.setPaymentAccountId(paymentAcctId)
Expand Down
10 changes: 10 additions & 0 deletions cli/src/main/java/bisq/cli/CurrencyFormat.java
Expand Up @@ -17,6 +17,8 @@

package bisq.cli;

import com.google.common.math.DoubleMath;

import java.text.DecimalFormat;
import java.text.NumberFormat;

Expand All @@ -26,6 +28,7 @@
import java.util.Locale;

import static java.lang.String.format;
import static java.math.RoundingMode.HALF_UP;

class CurrencyFormat {

Expand Down Expand Up @@ -74,4 +77,11 @@ static long toSatoshis(String btc) {
throw new IllegalArgumentException(format("'%s' is not a number", btc));
}
}

static long fixedPriceToLong(String fixedPrice) {
BigDecimal priceInput = new BigDecimal(fixedPrice);
int precision = 2;
double factor = Math.pow(priceInput.doubleValue(), precision);
return DoubleMath.roundToLong(factor, HALF_UP);
}
}