Split API examples & doc generator into separate modules

This might give Python devs an easier time than if all the sample
code lived deep inside a gradle project.  This means there is
no root project gradle build file;  the reference-doc-builder and
java-examples modules are separate java projects, with their own
build files.
This commit is contained in:
ghubstan 2022-03-16 17:21:25 -03:00
parent 4d942afd6b
commit cffbfcf481
No known key found for this signature in database
GPG Key ID: E35592D6800A861E
266 changed files with 14818 additions and 0 deletions

46
.gitignore vendored Normal file
View File

@ -0,0 +1,46 @@
.idea
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
# Files generated by build, execution
cli-examples/*.iml
java-examples/*.iml
java-examples/build
java-examples/.gradle
java-examples/src/main/proto/*
proto-downloader/*.iml
python-examples/*.iml
python-examples/bisq/api/__pycache__/
python-examples/bisq/api/*.py
python-examples/bots/__pycache__
python-examples/bots/events/__pycache__
python-examples/proto/*
reference-doc-builder/*.iml
reference-doc-builder/build
reference-doc-builder/.gradle
scratch
*/out
index.html.md
测试文档.md

54
README.md Normal file
View File

@ -0,0 +1,54 @@
# Bisq API Reference Doc Generator
[Produces Bisq API Reference Doc.](https://bisq-network.github.io/slate)
## What is bisq-api-reference?
This application script consumes Bisq .proto files (`pb.proto` and `grpc.proto`), and produces
`index.html.md` -- a [Slate](https://github.com/slatedocs/slate) compatible Markdown file.
_Note: For Python proto generation to work properly, the .proto files must be copied to the project's proto
directory from the remote or local GitHub repo. They are not versioned in this project repo._
The Markdown file is then manually deployed to a developer's or bisq-network's fork of the
[Slate repository](https://github.com/slatedocs/slate), where the slate fork transforms it to a single html file
describing Bisq gRPC API services, with example code.
## Usage
1. [Fork Slate](https://github.com/slatedocs/slate)
2. Run `BisqApiDocMain`:
```asciidoc
BisqApiDocMain --protosIn=<path-to-bisq-protub-files>/proto
\ --markdownOut=<path-to-slate-home>/source
\ --failOnMissingDocumentation=false
```
3. Commit changes in your local slate/source file (`index.html.md`) _to your forked slate repo_.
```asciidoc
git commit -a -m "Update index.html.md"
```
4. Run slate's `deploy.sh` script
5. After a few minutes, see changes on in your forked slate's github pages site. For example,</br>
if your `index.html.md` file was deployed to bisq-network, the URL will be
https://bisq-network.github.io/slate.
## Credits
Credit to [Juntao Han](https://github.com/mstao) for making his [markdown4j](https://github.com/mstao/markdown4j)
API available for use in this project. His source code is included in this project, modified in ways to make
generated markdown blocks compatible with Slate/GitHub style markdown.
Lombok annotations are also replaced by the implementations they would generate if that had worked in my
gradle development setup.

4
cli-examples/CancelOffer.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
source "env.sh"
$BISQ_HOME/bisq-cli --password=xyz --port=9998 canceloffer \
--offer-id=83e8b2e2-51b6-4f39-a748-3ebd29c22aea

3
cli-examples/CloseTrade.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
source "env.sh"
$BISQ_HOME/bisq-cli --password=xyz --port=9998 closetrade --trade-id=83e8b2e2-51b6-4f39-a748-3ebd29c22aea

View File

@ -0,0 +1,5 @@
#!/bin/bash
source "env.sh"
# Send message to BTC buyer that payment has been received.
$BISQ_HOME/bisq-cli --password=xyz --port=9998 confirmpaymentreceived \
--trade-id=83e8b2e2-51b6-4f39-a748-3ebd29c22aea

View File

@ -0,0 +1,5 @@
#!/bin/bash
source "env.sh"
# Send message to BTC seller that payment has been sent.
$BISQ_HOME/bisq-cli --password=xyz --port=9998 confirmpaymentstarted \
--trade-id=83e8b2e2-51b6-4f39-a748-3ebd29c22aea

View File

@ -0,0 +1,9 @@
#!/bin/bash
source "env.sh"
$BISQ_HOME/bisq-cli --password=xyz --port=9998 createoffer \
--swap=true \
--direction=BUY \
--currency-code=BSQ \
--amount=0.50 \
--min-amount=0.25 \
--fixed-price=0.00005

View File

@ -0,0 +1,7 @@
#!/bin/bash
source "env.sh"
$BISQ_HOME/bisq-cli --password=xyz --port=9998 createcryptopaymentacct \
--account-name="My XMR Payment Account" \
--currency-code=XMR \
--address=4AsjtNXChh3Va58czCWHjn9S8ZFnsxggGZoSePauBHmSMr8vY5aBSqrPtQ9Y9M1iwkBHxcuTWXJsJ4NDATQjQJyKBXR7WP7 \
--trade-instant=false

32
cli-examples/CreateOffer.sh Executable file
View File

@ -0,0 +1,32 @@
#!/bin/bash
source "env.sh"
# Create a fixed-price offer to buy BTC with EUR.
$BISQ_HOME/bisq-cli --password=xyz --port=9998 createoffer \
--payment-account-id=f3c1ec8b-9761-458d-b13d-9039c6892413 \
--direction=BUY \
--currency-code=EUR \
--amount=0.125 \
--min-amount=0.0625 \
--fixed-price=34500 \
--security-deposit=15.0 \
--fee-currency=BSQ
# Create a market-price-margin based offer to sell BTC for JPY, at 0.5% above the current market JPY price.
$BISQ_HOME/bisq-cli --password=xyz --port=9998 createoffer \
--payment-account-id=f3c1ec8b-9761-458d-b13d-9039c6892413 \
--direction=SELL \
--currency-code=JPY \
--amount=0.125 \
--min-amount=0.0625 \
--market-price-margin=0.5 \
--security-deposit=15.0 \
--fee-currency=BSQ
# Create an offer to swap 0.5 BTC for BSQ, at a price of 0.00005 BTC for 1 BSQ
$BISQ_HOME/bisq-cli --password=xyz --port=9998 createoffer \
--swap=true \
--direction=BUY \
--currency-code=BSQ \
--amount=0.5 \
--fixed-price=0.00005

View File

@ -0,0 +1,4 @@
#!/bin/bash
source "env.sh"
# Create a swift fiat payment account, providing details in a json form generated by getpaymentacctform.
$BISQ_HOME/bisq-cli --password=xyz --port=9998 createpaymentacct --payment-account-form=swift.json

44
cli-examples/EditOffer.sh Executable file
View File

@ -0,0 +1,44 @@
#!/bin/bash
source "env.sh"
# Warning: Editing an offer involves removing it from the offer book, then re-publishing
# it with the changes. This operation takes a few seconds and clients should not try
# to make rapid changes to the same offer; there must be a delay before each edit request
# for the same offer.
# Disable an offer.
$BISQ_HOME/bisq-cli --password=xyz --port=9998 editoffer \
--offer-id=83e8b2e2-51b6-4f39-a748-3ebd29c22aea \
--enable=false
# Enable an offer.
$BISQ_HOME/bisq-cli --password=xyz --port=9998 editoffer \
--offer-id=83e8b2e2-51b6-4f39-a748-3ebd29c22aea \
--enable=true
# Edit the fixed-price, and/or change a market price margin based offer to a fixed-price offer.
$BISQ_HOME/bisq-cli --password=xyz --port=9998 editoffer \
--offer-id=83e8b2e2-51b6-4f39-a748-3ebd29c22aea \
--fixed-price=35000.5555
# Edit the price margin, and/or change a fixed-price offer to a market price margin based offer.
$BISQ_HOME/bisq-cli --password=xyz --port=9998 editoffer \
--offer-id=83e8b2e2-51b6-4f39-a748-3ebd29c22aea \
--market-price-margin=0.5
# Set the trigger price on a market price margin based offer.
# Note: trigger prices do not apply to fixed-price offers.
$BISQ_HOME/bisq-cli --password=xyz --port=9998 editoffer \
--offer-id=83e8b2e2-51b6-4f39-a748-3ebd29c22aea \
--trigger-price=3960000.0000
# Remove the trigger price from a market price margin based offer.
$BISQ_HOME/bisq-cli --password=xyz --port=9998 editoffer \
--trigger-price=0
# Change a disabled fixed-price offer to a market price margin based offer, set a trigger price, and enable it.
$BISQ_HOME/bisq-cli --password=xyz --port=9998 editoffer \
--offer-id=83e8b2e2-51b6-4f39-a748-3ebd29c22aea \
--market-price-margin=0.5 \
--trigger-price=33000.0000 \
--enable=true

3
cli-examples/FailTrade.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
source "env.sh"
$BISQ_HOME/bisq-cli --password=xyz --port=9998 failtrade --trade-id=83e8b2e2-51b6-4f39-a748-3ebd29c22aea

View File

@ -0,0 +1,3 @@
#!/bin/bash
source "env.sh"
$BISQ_HOME/bisq-cli --password=xyz --port=9998 getaddressbalance --address=bcrt1qygvsqmyt8jyhtp7l3zwqm7s7v3nar6vkc2luz3

5
cli-examples/GetBalances.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
source "env.sh"
$BISQ_HOME/bisq-cli --password=xyz --port=9998 getbalance
$BISQ_HOME/bisq-cli --password=xyz --port=9998 getbalance --currency-code=BSQ
$BISQ_HOME/bisq-cli --password=xyz --port=9998 getbalance --currency-code=BTC

View File

@ -0,0 +1,4 @@
#!/bin/bash
source "env.sh"
$BISQ_HOME/bisq-cli --password=xyz --port=9998 getoffer \
--offer-id=83e8b2e2-51b6-4f39-a748-3ebd29c22aea

View File

@ -0,0 +1,6 @@
#!/bin/bash
source "env.sh"
# Get available BSQ swap offers to buy BTC with BSQ.
$BISQ_HOME/bisq-cli --password=xyz --port=9998 getoffers --direction=BUY --currency-code=BSQ
# Get available BSQ swap offers to sell BTC for BSQ.
$BISQ_HOME/bisq-cli --password=xyz --port=9998 getoffers --direction=SELL --currency-code=BSQ

View File

@ -0,0 +1,2 @@
#!/bin/bash
# Not yet supported in CLI. API currently supports only BSQ, BSQ Swap, and XMR trading.

View File

@ -0,0 +1,3 @@
#!/bin/bash
source "env.sh"
$BISQ_HOME/bisq-cli --password=xyz --port=9998 getfundingaddresses

4
cli-examples/GetMarketPrice.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
source "env.sh"
# Get most recently available market price of XMR in BTC.
$BISQ_HOME/bisq-cli --password=xyz --port=9998 getbtcprice --currency-code=XMR

3
cli-examples/GetMethodHelp.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
source "env.sh"
$BISQ_HOME/bisq-cli --password=xyz --port=9998 createoffer --help

View File

@ -0,0 +1,4 @@
#!/bin/bash
source "env.sh"
$BISQ_HOME/bisq-cli --password=xyz --port=9998 getmyoffer \
--offer-id=83e8b2e2-51b6-4f39-a748-3ebd29c22aea

View File

@ -0,0 +1,6 @@
#!/bin/bash
source "env.sh"
# Get my BSQ swap offers to buy BTC for BSQ.
$BISQ_HOME/bisq-cli --password=xyz --port=9998 getmyoffers --direction=BUY --currency-code=BSQ
# Get my BSQ swap offers to sell BTC for BSQ.
$BISQ_HOME/bisq-cli --password=xyz --port=9998 getmyoffers --direction=SELL --currency-code=BSQ

4
cli-examples/GetMyOffer.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
source "env.sh"
$BISQ_HOME/bisq-cli --password=xyz --port=9998 getmyoffer \
--offer-id=83e8b2e2-51b6-4f39-a748-3ebd29c22aea

6
cli-examples/GetMyOffers.sh Executable file
View File

@ -0,0 +1,6 @@
#!/bin/bash
source "env.sh"
# Get my offers to buy BTC with EUR.
$BISQ_HOME/bisq-cli --password=xyz --port=9998 getmyoffers --direction=BUY --currency-code=EUR
# Get my offers to sell BTC for EUR.
$BISQ_HOME/bisq-cli --password=xyz --port=9998 getmyoffers --direction=SELL --currency-code=EUR

4
cli-examples/GetOffer.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
source "env.sh"
$BISQ_HOME/bisq-cli --password=xyz --port=9998 getoffer \
--offer-id=83e8b2e2-51b6-4f39-a748-3ebd29c22aea

View File

@ -0,0 +1 @@
# Used internally by CLI; there is no user CLI command 'getoffercategory'.

6
cli-examples/GetOffers.sh Executable file
View File

@ -0,0 +1,6 @@
#!/bin/bash
source "env.sh"
# Get available offers to buy BTC with JPY.
$BISQ_HOME/bisq-cli --password=xyz --port=9998 getoffers --direction=BUY --currency-code=JPY
# Get available offers to sell BTC for JPY.
$BISQ_HOME/bisq-cli --password=xyz --port=9998 getoffers --direction=SELL --currency-code=JPY

View File

@ -0,0 +1,4 @@
#!/bin/bash
source "env.sh"
# Get a blank SWIFT payment account form and save the json file in the current working directory.
$BISQ_HOME/bisq-cli --password=xyz --port=9998 getpaymentacctform --payment-method-id=SWIFT

View File

@ -0,0 +1,4 @@
#!/bin/bash
source "env.sh"
# Get list of all saved payment accounts, including altcoin accounts.
$BISQ_HOME/bisq-cli --password=xyz --port=9998 getpaymentaccts

View File

@ -0,0 +1,4 @@
#!/bin/bash
source "env.sh"
# Get the ids of all supported Bisq payment methods.
$BISQ_HOME/bisq-cli --password=xyz --port=9998 getpaymentmethods

3
cli-examples/GetTrade.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
source "env.sh"
$BISQ_HOME/bisq-cli --password=xyz --port=9998 gettrade --trade-id=83e8b2e2-51b6-4f39-a748-3ebd29c22aea

11
cli-examples/GetTrades.sh Executable file
View File

@ -0,0 +1,11 @@
#!/bin/bash
source "env.sh"
# Get currently open trades.
$BISQ_HOME/bisq-cli --password=xyz --port=9998 gettrades
$BISQ_HOME/bisq-cli --password=xyz --port=9998 gettrades --category=open
# Get completed trades.
$BISQ_HOME/bisq-cli --password=xyz --port=9998 gettrades --category=closed
# Get failed trades.
$BISQ_HOME/bisq-cli --password=xyz --port=9998 gettrades --category=failed

4
cli-examples/GetTransaction.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
source "env.sh"
$BISQ_HOME/bisq-cli --password=xyz --port=9998 gettransaction \
--transaction-id=fef206f2ada53e70fd8430d130e43bc3994ce075d50ac1f4fda8182c40ef6bdd

3
cli-examples/GetTxFeeRate.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
source "env.sh"
$BISQ_HOME/bisq-cli --password=xyz --port=9998 gettxfeerate

View File

@ -0,0 +1,3 @@
#!/bin/bash
source "env.sh"
$BISQ_HOME/bisq-cli --password=xyz --port=9998 getunusedbsqaddress

3
cli-examples/GetVersion.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
source "env.sh"
$BISQ_HOME/bisq-cli --password=xyz --port=9998 getversion

3
cli-examples/LockWallet.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
source "env.sh"
$BISQ_HOME/bisq-cli --password=xyz --port=9998 lockwallet

View File

@ -0,0 +1,4 @@
#!/bin/bash
source "env.sh"
# Note: CLI command option parser expects a --wallet-password option, to differentiate it from an api daemon password.
$BISQ_HOME/bisq-cli --password=xyz --port=9998 removewalletpassword --wallet-password="abc"

5
cli-examples/SendBsq.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
source "env.sh"
$BISQ_HOME/bisq-cli --password=xyz --port=9998 sendbsq \
--address=Bbcrt1q9elrmtxtzpwt25zq2pmeeu6qk8029w404ad0xn \
--amount=1000.10

6
cli-examples/SendBtc.sh Executable file
View File

@ -0,0 +1,6 @@
#!/bin/bash
source "env.sh"
$BISQ_HOME/bisq-cli --password=xyz --port=9998 sendbtc \
--address=bcrt1qqau7ad7lf8xx08mnxl709h6cdv4ma9u3ace5k2 \
--amount=0.006 \
--tx-fee-rate=20

View File

@ -0,0 +1,3 @@
#!/bin/bash
source "env.sh"
$BISQ_HOME/bisq-cli --password=xyz --port=9998 settxfeerate --tx-fee-rate=50

View File

@ -0,0 +1,4 @@
#!/bin/bash
source "env.sh"
# Note: CLI command option parser expects a --wallet-password option, to differentiate it from an api daemon password.
$BISQ_HOME/bisq-cli --password=xyz --port=9998 setwalletpassword --wallet-password="abc"

3
cli-examples/Stop.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
source "env.sh"
$BISQ_HOME/bisq-cli --password=xyz --port=9998 stop

12
cli-examples/TakeOffer.sh Executable file
View File

@ -0,0 +1,12 @@
#!/bin/bash
source "env.sh"
# Take a BSQ swap offer.
$BISQ_HOME/bisq-cli --password=xyz --port=9998 takeoffer --offer-id=8368b2e2-anb6-4ty9-ab09-3ebdk34f2aea
# Take an offer that is not a BSQ swap offer.
# The payment-account-id param is required, the fee-currency param is optional.
$BISQ_HOME/bisq-cli --password=xyz --port=9998 takeoffer \
--offer-id=83e8b2e2-51b6-4f39-a748-3ebd29c22aea \
--payment-account-id=fe20cdbd-22be-4b8a-a4b6-d2608ff09d6e \
--fee-currency=BTC

3
cli-examples/UnFailTrade.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
source "env.sh"
$BISQ_HOME/bisq-cli --password=xyz --port=9998 unfailtrade --trade-id=83e8b2e2-51b6-4f39-a748-3ebd29c22aea

3
cli-examples/UnlockWallet.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
source "env.sh"
$BISQ_HOME/bisq-cli --password=xyz --port=9998 unlockwallet --wallet-password=abc --timeout=30

View File

@ -0,0 +1,3 @@
#!/bin/bash
source "env.sh"
$BISQ_HOME/bisq-cli --password=xyz --port=9998 unsettxfeerate

View File

@ -0,0 +1,5 @@
#!/bin/bash
source "env.sh"
$BISQ_HOME/bisq-cli --password=xyz --port=9998 verifybsqsenttoaddress \
--address=Bbcrt1q9elrmtxtzpwt25zq2pmeeu6qk8029w404ad0xn \
--amount="50.50"

7
cli-examples/WithdrawFunds.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
source "env.sh"
# Withdraw BTC trade proceeds to external bitcoin wallet.
$BISQ_HOME/bisq-cli --password=xyz --port=9998 withdrawfunds \
--trade-id=83e8b2e2-51b6-4f39-a748-3ebd29c22aea \
--address=bcrt1qqau7ad7lf8xx08mnxl709h6cdv4ma9u3ace5k2 \
--memo="Optional memo saved with transaction in Bisq wallet."

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="GENERAL_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_16" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$/..">
<excludeFolder url="file://$MODULE_DIR$/../scratch" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
cli-examples/env.sh Executable file
View File

@ -0,0 +1,6 @@
#!/bin/bash
# Absolute or relative directory path to the fully built Bisq source project, usually `master` or `bisq`.
# See https://github.com/bisq-network/bisq/blob/master/apitest/docs/api-beta-test-guide.md#clone-and-build-source-code
# for instructions on how to set up Bisq for running API daemon in regtest mode.
export BISQ_HOME="../../master-scratch"

View File

@ -0,0 +1,62 @@
plugins {
id 'java'
id 'com.google.protobuf' version '0.8.16'
}
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
group 'bisq'
version '0.0.1-SNAPSHOT'
apply plugin: 'com.google.protobuf'
dependencies {
compileOnly 'javax.annotation:javax.annotation-api:1.2'
implementation 'com.google.protobuf:protobuf-java:3.19.4'
implementation 'io.grpc:grpc-protobuf:1.42.1'
implementation 'io.grpc:grpc-core:1.42.1'
implementation 'io.grpc:grpc-stub:1.42.1'
implementation 'io.grpc:grpc-auth:1.42.1'
runtimeOnly 'io.grpc:grpc-netty-shaded:1.42.1'
implementation 'net.sf.jopt-simple:jopt-simple:5.0.4'
implementation 'commons-io:commons-io:2.11.0'
implementation 'com.google.protobuf:protobuf-java:3.12.4'
implementation 'org.slf4j:slf4j-api:1.7.30'
implementation 'ch.qos.logback:logback-classic:1.1.11'
implementation 'ch.qos.logback:logback-core:1.1.11'
annotationProcessor 'org.projectlombok:lombok:1.18.22'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.22'
compileOnly 'org.projectlombok:lombok:1.18.22'
testCompileOnly 'org.projectlombok:lombok:1.18.22'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.2'
}
sourceSets.main.java.srcDirs += [
'build/generated/source/main/java',
'build/generated/source/main/grpc'
]
protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.19.4'
}
plugins {
grpc {
artifact = 'io.grpc:protoc-gen-grpc-java:1.41.2'
}
}
generateProtoTasks {
all()*.plugins { grpc {} }
}
generatedFilesBaseDir = "$projectDir/build/generated/source"
}
test {
useJUnitPlatform()
}

View File

@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

185
java-examples/gradlew vendored Executable file
View File

@ -0,0 +1,185 @@
#!/usr/bin/env sh
#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MSYS* | MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=`expr $i + 1`
done
case $i in
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=`save "$@"`
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
exec "$JAVACMD" "$@"

89
java-examples/gradlew.bat vendored Normal file
View File

@ -0,0 +1,89 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

View File

@ -0,0 +1,2 @@
rootProject.name = 'java-examples'

View File

@ -0,0 +1,68 @@
package rpccalls;
import io.grpc.CallCredentials;
import io.grpc.ManagedChannel;
import io.grpc.Metadata;
import io.grpc.StatusRuntimeException;
import java.util.Scanner;
import java.util.concurrent.Executor;
import static io.grpc.Metadata.ASCII_STRING_MARSHALLER;
import static io.grpc.Status.UNAUTHENTICATED;
import static java.lang.System.*;
import static java.util.concurrent.TimeUnit.SECONDS;
public class BaseJavaExample {
static void addChannelShutdownHook(ManagedChannel channel) {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
channel.shutdown().awaitTermination(1, SECONDS);
} catch (InterruptedException ex) {
throw new IllegalStateException("Error shutting down gRPC channel.", ex);
}
}));
}
static String getApiPassword() {
Scanner scanner = new Scanner(in);
out.println("Enter api password:");
var apiPassword = "xyz"; // scanner.nextLine();
scanner.close();
return apiPassword;
}
static CallCredentials buildCallCredentials(String apiPassword) {
return new CallCredentials() {
@Override
public void applyRequestMetadata(RequestInfo requestInfo,
Executor appExecutor,
MetadataApplier metadataApplier) {
appExecutor.execute(() -> {
try {
var headers = new Metadata();
var passwordKey = Metadata.Key.of("password", ASCII_STRING_MARSHALLER);
headers.put(passwordKey, apiPassword);
metadataApplier.apply(headers);
} catch (Throwable ex) {
metadataApplier.fail(UNAUTHENTICATED.withCause(ex));
}
});
}
@Override
public void thisUsesUnstableApi() {
}
};
}
static void handleError(Throwable t) {
if (t instanceof StatusRuntimeException) {
var grpcErrorStatus = ((StatusRuntimeException) t).getStatus();
err.println(grpcErrorStatus.getCode() + ": " + grpcErrorStatus.getDescription());
} else {
err.println("Error: " + t);
}
}
}

