Update the brief example in the README.md

The existing example is not functional, mostly because of the change from `load_orders` -> `load_orderbook`. This commit amends the example to be functional, with a small change to place the order at a value we'd typically expect to see in the orderbook representation rather than a fixed $ value, which is hopefully a bit easier for a first time user to understand when they can see their order in the orderbook.

I have kept the `print` convention of the existing example,
This commit is contained in:
Aaron Critchley 2021-12-28 21:09:55 +00:00 committed by GitHub
parent 5e697a3bd8
commit 63dd3f3f90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 17 deletions

View File

@ -38,10 +38,11 @@ Here's a brief but complete example of how to place and cancel an order. [This e
```
import decimal
import mango
import os
import time
import mango
from mango.oracles.market.market import MarketOracle
# Load the wallet from the environment variable 'KEYPAIR'. (Other mechanisms are available.)
wallet = mango.Wallet(os.environ.get("KEYPAIR"))
@ -59,34 +60,32 @@ market = mango.ensure_market_loaded(context, stub)
market_operations = mango.create_market_operations(context, wallet, account, market, dry_run=False)
print("Orders (initial):")
for order in market_operations.load_orders():
print(order)
print("Orders (initial):\n\t", market_operations.load_orderbook())
# Go on - try to buy 1 SOL for $10.
# Check the current price in the devnet SOL-PERP Mango Markets oracle
oracle = MarketOracle(market)
price = oracle.fetch_price(context)
# Go on - try to buy 1 SOL-PERP contract for the current best bid.
order = mango.Order.from_basic_info(side=mango.Side.BUY,
price=decimal.Decimal(10),
price=price.top_bid,
quantity=decimal.Decimal(1),
order_type=mango.OrderType.POST_ONLY)
placed_order = market_operations.place_order(order)
print("\n\nplaced_order\n\t", placed_order)
print("\n\nPlaced order:\n\t", placed_order)
print("\n\nSleeping for 10 seconds...")
time.sleep(10)
print("\n\nOrders (including our new order):")
for order in market_operations.load_orders():
print(order)
print("\n\nOrders (including our new order):\n", market_operations.load_orderbook())
cancellaton_signatures = market_operations.cancel_order(placed_order)
print("\n\ncancellaton_signatures:\n\t", cancellaton_signatures)
cancellation_signatures = market_operations.cancel_order(placed_order)
print("\n\nCancellation signature:\n\t", cancellation_signatures)
print("\n\nSleeping for 10 seconds...")
time.sleep(10)
print("\n\nOrders (without our order):")
for order in market_operations.load_orders():
print(order)
print("\n\nOrders (without our order):\n", market_operations.load_orderbook())
```
@ -116,4 +115,4 @@ Requirements:
# Support
[🥭 Mango Markets](https://mango.markets/) support is available at: [Docs](https://docs.mango.markets/) | [Discord](https://discord.gg/67jySBhxrg) | [Twitter](https://twitter.com/mangomarkets) | [Github](https://github.com/blockworks-foundation) | [Email](mailto:hello@blockworks.foundation)
[🥭 Mango Markets](https://mango.markets/) support is available at: [Docs](https://docs.mango.markets/) | [Discord](https://discord.gg/67jySBhxrg) | [Twitter](https://twitter.com/mangomarkets) | [Github](https://github.com/blockworks-foundation) | [Email](mailto:hello@blockworks.foundation)