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

[WIP (redo after atomic-tx merge)] Support XMR<->BTC trading via API #5691

Closed
wants to merge 43 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
96731b5
Define toString method
ghubstan Sep 9, 2021
aeedfd5
Adjust for XMR support
ghubstan Sep 9, 2021
5425843
Refactor for supporting creation of XMR accounts via API
ghubstan Sep 9, 2021
5d318f8
Refactor for supporting creation of XMR accounts via API
ghubstan Sep 9, 2021
0f17815
Add create bsq & xmr payment acct test cases
ghubstan Sep 9, 2021
dee8cc4
Don't run method test 2x from gradle
ghubstan Sep 9, 2021
fbd1f33
Merge branch 'master' into 2-create-xmr-payment-accts-via-api
ghubstan Sep 9, 2021
13d221c
Remove unused fields
ghubstan Sep 9, 2021
2fe1903
Update createoffer help text with BSQ & XMR examples
ghubstan Sep 10, 2021
f59247b
Adjust gRPC client & CLI opt parsers for XMR support
ghubstan Sep 10, 2021
80c02c4
Update required JDK version and target source version
ghubstan Sep 10, 2021
600d43f
Test create and edit XMR offers via API
ghubstan Sep 10, 2021
6507885
Adjust for xmr support
ghubstan Sep 10, 2021
91cd3d4
Minor refactor / remove a bit of duplication
ghubstan Sep 10, 2021
7a46d23
Fill out / refactor CLI getoffers smoke test
ghubstan Sep 10, 2021
233261d
Make codacy happy
ghubstan Sep 10, 2021
e90797d
Adjust for XMR (more generic) altcoin support in API
ghubstan Sep 11, 2021
39c2f5d
Add XMR/BTC trade pair tests & refactor trade tests
ghubstan Sep 11, 2021
76feac6
Adjust trade-simulation-utils.sh for altcoin trading
ghubstan Sep 11, 2021
b6e9c80
Add parsexmrscriptopts function
ghubstan Sep 11, 2021
934dae2
Update JDK requirement comment, fix typo
ghubstan Sep 11, 2021
5967a8b
Add trade-xmr-simulation script
ghubstan Sep 11, 2021
0583e45
Fix fee-currency spec error, adjust description
ghubstan Sep 11, 2021
cf18676
Make xmr address var local, not global
ghubstan Sep 11, 2021
dfcaeda
Adjust for market-price-margin based xmr offers
ghubstan Sep 12, 2021
feb5f7a
Add createoffer tests (price-margin based xmr offers)
ghubstan Sep 12, 2021
1be1132
Merge branch '3-create-xmr-offers' into 4-trade-xmr-btc
ghubstan Sep 12, 2021
cdf6d97
Change xmr trade test case to use price margin based offer
ghubstan Sep 12, 2021
707a367
Adjust xmr simulation script for price margin based offer
ghubstan Sep 12, 2021
16442c8
Conditionally display altcoin offer trigger price
ghubstan Sep 13, 2021
2f32692
Correctly scale CLI's 'editoffer' trigger-price param
ghubstan Sep 13, 2021
beeaa85
Adjust core 'editoffer' validation for XMR offers
ghubstan Sep 13, 2021
09edef5
Add static "GBP" field for test cases
ghubstan Sep 13, 2021
3a480e8
Adjust test cases to scaling 'editoffer' trigger-price
ghubstan Sep 13, 2021
09cdaae
Allow API to look up altcoin market prices
ghubstan Sep 14, 2021
79d40c8
Test XMR offer.trigger-price definition, edit & display
ghubstan Sep 14, 2021
4255742
Merge branch 'master' into 4-trade-xmr-btc
ghubstan Sep 14, 2021
c233297
Add TODO commment above placeholder for future swift test
ghubstan Sep 16, 2021
e79cdfe
Return early when field name match fails
ghubstan Sep 16, 2021
47a9949
Merge branch 'master' into 4-trade-xmr-btc
ghubstan Sep 18, 2021
36467dd
Remove duplicated line
ghubstan Sep 18, 2021
2c631fe
Merge API's trade.volume bugfix (PR 5704)
ghubstan Sep 21, 2021
545e83c
Merge branch 'master' into 4-trade-xmr-btc
ghubstan Sep 21, 2021
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
Expand Up @@ -44,6 +44,7 @@
import static protobuf.OfferPayload.Direction.BUY;
import static protobuf.OfferPayload.Direction.SELL;