View File

@ -0,0 +1,26 @@
package rpccalls;
import bisq.proto.grpc.CancelOfferRequest;
import bisq.proto.grpc.OffersGrpc;
import io.grpc.ManagedChannelBuilder;
import static java.lang.System.out;
public class CancelOffer extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = OffersGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var request = CancelOfferRequest.newBuilder()
.setId("83e8b2e2-51b6-4f39-a748-3ebd29c22aea")
.build();
var response = stub.cancelOffer(request);
out.println(response);
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1,26 @@
package rpccalls;
import bisq.proto.grpc.CloseTradeRequest;
import bisq.proto.grpc.TradesGrpc;
import io.grpc.ManagedChannelBuilder;
import static java.lang.System.out;
public class CloseTrade extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = TradesGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var request = CloseTradeRequest.newBuilder()
.setTradeId("83e8b2e2-51b6-4f39-a748-3ebd29c22aea")
.build();
stub.closeTrade(request);
out.println("Open trade is closed.");
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1,26 @@
package rpccalls;
import bisq.proto.grpc.ConfirmPaymentReceivedRequest;
import bisq.proto.grpc.TradesGrpc;
import io.grpc.ManagedChannelBuilder;
import static java.lang.System.out;
public class ConfirmPaymentReceived extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = TradesGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var request = ConfirmPaymentReceivedRequest.newBuilder()
.setTradeId("83e8b2e2-51b6-4f39-a748-3ebd29c22aea")
.build();
stub.confirmPaymentReceived(request);
out.println("Payment receipt confirmation message has been sent to BTC buyer.");
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1,26 @@
package rpccalls;
import bisq.proto.grpc.ConfirmPaymentStartedRequest;
import bisq.proto.grpc.TradesGrpc;
import io.grpc.ManagedChannelBuilder;
import static java.lang.System.out;
public class ConfirmPaymentStarted extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = TradesGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var request = ConfirmPaymentStartedRequest.newBuilder()
.setTradeId("83e8b2e2-51b6-4f39-a748-3ebd29c22aea")
.build();
stub.confirmPaymentStarted(request);
out.println("Payment started message has been sent to BTC seller.");
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1,29 @@
package rpccalls;
import bisq.proto.grpc.CreateBsqSwapOfferRequest;
import bisq.proto.grpc.OffersGrpc;
import io.grpc.ManagedChannelBuilder;
import static java.lang.System.out;
public class CreateBsqSwapOffer extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = OffersGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var request = CreateBsqSwapOfferRequest.newBuilder()
.setDirection("BUY") // Buy BTC with BSQ
.setAmount(12500000) // Satoshis
.setMinAmount(6250000) // Satoshis
.setPrice("0.00005") // Price of 1 BSQ in BTC
.build();
var response = stub.createBsqSwapOffer(request);
out.println(response);
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1,30 @@
package rpccalls;
import bisq.proto.grpc.CreateCryptoCurrencyPaymentAccountRequest;
import bisq.proto.grpc.PaymentAccountsGrpc;
import io.grpc.ManagedChannelBuilder;
import static java.lang.System.out;
public class CreateCryptoCurrencyPaymentAccount extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = PaymentAccountsGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var xmrAddress = "4AsjtNXChh3Va58czCWHjn9S8ZFnsxggGZoSePauBHmSMr8vY5aBSqrPtQ9Y9M1iwkBHxcuTWXJsJ4NDATQjQJyKBXR7WP7";
var request = CreateCryptoCurrencyPaymentAccountRequest.newBuilder()
.setAccountName("My Instant XMR Payment Account")
.setCurrencyCode("XMR")
.setAddress(xmrAddress)
.setTradeInstant(true)
.build();
var response = stub.createCryptoCurrencyPaymentAccount(request);
out.println("New XMR instant payment account: " + response.getPaymentAccount());
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1,85 @@
package rpccalls;
import bisq.proto.grpc.CreateOfferRequest;
import bisq.proto.grpc.OffersGrpc;
import io.grpc.ManagedChannelBuilder;
import static java.lang.System.out;
public class CreateOffer extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = OffersGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var fixedPriceOfferRequest = createFixedPriceEurOfferRequest();
var fixedPriceOfferResponse = stub.createOffer(fixedPriceOfferRequest);
out.println(fixedPriceOfferResponse);
waitForOfferPreparation(5_000);
var marketBasedPriceOfferRequest = createMarketBasedPriceEurOfferRequest();
var marketBasedPriceOfferResponse = stub.createOffer(marketBasedPriceOfferRequest);
out.println(marketBasedPriceOfferResponse);
waitForOfferPreparation(5_000);
var fixedPriceXmrOfferRequest = createFixedPriceXmrOfferRequest();
var fixedPriceXmrOfferResponse = stub.createOffer(fixedPriceXmrOfferRequest);
out.println(fixedPriceXmrOfferResponse);
} catch (Throwable t) {
handleError(t);
}
}
private static CreateOfferRequest createFixedPriceEurOfferRequest() {
return CreateOfferRequest.newBuilder()
.setCurrencyCode("EUR")
.setDirection("BUY") // Buy BTC with EUR
.setPrice("34500.00")
.setAmount(12500000) // Satoshis
.setMinAmount(6250000) // Satoshis
.setBuyerSecurityDepositPct(15.00) // 15%
.setPaymentAccountId("f3c1ec8b-9761-458d-b13d-9039c6892413")
.setMakerFeeCurrencyCode("BTC") // Pay Bisq trade fee in BTC
.build();
}
private static CreateOfferRequest createMarketBasedPriceEurOfferRequest() {
return CreateOfferRequest.newBuilder()
.setCurrencyCode("EUR")
.setDirection("SELL") // Sell BTC for EUR
.setUseMarketBasedPrice(true)
.setMarketPriceMarginPct(3.25) // Sell at 3.25% above market BTC price in EUR
.setAmount(12500000) // Satoshis
.setMinAmount(6250000) // Satoshis
.setBuyerSecurityDepositPct(15.00) // 15%
.setTriggerPrice("0") // No trigger price
.setPaymentAccountId("f3c1ec8b-9761-458d-b13d-9039c6892413")
.setMakerFeeCurrencyCode("BSQ") // Pay Bisq trade fee in BSQ
.build();
}
private static CreateOfferRequest createFixedPriceXmrOfferRequest() {
return CreateOfferRequest.newBuilder()
.setCurrencyCode("XMR")
.setDirection("BUY") // Buy BTC with XMR
.setPrice("0.005") // BTC price for 1 XMR
.setAmount(12500000) // Satoshis
.setMinAmount(6250000) // Satoshis
.setBuyerSecurityDepositPct(33.00) // 33%
.setPaymentAccountId("g3c8ec8b-9aa1-458d-b66d-9039c6892413")
.setMakerFeeCurrencyCode("BSQ") // Pay Bisq trade fee in BSQ
.build();
}
private static void waitForOfferPreparation(long ms) {
try {
// Wait new offer's preparation and wallet updates before attempting to create another offer.
Thread.sleep(5_000);
} catch (InterruptedException ex) {
// ignored
}
}
}

