demo and fix python

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
microwavedcola1 2021-10-14 09:59:24 +02:00
parent 21b27feef6
commit 7830496938
13 changed files with 131 additions and 1 deletions

View File

@ -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

6
curl-demo/cancel_all_orders.sh Executable file
View File

@ -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'

33
curl-demo/fire-curl-commands.sh Executable file
View File

@ -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

8
curl-demo/get_balances.sh Executable file
View File

@ -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]'

6
curl-demo/get_candles.sh Executable file
View File

@ -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]'

8
curl-demo/get_coins.sh Executable file
View File

@ -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]'

6
curl-demo/get_markets.sh Executable file
View File

@ -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'

6
curl-demo/get_orderbook.sh Executable file
View File

@ -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]

8
curl-demo/get_orders.sh Executable file
View File

@ -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'

8
curl-demo/get_positions.sh Executable file
View File

@ -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]'

6
curl-demo/get_trades.sh Executable file
View File

@ -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]'

34
curl-demo/post_order.sh Executable file
View File

@ -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"
}
'

View File

@ -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