@SuppressWarnings("ConstantConditions")
@Disabled
@Slf4j
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
Expand All @@ -59,7 +60,7 @@ public static void setUp() {

@Test
@Order(1)
public void testCreateBuy1BTCFor200KXMROffer() {
public void testCreateFixedPriceBuy1BTCFor200KXMROffer() {
// Remember alt coin trades are BTC trades. When placing an offer, you are
// offering to buy or sell BTC, not BSQ, XMR, etc. In this test case,
// Alice places an offer to BUY BTC with BSQ.
Expand Down Expand Up @@ -108,7 +109,7 @@ public void testCreateBuy1BTCFor200KXMROffer() {

@Test
@Order(2)
public void testCreateSell1BTCFor200KXMROffer() {
public void testCreateFixedPriceSell1BTCFor200KXMROffer() {
// Alice places an offer to SELL BTC for XMR.
var newOffer = aliceClient.createFixedPricedOffer(SELL.name(),
XMR,
Expand Down Expand Up @@ -155,19 +156,112 @@ public void testCreateSell1BTCFor200KXMROffer() {

@Test
@Order(3)
public void testCreatePriceMarginBasedBuy1BTCOffer() {
double priceMarginPctInput = 1.00;
var newOffer = aliceClient.createMarketBasedPricedOffer(BUY.name(),
XMR,
100_000_000L,
75_000_000L,
priceMarginPctInput,
getDefaultBuyerSecurityDepositAsPercent(),
alicesXmrAcct.getId(),
MAKER_FEE_CURRENCY_CODE,
NO_TRIGGER_PRICE);
log.info("Sell XMR (Buy BTC) OFFER:\n{}", formatOfferTable(singletonList(newOffer), XMR));
assertTrue(newOffer.getIsMyOffer());
assertTrue(newOffer.getIsMyPendingOffer());

String newOfferId = newOffer.getId();
assertNotEquals("", newOfferId);
assertEquals(BUY.name(), newOffer.getDirection());
assertTrue(newOffer.getUseMarketBasedPrice());
assertEquals(100_000_000L, newOffer.getAmount());
assertEquals(75_000_000L, newOffer.getMinAmount());
assertEquals(15_000_000, newOffer.getBuyerSecurityDeposit());
assertEquals(alicesXmrAcct.getId(), newOffer.getPaymentAccountId());
assertEquals(XMR, newOffer.getBaseCurrencyCode());
assertEquals(BTC, newOffer.getCounterCurrencyCode());
assertFalse(newOffer.getIsCurrencyForMakerFeeBtc());

genBtcBlockAndWaitForOfferPreparation();

newOffer = aliceClient.getMyOffer(newOfferId);
assertTrue(newOffer.getIsMyOffer());
assertFalse(newOffer.getIsMyPendingOffer());
assertEquals(newOfferId, newOffer.getId());
assertEquals(BUY.name(), newOffer.getDirection());
assertTrue(newOffer.getUseMarketBasedPrice());
assertEquals(100_000_000L, newOffer.getAmount());
assertEquals(75_000_000L, newOffer.getMinAmount());
assertEquals(15_000_000, newOffer.getBuyerSecurityDeposit());
assertEquals(alicesXmrAcct.getId(), newOffer.getPaymentAccountId());
assertEquals(XMR, newOffer.getBaseCurrencyCode());
assertEquals(BTC, newOffer.getCounterCurrencyCode());
assertFalse(newOffer.getIsCurrencyForMakerFeeBtc());
}

@Test
@Order(4)
public void testCreatePriceMarginBasedSell1BTCOffer() {
// Alice places an offer to SELL BTC for XMR.
double priceMarginPctInput = 0.50;
var newOffer = aliceClient.createMarketBasedPricedOffer(SELL.name(),
XMR,
100_000_000L,
50_000_000L,
priceMarginPctInput,
getDefaultBuyerSecurityDepositAsPercent(),
alicesXmrAcct.getId(),
MAKER_FEE_CURRENCY_CODE,
NO_TRIGGER_PRICE);
log.info("Buy XMR (Sell BTC) OFFER:\n{}", formatOfferTable(singletonList(newOffer), XMR));
assertTrue(newOffer.getIsMyOffer());
assertTrue(newOffer.getIsMyPendingOffer());

String newOfferId = newOffer.getId();
assertNotEquals("", newOfferId);
assertEquals(SELL.name(), newOffer.getDirection());
assertTrue(newOffer.getUseMarketBasedPrice());
assertEquals(100_000_000L, newOffer.getAmount());
assertEquals(50_000_000L, newOffer.getMinAmount());
assertEquals(15_000_000, newOffer.getBuyerSecurityDeposit());
assertEquals(alicesXmrAcct.getId(), newOffer.getPaymentAccountId());
assertEquals(XMR, newOffer.getBaseCurrencyCode());
assertEquals(BTC, newOffer.getCounterCurrencyCode());
assertFalse(newOffer.getIsCurrencyForMakerFeeBtc());

genBtcBlockAndWaitForOfferPreparation();

newOffer = aliceClient.getMyOffer(newOfferId);
assertTrue(newOffer.getIsMyOffer());
assertFalse(newOffer.getIsMyPendingOffer());
assertEquals(newOfferId, newOffer.getId());
assertEquals(SELL.name(), newOffer.getDirection());
assertTrue(newOffer.getUseMarketBasedPrice());
assertEquals(100_000_000L, newOffer.getAmount());
assertEquals(50_000_000L, newOffer.getMinAmount());
assertEquals(15_000_000, newOffer.getBuyerSecurityDeposit());
assertEquals(alicesXmrAcct.getId(), newOffer.getPaymentAccountId());
assertEquals(XMR, newOffer.getBaseCurrencyCode());
assertEquals(BTC, newOffer.getCounterCurrencyCode());
assertFalse(newOffer.getIsCurrencyForMakerFeeBtc());
}

@Test
@Order(5)
public void testGetAllMyXMROffers() {
List<OfferInfo> offers = aliceClient.getMyCryptoCurrencyOffersSortedByDate(XMR);
log.info("ALL ALICE'S XMR OFFERS:\n{}", formatOfferTable(offers, XMR));
assertEquals(2, offers.size());
assertEquals(4, offers.size());
log.info("ALICE'S BALANCES\n{}", formatBalancesTbls(aliceClient.getBalances()));
}

@Test
@Order(4)
@Order(6)
public void testGetAvailableXMROffers() {
List<OfferInfo> offers = bobClient.getCryptoCurrencyOffersSortedByDate(XMR);
log.info("ALL BOB'S AVAILABLE XMR OFFERS:\n{}", formatOfferTable(offers, XMR));
assertEquals(2, offers.size());
assertEquals(4, offers.size());
log.info("BOB'S BALANCES\n{}", formatBalancesTbls(bobClient.getBalances()));
}

Expand Down
6 changes: 4 additions & 2 deletions apitest/src/test/java/bisq/apitest/scenario/OfferTest.java
Expand Up @@ -94,8 +94,10 @@ public void testCreateBSQOffers() {
public void testCreateXMROffers() {
CreateXMROffersTest test = new CreateXMROffersTest();
CreateXMROffersTest.createXmrPaymentAccounts();
test.testCreateBuy1BTCFor200KXMROffer();
test.testCreateSell1BTCFor200KXMROffer();
test.testCreateFixedPriceBuy1BTCFor200KXMROffer();
test.testCreateFixedPriceSell1BTCFor200KXMROffer();
test.testCreatePriceMarginBasedBuy1BTCOffer();
test.testCreatePriceMarginBasedSell1BTCOffer();
test.testGetAllMyXMROffers();
test.testGetAvailableXMROffers();
}
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/resources/help/createoffer-help.txt
Expand Up @@ -95,14 +95,14 @@ $ ./bisq-cli --password=xyz --port=9998 createoffer --payment-account=1473d263-2
--fee-currency=btc

To create a SELL 0.025 BTC for XMR offer
at a fixed XMR price of 0.005 BTC,
at a market price margin of 0.50 percent above current XMR market price,
using a payment account with ID 1373d263-225a-4f1b-837a-1e3094dc0e32,
putting up a 30 percent security deposit,
putting up a 25 percent security deposit,
and paying the Bisq maker trading fee in BSQ:
$ ./bisq-cli --password=xyz --port=9998 createoffer --payment-account=1373d263-225a-4f1b-837a-1e3094dc0e32 \
--direction=sell \
--currency-code=xmr \
--amount=0.025 \
--fixed-price=0.005 \
--security-deposit=30.0 \
--market-price-margin=0.50 \
--security-deposit=25.0 \
--fee-currency=bsq