View File

@ -0,0 +1,27 @@
package rpccalls;
import bisq.proto.grpc.CreatePaymentAccountRequest;
import bisq.proto.grpc.PaymentAccountsGrpc;
import io.grpc.ManagedChannelBuilder;
import static java.lang.System.out;
public class CreatePaymentAccount extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = PaymentAccountsGrpc.newBlockingStub(channel).withCallCredentials(credentials);
// Fill in the swift payment account json form generated by GetPaymentAccountForm.
var request = CreatePaymentAccountRequest.newBuilder()
.setPaymentAccountForm("/path/to/swift.json")
.build();
var response = stub.createPaymentAccount(request);
out.println("New swift payment account: " + response.getPaymentAccount());
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1,98 @@
package rpccalls;
import bisq.proto.grpc.EditOfferRequest;
import bisq.proto.grpc.OffersGrpc;
import io.grpc.ManagedChannelBuilder;
import static bisq.proto.grpc.EditOfferRequest.EditType.*;
import static bisq.proto.grpc.EditOfferRequest.newBuilder;
import static java.lang.System.out;
public class EditOffer extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = OffersGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var disableOfferRequest = createDisableOfferRequest();
stub.editOffer(disableOfferRequest);
out.println("Offer is disabled (removed from peers' offer book).");
waitForOfferToBeRepublished(2_500);
var editFixedPriceRequest = createEditFixedPriceRequest();
stub.editOffer(editFixedPriceRequest);
out.println("Offer has been re-published with new fixed-price.");
waitForOfferToBeRepublished(2_500);
var editFixedPriceAndEnableRequest = createEditFixedPriceAndEnableRequest();
stub.editOffer(editFixedPriceAndEnableRequest);
out.println("Offer has been re-published with new fixed-price, and enabled.");
waitForOfferToBeRepublished(2_500);
var editPriceMarginRequest = createEditPriceMarginRequest();
stub.editOffer(editPriceMarginRequest);
out.println("Offer has been re-published with new price margin.");
waitForOfferToBeRepublished(2_500);
var editTriggerPriceRequest = createEditTriggerPriceRequest();
stub.editOffer(editTriggerPriceRequest);
out.println("Offer has been re-published with new trigger price.");
} catch (Throwable t) {
handleError(t);
}
}
private static EditOfferRequest createDisableOfferRequest() {
return newBuilder()
.setId("83e8b2e2-51b6-4f39-a748-3ebd29c22aea")
.setEditType(ACTIVATION_STATE_ONLY)
.setEnable(0) // -1 = ignore this parameter, 0 = disable offer, 1 = enable offer
.build();
}
private static EditOfferRequest createEditFixedPriceRequest() {
return newBuilder()
.setId("83e8b2e2-51b6-4f39-a748-3ebd29c22aea")
.setEditType(FIXED_PRICE_ONLY)
.setPrice("30000.99")
.build();
}
private static EditOfferRequest createEditFixedPriceAndEnableRequest() {
return newBuilder()
.setId("83e8b2e2-51b6-4f39-a748-3ebd29c22aea")
.setEditType(FIXED_PRICE_AND_ACTIVATION_STATE)
.setPrice("30000.99")
.setEnable(1)
.build();
}
private static EditOfferRequest createEditPriceMarginRequest() {
return newBuilder()
.setId("83e8b2e2-51b6-4f39-a748-3ebd29c22aea")
.setEditType(MKT_PRICE_MARGIN_ONLY)
.setUseMarketBasedPrice(true)
.setMarketPriceMarginPct(2.00) // 2.00%
.build();
}
private static EditOfferRequest createEditTriggerPriceRequest() {
return newBuilder()
.setId("83e8b2e2-51b6-4f39-a748-3ebd29c22aea")
.setEditType(TRIGGER_PRICE_ONLY)
.setTriggerPrice("29000.00") // Trigger price is disabled when set to "0".
.build();
}
private static void waitForOfferToBeRepublished(long ms) {
try {
// Wait for edited offer to be removed from offer-book, edited, and re-published.
Thread.sleep(ms);
} catch (InterruptedException ex) {
// ignored
}
}
}

