Renamed fetch-price to show-price

This commit is contained in:
Geoff Taylor 2022-01-19 12:11:19 +00:00
parent 8ad9033948
commit 3133d5ba15
5 changed files with 54 additions and 7 deletions

47
bin/show-price Executable file
View File

@ -0,0 +1,47 @@
#!/usr/bin/env python3
import argparse
import logging
import os
import os.path
import sys
sys.path.insert(0, os.path.abspath(
os.path.join(os.path.dirname(__file__), "..")))
import mango # nopep8
parser = argparse.ArgumentParser(description="Displays the price from the Pyth Network.")
mango.ContextBuilder.add_command_line_parameters(parser)
parser.add_argument("--provider", type=str, required=True,
help="name of the price provider to use (e.g. pyth)")
parser.add_argument("--market", type=str, required=True,
help="market symbol to display (e.g. ETH/USDC)")
parser.add_argument("--stream", action="store_true", default=False,
help="stream the prices until stopped")
args: argparse.Namespace = mango.parse_args(parser)
context = mango.ContextBuilder.from_command_line_parameters(args)
logging.info(str(context))
oracle_provider: mango.OracleProvider = mango.create_oracle_provider(context, args.provider)
market = context.market_lookup.find_by_symbol(args.market)
if market is None:
raise Exception(f"Could not find market {args.market}.")
oracle = oracle_provider.oracle_for_market(context, market)
if oracle is None:
mango.output(f"Could not find oracle for market {market.symbol} from provider {args.provider}.")
else:
if not args.stream:
price = oracle.fetch_price(context)
mango.output(price)
else:
mango.output("Press <ENTER> to quit.")
price_subscription = oracle.to_streaming_observable(context)
disposable = price_subscription.subscribe(mango.PrintingObserverSubscriber(False))
# Wait - don't exit
input()
disposable.dispose()

View File

@ -25,7 +25,7 @@ while :
do
cancel-my-orders --name "WSMM ${MARKET} (cancel)" --market $MARKET --log-level ERROR
CURRENT_PRICE=$(fetch-price --provider serum --symbol $ORACLE_MARKET --log-level ERROR --cluster-name mainnet | cut -d"'" -f 2 | sed 's/,//')
CURRENT_PRICE=$(show-price --provider serum --market $ORACLE_MARKET --log-level ERROR --cluster-name mainnet | cut -d"'" -f 2 | sed 's/,//')
place-order --name "WSMM ${MARKET} (buy)" --market $MARKET --order-type LIMIT \
--log-level ERROR --side BUY --quantity $FIXED_POSITION_SIZE --price $(echo "$CURRENT_PRICE - $FIXED_SPREAD" | bc)
place-order --name "WSMM ${MARKET} (sell)" --market $MARKET --order-type LIMIT \
@ -43,7 +43,7 @@ mango-explorer worlds-simplest-market-maker ETH-PERP 1 10 30
```
Thats not bad for 21 lines of `bash` scripting! OK, the price-fetching is a bit contorted, but you can see its calling:
* `cancel-my-orders`
* `fetch-price`
* `show-price`
* `place-order` (BUY)
* `place-order` (SELL)
* `sleep`

View File

@ -22,11 +22,11 @@ Specifics to each of these implementations are detailed later in the 'Oracle Ref
You can see an example of using an oracle to fetch the current price by using the following command:
```
$ fetch-price --symbol BTC/USDC --provider ftx
$ show-price --market BTC/USDC --provider ftx
```
Alternatively, to get the current price of the BTC perp on Mango:
```
$ fetch-price --symbol BTC-PERP --provider market
$ show-price --market BTC-PERP --provider market
```

View File

@ -10,7 +10,7 @@ do
cancel-my-orders --name "Random Taker ${MARKET} (cancel)" --market $MARKET --log-level ERROR
RANDOM_POSITION_SIZE=$(echo "scale=4; ($(echo "$RANDOM % 1000" | bc) / 1000) * $POSITION_SIZE_CEILING" | bc)
CURRENT_PRICE=$(fetch-price --provider ftx --symbol $ORACLE_MARKET --log-level ERROR 2>&1 | cut -d" " -f 8 | sed 's/,//')
CURRENT_PRICE=$(show-price --provider ftx --market $ORACLE_MARKET --log-level ERROR 2>&1 | cut -d" " -f 8 | sed 's/,//')
place-order --name "Random Taker ${MARKET} (place buy)" --market $MARKET --order-type IOC --log-level ERROR \
--side BUY --quantity $RANDOM_POSITION_SIZE --price $(echo "$CURRENT_PRICE + $IMMEDIATE_BUY_ADJUSTMENT" | bc)
@ -19,7 +19,7 @@ do
sleep ${PAUSE_FOR}
RANDOM_POSITION_SIZE=$(echo "scale=4; ($(echo "$RANDOM % 1000" | bc) / 1000) * $POSITION_SIZE_CEILING" | bc)
CURRENT_PRICE=$(fetch-price --provider ftx --symbol $ORACLE_MARKET --log-level ERROR 2>&1 | cut -d" " -f 8 | sed 's/,//')
CURRENT_PRICE=$(show-price --provider ftx --market $ORACLE_MARKET --log-level ERROR 2>&1 | cut -d" " -f 8 | sed 's/,//')
place-order --name "Random Taker ${MARKET} (place sell)" --market $MARKET --order-type IOC --log-level ERROR \
--side SELL --quantity $RANDOM_POSITION_SIZE --price $(echo "$CURRENT_PRICE - $IMMEDIATE_BUY_ADJUSTMENT" | bc)

View File

@ -10,7 +10,7 @@ while :
do
cancel-my-orders --name "WSMM ${MARKET} (cancel)" --market $MARKET --log-level ERROR
CURRENT_PRICE=$(fetch-price --provider serum --symbol $ORACLE_MARKET --log-level ERROR --cluster-name mainnet | cut -d"'" -f 2 | sed 's/,//')
CURRENT_PRICE=$(show-price --provider serum --market $ORACLE_MARKET --log-level ERROR --cluster-name mainnet | cut -d"'" -f 2 | sed 's/,//')
place-order --name "WSMM ${MARKET} (buy)" --market $MARKET --order-type LIMIT \
--log-level ERROR --side BUY --quantity $FIXED_POSITION_SIZE --price $(echo "$CURRENT_PRICE - $FIXED_SPREAD" | bc)
place-order --name "WSMM ${MARKET} (sell)" --market $MARKET --order-type LIMIT \