From b80d8e03113f26076216b0b117915fcac9f75046 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Thu, 23 Jun 2022 14:45:17 -0300 Subject: [PATCH 1/2] Fix default protosIn option value --- .../src/main/java/bisq/apidoc/BisqApiDocMain.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference-doc-builder/src/main/java/bisq/apidoc/BisqApiDocMain.java b/reference-doc-builder/src/main/java/bisq/apidoc/BisqApiDocMain.java index 1e4c937..902e0ce 100644 --- a/reference-doc-builder/src/main/java/bisq/apidoc/BisqApiDocMain.java +++ b/reference-doc-builder/src/main/java/bisq/apidoc/BisqApiDocMain.java @@ -125,7 +125,7 @@ public class BisqApiDocMain { OptionSpec protosInOpt = optionParser.accepts("protosIn", "directory path to input protobuf files") .withRequiredArg() - .defaultsTo("src/main/resources/proto"); + .defaultsTo("java-examples/src/main/proto"); OptionSpec markdownOutOpt = optionParser.accepts("markdownOut", "directory path to output markdown file") .withRequiredArg() .defaultsTo("./"); From 07a8777ae8babf620ee1dba411f2d541107f888f Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Thu, 23 Jun 2022 14:48:11 -0300 Subject: [PATCH 2/2] Add getnetwork, getavgbsqprice examples --- cli-examples/GetAverageBsqPrice.sh | 3 ++ cli-examples/GetNetwork.sh | 3 ++ .../bisq/rpccalls/GetAverageBsqPrice.java | 28 +++++++++++++++++++ .../main/java/bisq/rpccalls/GetNetwork.java | 24 ++++++++++++++++ .../bisq/rpccalls/get_average_bsq_price.py | 24 ++++++++++++++++ python-examples/bisq/rpccalls/get_network.py | 22 +++++++++++++++ 6 files changed, 104 insertions(+) create mode 100755 cli-examples/GetAverageBsqPrice.sh create mode 100755 cli-examples/GetNetwork.sh create mode 100644 java-examples/src/main/java/bisq/rpccalls/GetAverageBsqPrice.java create mode 100644 java-examples/src/main/java/bisq/rpccalls/GetNetwork.java create mode 100644 python-examples/bisq/rpccalls/get_average_bsq_price.py create mode 100644 python-examples/bisq/rpccalls/get_network.py diff --git a/cli-examples/GetAverageBsqPrice.sh b/cli-examples/GetAverageBsqPrice.sh new file mode 100755 index 0000000..2e6009f --- /dev/null +++ b/cli-examples/GetAverageBsqPrice.sh @@ -0,0 +1,3 @@ +#!/bin/bash +source "env.sh" +$BISQ_HOME/bisq-cli --password=xyz --port=9998 getavgbsqprice --days=30 diff --git a/cli-examples/GetNetwork.sh b/cli-examples/GetNetwork.sh new file mode 100755 index 0000000..d9979ce --- /dev/null +++ b/cli-examples/GetNetwork.sh @@ -0,0 +1,3 @@ +#!/bin/bash +source "env.sh" +$BISQ_HOME/bisq-cli --password=xyz --port=9998 getnetwork diff --git a/java-examples/src/main/java/bisq/rpccalls/GetAverageBsqPrice.java b/java-examples/src/main/java/bisq/rpccalls/GetAverageBsqPrice.java new file mode 100644 index 0000000..5e18847 --- /dev/null +++ b/java-examples/src/main/java/bisq/rpccalls/GetAverageBsqPrice.java @@ -0,0 +1,28 @@ +package bisq.rpccalls; + +import bisq.proto.grpc.GetAverageBsqTradePriceRequest; +import bisq.proto.grpc.PriceGrpc; +import io.grpc.ManagedChannelBuilder; + +import static java.lang.String.format; +import static java.lang.System.out; + +public class GetAverageBsqPrice 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 = GetAverageBsqTradePriceRequest.newBuilder().setDays(30).build(); + var reply = stub.getAverageBsqTradePrice(request); + var price = reply.getPrice(); + out.println(format("30-day avg BTC price: %s, 30-day avg USD price: %s", + price.getBtcPrice(), + price.getUsdPrice())); + } catch (Throwable t) { + handleError(t); + } + } +} diff --git a/java-examples/src/main/java/bisq/rpccalls/GetNetwork.java b/java-examples/src/main/java/bisq/rpccalls/GetNetwork.java new file mode 100644 index 0000000..c0a2a2c --- /dev/null +++ b/java-examples/src/main/java/bisq/rpccalls/GetNetwork.java @@ -0,0 +1,24 @@ +package bisq.rpccalls; + +import bisq.proto.grpc.GetNetworkRequest; +import bisq.proto.grpc.WalletsGrpc; +import io.grpc.ManagedChannelBuilder; + +import static java.lang.System.out; + +public class GetNetwork 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 = GetNetworkRequest.newBuilder().build(); + var reply = stub.getNetwork(request); + out.println(reply.getNetwork()); + } catch (Throwable t) { + handleError(t); + } + } +} diff --git a/python-examples/bisq/rpccalls/get_average_bsq_price.py b/python-examples/bisq/rpccalls/get_average_bsq_price.py new file mode 100644 index 0000000..5bf6784 --- /dev/null +++ b/python-examples/bisq/rpccalls/get_average_bsq_price.py @@ -0,0 +1,24 @@ +import grpc + +# from getpass import getpass +import bisq.api.grpc_pb2 as bisq_messages +import bisq.api.grpc_pb2_grpc as bisq_service +import grpc + + +def main(): + grpc_channel = grpc.insecure_channel('localhost:9998') + grpc_service_stub = bisq_service.PriceStub(grpc_channel) + api_password: str = 'xyz' # getpass("Enter API password: ") + try: + response = grpc_service_stub.GetAverageBsqTradePrice.with_call( + bisq_messages.GetAverageBsqTradePriceRequest(days=30), + metadata=[('password', api_password)]) + price = response[0].price + print('Response: ' + '30-day BTC price: ' + price.btc_price + ' 30-day USD price: ' + price.usd_pricez) + except grpc.RpcError as rpc_error: + print('gRPC API Exception: %s', rpc_error) + + +if __name__ == '__main__': + main() diff --git a/python-examples/bisq/rpccalls/get_network.py b/python-examples/bisq/rpccalls/get_network.py new file mode 100644 index 0000000..b554f0d --- /dev/null +++ b/python-examples/bisq/rpccalls/get_network.py @@ -0,0 +1,22 @@ +import grpc + +# from getpass import getpass +import bisq.api.grpc_pb2 as bisq_messages +import bisq.api.grpc_pb2_grpc as bisq_service + + +def main(): + grpc_channel = grpc.insecure_channel('localhost:9998') + grpc_service_stub = bisq_service.WalletsStub(grpc_channel) + api_password: str = 'xyz' # getpass("Enter API password: ") + try: + response = grpc_service_stub.GetNetwork.with_call( + bisq_messages.GetNetworkRequest(), + metadata=[('password', api_password)]) + print('Response: ' + response[0].network) + except grpc.RpcError as rpc_error: + print('gRPC API Exception: %s', rpc_error) + + +if __name__ == '__main__': + main()