View File

@ -0,0 +1,26 @@
package rpccalls;
import bisq.proto.grpc.FailTradeRequest;
import bisq.proto.grpc.TradesGrpc;
import io.grpc.ManagedChannelBuilder;
import static java.lang.System.out;
public class FailTrade extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = TradesGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var request = FailTradeRequest.newBuilder()
.setTradeId("83e8b2e2-51b6-4f39-a748-3ebd29c22aea")
.build();
stub.failTrade(request);
out.println("Open trade has been moved to failed trades list.");
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1,26 @@
package rpccalls;
import bisq.proto.grpc.GetAddressBalanceRequest;
import bisq.proto.grpc.WalletsGrpc;
import io.grpc.ManagedChannelBuilder;
import static java.lang.System.out;
public class GetAddressBalance extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = WalletsGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var request = GetAddressBalanceRequest.newBuilder()
.setAddress("mwLYmweQf2dCgAqQCb3qU2UbxBycVBi2PW")
.build();
var response = stub.getAddressBalance(request);
out.println(response);
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1,25 @@
package rpccalls;
import bisq.proto.grpc.GetBalancesRequest;
import bisq.proto.grpc.WalletsGrpc;
import io.grpc.ManagedChannelBuilder;
import static java.lang.System.out;
public class GetBalances extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = WalletsGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var request = GetBalancesRequest.newBuilder().build();
var response = stub.getBalances(request);
out.println("BSQ " + response.getBalances().getBsq());
out.println("BTC " + response.getBalances().getBtc());
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1,26 @@
package rpccalls;
import bisq.proto.grpc.GetOfferRequest;
import bisq.proto.grpc.OffersGrpc;
import io.grpc.ManagedChannelBuilder;
import static java.lang.System.out;
public class GetBsqSwapOffer extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = OffersGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var request = GetOfferRequest.newBuilder()
.setId("83e8b2e2-51b6-4f39-a748-3ebd29c22aea")
.build();
var response = stub.getBsqSwapOffer(request);
out.println(response);
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1,26 @@
package rpccalls;
import bisq.proto.grpc.GetBsqSwapOffersRequest;
import bisq.proto.grpc.OffersGrpc;
import io.grpc.ManagedChannelBuilder;
import static java.lang.System.out;
public class GetBsqSwapOffers extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = OffersGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var request = GetBsqSwapOffersRequest.newBuilder()
.setDirection("SELL") // Offers to sell (swap) BTC for BSQ.
.build();
var response = stub.getBsqSwapOffers(request);
out.println(response);
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1,24 @@
package rpccalls;
import bisq.proto.grpc.GetCryptoCurrencyPaymentMethodsRequest;
import bisq.proto.grpc.PaymentAccountsGrpc;
import io.grpc.ManagedChannelBuilder;
import static java.lang.System.out;
public class GetCryptoCurrencyPaymentMethods extends BaseJavaExample {
// Note: API currently supports only BSQ, BSQ Swap, and XMR trading.
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = PaymentAccountsGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var request = GetCryptoCurrencyPaymentMethodsRequest.newBuilder().build();
var response = stub.getCryptoCurrencyPaymentMethods(request);
out.println("Response: " + response.getPaymentMethodsList());
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1,24 @@
package rpccalls;
import bisq.proto.grpc.GetFundingAddressesRequest;
import bisq.proto.grpc.WalletsGrpc;
import io.grpc.ManagedChannelBuilder;
import static java.lang.System.out;
public class GetFundingAddresses extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = WalletsGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var request = GetFundingAddressesRequest.newBuilder().build();
var response = stub.getFundingAddresses(request);
out.println(response);
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1,26 @@
package rpccalls;
import bisq.proto.grpc.MarketPriceRequest;
import bisq.proto.grpc.PriceGrpc;
import io.grpc.ManagedChannelBuilder;
import static java.lang.System.out;
public class GetMarketPrice extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = PriceGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var request = MarketPriceRequest.newBuilder()
.setCurrencyCode("XMR")
.build();
var response = stub.getMarketPrice(request);
out.println("Most recently available XMR market price: " + response.getPrice());
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1 @@
package rpccalls;// Help Service is for CLI users.

View File

@ -0,0 +1,26 @@
package rpccalls;
import bisq.proto.grpc.GetMyOfferRequest;
import bisq.proto.grpc.OffersGrpc;
import io.grpc.ManagedChannelBuilder;
import static java.lang.System.out;
public class GetMyBsqSwapOffer extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = OffersGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var request = GetMyOfferRequest.newBuilder()
.setId("83e8b2e2-51b6-4f39-a748-3ebd29c22aea")
.build();
var response = stub.getMyBsqSwapOffer(request);
out.println(response);
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1,26 @@
package rpccalls;
import bisq.proto.grpc.GetBsqSwapOffersRequest;
import bisq.proto.grpc.OffersGrpc;
import io.grpc.ManagedChannelBuilder;
import static java.lang.System.out;
public class GetMyBsqSwapOffers extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = OffersGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var request = GetBsqSwapOffersRequest.newBuilder()
.setDirection("BUY") // Offers to buy (swap) BTC for BSQ.
.build();
var response = stub.getBsqSwapOffers(request);
out.println(response);
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1,26 @@
package rpccalls;
import bisq.proto.grpc.GetMyOfferRequest;
import bisq.proto.grpc.OffersGrpc;
import io.grpc.ManagedChannelBuilder;
import static java.lang.System.out;
public class GetMyOffer extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = OffersGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var request = GetMyOfferRequest.newBuilder()
.setId("83e8b2e2-51b6-4f39-a748-3ebd29c22aea")
.build();
var response = stub.getMyOffer(request);
out.println(response);
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1,27 @@
package rpccalls;
import bisq.proto.grpc.GetMyOffersRequest;
import bisq.proto.grpc.OffersGrpc;
import io.grpc.ManagedChannelBuilder;
import static java.lang.System.out;
public class GetMyOffers extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = OffersGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var request = GetMyOffersRequest.newBuilder()
.setDirection("BUY") // Offers to buy BTC
.setCurrencyCode("USD") // with USD
.build();
var response = stub.getMyOffers(request);
out.println(response);
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1,26 @@
package rpccalls;
import bisq.proto.grpc.GetOfferRequest;
import bisq.proto.grpc.OffersGrpc;
import io.grpc.ManagedChannelBuilder;
import static java.lang.System.out;
public class GetOffer extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = OffersGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var request = GetOfferRequest.newBuilder()
.setId("83e8b2e2-51b6-4f39-a748-3ebd29c22aea")
.build();
var response = stub.getOffer(request);
out.println(response);
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1,26 @@
package rpccalls;
import bisq.proto.grpc.GetOfferCategoryRequest;
import bisq.proto.grpc.OffersGrpc;
import io.grpc.ManagedChannelBuilder;
import static java.lang.System.out;
public class GetOfferCategory extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = OffersGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var request = GetOfferCategoryRequest.newBuilder()
.setId("83e8b2e2-51b6-4f39-a748-3ebd29c22aea")
.build();
var response = stub.getOfferCategory(request);
out.println(response);
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1,27 @@
package rpccalls;
import bisq.proto.grpc.GetOffersRequest;
import bisq.proto.grpc.OffersGrpc;
import io.grpc.ManagedChannelBuilder;
import static java.lang.System.out;
public class GetOffers extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = OffersGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var request = GetOffersRequest.newBuilder()
.setDirection("SELL") // Available offers to sell BTC
.setCurrencyCode("JPY") // for JPY
.build();
var response = stub.getOffers(request);
out.println(response);
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1,35 @@
package rpccalls;
import bisq.proto.grpc.GetPaymentAccountFormRequest;
import bisq.proto.grpc.PaymentAccountsGrpc;
import io.grpc.ManagedChannelBuilder;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import static java.lang.System.out;
public class GetPaymentAccountForm extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = PaymentAccountsGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var request = GetPaymentAccountFormRequest.newBuilder()
.setPaymentMethodId("SWIFT")
.build();
var response = stub.getPaymentAccountForm(request);
var paymentAccountFormJson = response.getPaymentAccountFormJson();
File jsonFile = new File("/tmp/blank-swift-account-form.json");
BufferedWriter writer = new BufferedWriter(new FileWriter(jsonFile));
writer.write(paymentAccountFormJson);
writer.close();
out.println("Swift payment account saved to " + jsonFile.getAbsolutePath());
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1,24 @@
package rpccalls;
import bisq.proto.grpc.GetPaymentAccountsRequest;
import bisq.proto.grpc.PaymentAccountsGrpc;
import io.grpc.ManagedChannelBuilder;
import static java.lang.System.out;
public class GetPaymentAccounts extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = PaymentAccountsGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var request = GetPaymentAccountsRequest.newBuilder().build();
var response = stub.getPaymentAccounts(request);
out.println("Response: " + response.getPaymentAccountsList());
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1,24 @@
package rpccalls;
import bisq.proto.grpc.GetPaymentMethodsRequest;
import bisq.proto.grpc.PaymentAccountsGrpc;
import io.grpc.ManagedChannelBuilder;
import static java.lang.System.out;
public class GetPaymentMethods extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = PaymentAccountsGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var request = GetPaymentMethodsRequest.newBuilder().build();
var response = stub.getPaymentMethods(request);
out.println("Response: " + response.getPaymentMethodsList());
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1,26 @@
package rpccalls;
import bisq.proto.grpc.GetTradeRequest;
import bisq.proto.grpc.TradesGrpc;
import io.grpc.ManagedChannelBuilder;
import static java.lang.System.out;
public class GetTrade extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = TradesGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var request = GetTradeRequest.newBuilder()
.setTradeId("83e8b2e2-51b6-4f39-a748-3ebd29c22aea")
.build();
var response = stub.getTrade(request);
out.println("Trade: " + response.getTrade());
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1,27 @@
package rpccalls;
import bisq.proto.grpc.GetTradesRequest;
import bisq.proto.grpc.TradesGrpc;
import io.grpc.ManagedChannelBuilder;
import static bisq.proto.grpc.GetTradesRequest.Category.CLOSED;
import static java.lang.System.out;
public class GetTrades extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = TradesGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var request = GetTradesRequest.newBuilder()
.setCategory(CLOSED) // Or currently OPEN, or FAILED
.build();
var response = stub.getTrades(request);
out.println("Open trades: " + response.getTradesList());
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1,26 @@
package rpccalls;
import bisq.proto.grpc.GetTransactionRequest;
import bisq.proto.grpc.WalletsGrpc;
import io.grpc.ManagedChannelBuilder;
import static java.lang.System.out;
public class GetTransaction extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = WalletsGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var request = GetTransactionRequest.newBuilder()
.setTxId("fef206f2ada53e70fd8430d130e43bc3994ce075d50ac1f4fda8182c40ef6bdd")
.build();
var response = stub.getTransaction(request);
out.println(response);
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1,24 @@
package rpccalls;
import bisq.proto.grpc.GetTxFeeRateRequest;
import bisq.proto.grpc.WalletsGrpc;
import io.grpc.ManagedChannelBuilder;
import static java.lang.System.out;
public class GetTxFeeRate extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = WalletsGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var request = GetTxFeeRateRequest.newBuilder().build();
var response = stub.getTxFeeRate(request);
out.println(response);
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1,24 @@
package rpccalls;
import bisq.proto.grpc.GetUnusedBsqAddressRequest;
import bisq.proto.grpc.WalletsGrpc;
import io.grpc.ManagedChannelBuilder;
import static java.lang.System.out;
public class GetUnusedBsqAddress extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = WalletsGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var request = GetUnusedBsqAddressRequest.newBuilder().build();
var response = stub.getUnusedBsqAddress(request);
out.println(response);
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1,24 @@
package rpccalls;
import bisq.proto.grpc.GetVersionGrpc;
import bisq.proto.grpc.GetVersionRequest;
import io.grpc.ManagedChannelBuilder;
import static java.lang.System.out;
public class GetVersion extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = GetVersionGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var request = GetVersionRequest.newBuilder().build();
var reply = stub.getVersion(request);
out.println(reply.getVersion());
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1,24 @@
package rpccalls;
import bisq.proto.grpc.LockWalletRequest;
import bisq.proto.grpc.WalletsGrpc;
import io.grpc.ManagedChannelBuilder;
import static java.lang.System.out;
public class LockWallet extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = WalletsGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var request = LockWalletRequest.newBuilder().build();
stub.lockWallet(request);
out.println("Wallet is locked.");
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1,24 @@
package rpccalls;
import bisq.proto.grpc.RemoveWalletPasswordRequest;
import bisq.proto.grpc.WalletsGrpc;
import io.grpc.ManagedChannelBuilder;
import static java.lang.System.out;
public class RemoveWalletPassword extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = WalletsGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var request = RemoveWalletPasswordRequest.newBuilder().setPassword("abc").build();
stub.removeWalletPassword(request);
out.println("Wallet encryption password is removed.");
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1,28 @@
package rpccalls;
import bisq.proto.grpc.SendBsqRequest;
import bisq.proto.grpc.WalletsGrpc;
import io.grpc.ManagedChannelBuilder;
import static java.lang.System.out;
public class SendBsq extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = WalletsGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var request = SendBsqRequest.newBuilder()
.setAddress("Bbcrt1q9elrmtxtzpwt25zq2pmeeu6qk8029w404ad0xn")
.setAmount("50.50")
.setTxFeeRate("50")
.build();
var response = stub.sendBsq(request);
out.println(response);
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1,29 @@
package rpccalls;
import bisq.proto.grpc.SendBtcRequest;
import bisq.proto.grpc.WalletsGrpc;
import io.grpc.ManagedChannelBuilder;
import static java.lang.System.out;
public class SendBtc extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = WalletsGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var request = SendBtcRequest.newBuilder()
.setAddress("bcrt1qqau7ad7lf8xx08mnxl709h6cdv4ma9u3ace5k2")
.setAmount("0.005")
.setTxFeeRate("50")
.setMemo("Optional memo.")
.build();
var response = stub.sendBtc(request);
out.println(response);
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1,26 @@
package rpccalls;
import bisq.proto.grpc.SetTxFeeRatePreferenceRequest;
import bisq.proto.grpc.WalletsGrpc;
import io.grpc.ManagedChannelBuilder;
import static java.lang.System.out;
public class SetTxFeeRatePreference extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = WalletsGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var request = SetTxFeeRatePreferenceRequest.newBuilder()
.setTxFeeRatePreference(25)
.build();
var response = stub.setTxFeeRatePreference(request);
out.println(response);
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1,24 @@
package rpccalls;
import bisq.proto.grpc.SetWalletPasswordRequest;
import bisq.proto.grpc.WalletsGrpc;
import io.grpc.ManagedChannelBuilder;
import static java.lang.System.out;
public class SetWalletPassword extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = WalletsGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var request = SetWalletPasswordRequest.newBuilder().setPassword("abc").build();
stub.setWalletPassword(request);
out.println("Wallet encryption password is set.");
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1,24 @@
package rpccalls;
import bisq.proto.grpc.ShutdownServerGrpc;
import bisq.proto.grpc.StopRequest;
import io.grpc.ManagedChannelBuilder;
import static java.lang.System.out;
public class Stop extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = ShutdownServerGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var request = StopRequest.newBuilder().build();
stub.stop(request);
out.println("Daemon is shutting down.");
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1,48 @@
package rpccalls;
import bisq.proto.grpc.GetOfferCategoryRequest;
import bisq.proto.grpc.OffersGrpc;
import bisq.proto.grpc.TakeOfferRequest;
import bisq.proto.grpc.TradesGrpc;
import io.grpc.ManagedChannelBuilder;
import static bisq.proto.grpc.GetOfferCategoryReply.OfferCategory.BSQ_SWAP;
import static java.lang.System.err;
import static java.lang.System.out;
public class TakeOffer extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var offersStub = OffersGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var tradesStub = TradesGrpc.newBlockingStub(channel).withCallCredentials(credentials);
// We need to send our payment account id, and the taker fee currency code if offer is
// not a BSQ swap offer. Find out by calling GetOfferCategory before taking the offer.
var getOfferCategoryRequest = GetOfferCategoryRequest.newBuilder()
.setId("83e8b2e2-51b6-4f39-a748-3ebd29c22aea")
.build();
var offerCategory = offersStub.getOfferCategory(getOfferCategoryRequest);
// Create a takeoffer request builder with just the offerId parameter.
var takeOfferRequestBuilder = TakeOfferRequest.newBuilder()
.setOfferId("83e8b2e2-51b6-4f39-a748-3ebd29c22aea");
// If offer is not a BSQ swap offer, add the paymentAccountId and takerFeeCurrencyCode parameters.
if (!offerCategory.equals(BSQ_SWAP))
takeOfferRequestBuilder
.setPaymentAccountId("f3c1ec8b-9761-458d-b13d-9039c6892413")
.setTakerFeeCurrencyCode("BSQ");
var takeOfferRequest = takeOfferRequestBuilder.build();
var takeOfferResponse = tradesStub.takeOffer(takeOfferRequest);
if (takeOfferResponse.hasFailureReason())
err.println("Take offer failure reason: " + takeOfferResponse.getFailureReason());
else
out.println("New trade: " + takeOfferResponse.getTrade());
} catch (Throwable t) {
handleError(t);
}
}
}

View File

@ -0,0 +1,26 @@
package rpccalls;
import bisq.proto.grpc.TradesGrpc;
import bisq.proto.grpc.UnFailTradeRequest;
import io.grpc.ManagedChannelBuilder;
import static java.lang.System.out;
public class UnFailTrade extends BaseJavaExample {
public static void main(String[] args) {
try {
var channel = ManagedChannelBuilder.forAddress("localhost", 9998).usePlaintext().build();
addChannelShutdownHook(channel);
var credentials = buildCallCredentials(getApiPassword());
var stub = TradesGrpc.newBlockingStub(channel).withCallCredentials(credentials);
var request = UnFailTradeRequest.newBuilder()
.setTradeId("83e8b2e2-51b6-4f39-a748-3ebd29c22aea")
.build();
stub.unFailTrade(request);
out.println("Failed trade has been moved to open trades list.");
} catch (Throwable t) {
handleError(t);
}
}
}

Some files were not shown because too many files have changed in this diff Show More