From 78304969388b8b2d0d4706390283b783e8e2b491 Mon Sep 17 00:00:00 2001 From: microwavedcola1 Date: Thu, 14 Oct 2021 09:59:24 +0200 Subject: [PATCH] demo and fix python Signed-off-by: microwavedcola1 --- README.md | 1 + curl-demo/cancel_all_orders.sh | 6 ++++++ curl-demo/fire-curl-commands.sh | 33 ++++++++++++++++++++++++++++++++ curl-demo/get_balances.sh | 8 ++++++++ curl-demo/get_candles.sh | 6 ++++++ curl-demo/get_coins.sh | 8 ++++++++ curl-demo/get_markets.sh | 6 ++++++ curl-demo/get_orderbook.sh | 6 ++++++ curl-demo/get_orders.sh | 8 ++++++++ curl-demo/get_positions.sh | 8 ++++++++ curl-demo/get_trades.sh | 6 ++++++ curl-demo/post_order.sh | 34 +++++++++++++++++++++++++++++++++ py/mango_service_v3_py/api.py | 2 +- 13 files changed, 131 insertions(+), 1 deletion(-) create mode 100755 curl-demo/cancel_all_orders.sh create mode 100755 curl-demo/fire-curl-commands.sh create mode 100755 curl-demo/get_balances.sh create mode 100755 curl-demo/get_candles.sh create mode 100755 curl-demo/get_coins.sh create mode 100755 curl-demo/get_markets.sh create mode 100755 curl-demo/get_orderbook.sh create mode 100755 curl-demo/get_orders.sh create mode 100755 curl-demo/get_positions.sh create mode 100755 curl-demo/get_trades.sh create mode 100755 curl-demo/post_order.sh diff --git a/README.md b/README.md index eaeb76f..4e3854c 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ Directory structure . ├── README.md ├── mango-service-v3 - REST API Service for mango markets version 3 +├── mango-vial - WEBSOCKET API Service for L1, L2 orderbook data for mango markets version 3 └── py - python3 client for above REST API Service ``` # Todos diff --git a/curl-demo/cancel_all_orders.sh b/curl-demo/cancel_all_orders.sh new file mode 100755 index 0000000..ec3a356 --- /dev/null +++ b/curl-demo/cancel_all_orders.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env zsh + +echo "cancel all orders" +echo "curl --location --request DELETE 'http://localhost:3000/api/orders'" + +curl --location --request DELETE 'http://localhost:3000/api/orders' \ No newline at end of file diff --git a/curl-demo/fire-curl-commands.sh b/curl-demo/fire-curl-commands.sh new file mode 100755 index 0000000..6e330c9 --- /dev/null +++ b/curl-demo/fire-curl-commands.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env zsh + +./get_balances.sh +echo "\n\n" +sleep 1 + +./get_candles.sh +echo "\n\n" +sleep 1 + +./get_coins.sh +echo "\n\n" +sleep 1 + +./get_markets.sh +echo "\n\n" +sleep 1 + +./get_orders.sh +echo "\n\n" +sleep 1 + +./cancel_all_orders.sh +echo "\n\n" +sleep 1 + +./post_order.sh +echo "\n\n" +sleep 1 + +./get_orders.sh +echo "\n\n" +sleep 1 \ No newline at end of file diff --git a/curl-demo/get_balances.sh b/curl-demo/get_balances.sh new file mode 100755 index 0000000..f17eb1d --- /dev/null +++ b/curl-demo/get_balances.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env zsh + +echo "show USDC balance for user" +echo "curl -s --location --request GET 'http://localhost:3000/api/wallet/balances' \ +--data-raw '' | jq '.result[8]'" + +curl -s --location --request GET 'http://localhost:3000/api/wallet/balances' \ +--data-raw '' | jq '.result[8]' \ No newline at end of file diff --git a/curl-demo/get_candles.sh b/curl-demo/get_candles.sh new file mode 100755 index 0000000..c13b57f --- /dev/null +++ b/curl-demo/get_candles.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env zsh + +echo "show candles for a BTC-PERP" +echo "curl -s --location --request GET 'http://localhost:3000/api/markets/BTC-PERP/candles?resolution=60&start_time=1625922900&end_time=1631214960' | jq '.result[8]'" + +curl -s --location --request GET 'http://localhost:3000/api/markets/BTC-PERP/candles?resolution=60&start_time=1625922900&end_time=1631214960' | jq '.result[8]' \ No newline at end of file diff --git a/curl-demo/get_coins.sh b/curl-demo/get_coins.sh new file mode 100755 index 0000000..1c2372e --- /dev/null +++ b/curl-demo/get_coins.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env zsh + +echo "show a random coin availbale to trade" +echo "curl -s --location --request GET 'http://localhost:3000/api/coins' \ +--data-raw '' | jq '.result[8]'" + +curl -s --location --request GET 'http://localhost:3000/api/coins' \ +--data-raw '' | jq '.result[8]' \ No newline at end of file diff --git a/curl-demo/get_markets.sh b/curl-demo/get_markets.sh new file mode 100755 index 0000000..22fb994 --- /dev/null +++ b/curl-demo/get_markets.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env zsh + +echo "show BTC-PERP market" +echo "curl -s --location --request GET 'http://localhost:3000/api/markets/BTC-PERP' | jq '.result'" + +curl -s --location --request GET 'http://localhost:3000/api/markets/BTC-PERP' | jq '.result' \ No newline at end of file diff --git a/curl-demo/get_orderbook.sh b/curl-demo/get_orderbook.sh new file mode 100755 index 0000000..40787d5 --- /dev/null +++ b/curl-demo/get_orderbook.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env zsh + +echo "show orderbook" +echo "curl -s --location --request GET 'http://localhost:3000/api/markets/BTC-PERP/orderbook?depth=30' | jq '.result.asks[0]" + +curl -s --location --request GET 'http://localhost:3000/api/markets/BTC-PERP/orderbook?depth=30' | jq '.result.asks[0] \ No newline at end of file diff --git a/curl-demo/get_orders.sh b/curl-demo/get_orders.sh new file mode 100755 index 0000000..8ad9dfd --- /dev/null +++ b/curl-demo/get_orders.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env zsh + +echo "show all orders" +echo "curl -s --location --request GET 'http://localhost:3000/api/orders' \ +--data-raw '' | jq '.result'" + +curl -s --location --request GET 'http://localhost:3000/api/orders' \ +--data-raw '' | jq '.result' \ No newline at end of file diff --git a/curl-demo/get_positions.sh b/curl-demo/get_positions.sh new file mode 100755 index 0000000..b4bbcec --- /dev/null +++ b/curl-demo/get_positions.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env zsh + +echo "show all positions" +echo "curl -s --location --request GET 'http://localhost:3000/api/positions' \ +--data-raw '' | jq '.result[0]'" + +curl -s --location --request GET 'http://localhost:3000/api/positions' \ +--data-raw '' | jq '.result[0]' \ No newline at end of file diff --git a/curl-demo/get_trades.sh b/curl-demo/get_trades.sh new file mode 100755 index 0000000..8f3298d --- /dev/null +++ b/curl-demo/get_trades.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env zsh + +echo "show a random trade" +echo "curl -s --location --request GET 'http://localhost:3000/api/markets/BTC-PERP/trades' | jq '.result[0]'" + +curl -s --location --request GET 'http://localhost:3000/api/markets/BTC-PERP/trades' | jq '.result[0]' \ No newline at end of file diff --git a/curl-demo/post_order.sh b/curl-demo/post_order.sh new file mode 100755 index 0000000..fa68cea --- /dev/null +++ b/curl-demo/post_order.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env zsh + +echo "place order" +cat << EOF +curl -s --location --request POST 'http://localhost:3000/api/orders' \ +--header 'Content-Type: application/json' \ +--data-raw '{ + "market": "BTC-PERP", + "side": "buy", + "price": 20000, + "type": "limit", + "size": 0.0001, + "reduceOnly": false, + "ioc": false, + "postOnly": false, + "clientId": "870" +} +' | jq . +EOF + +curl -s --location --request POST 'http://localhost:3000/api/orders' \ +--header 'Content-Type: application/json' \ +--data-raw '{ + "market": "BTC-PERP", + "side": "buy", + "price": 20000, + "type": "limit", + "size": 0.0001, + "reduceOnly": false, + "ioc": false, + "postOnly": false, + "clientId": "870" +} +' \ No newline at end of file diff --git a/py/mango_service_v3_py/api.py b/py/mango_service_v3_py/api.py index ec3786f..6ea4ff2 100644 --- a/py/mango_service_v3_py/api.py +++ b/py/mango_service_v3_py/api.py @@ -33,7 +33,7 @@ def delayed(seconds): class MangoServiceV3Client: - def __init__(self, base_url, timeout): + def __init__(self, base_url=None, timeout=None): self.timeout = timeout if timeout else 10.0 if base_url: self.BASE_URL = base_url