Go to file
Geoff Taylor 76530318bb Added more detail about keys/accounts to instruction reporters. 2022-01-22 16:42:17 +00:00
.github/workflows Including Bandit 2022-01-09 17:57:35 +00:00
.vscode Fixed some settings for venv. 2021-10-13 18:42:02 +01:00
bin Can now specify a different 'hedging' interval in the marketmaker. 2022-01-21 17:53:25 +00:00
data Added CANCEL_ALL_PERPS instruction and a transaction reporter. 2022-01-14 17:18:31 +00:00
docs Added MarketmakerDelegation.md documentation. 2022-01-22 14:16:47 +00:00
mango Added more detail about keys/accounts to instruction reporters. 2022-01-22 16:42:17 +00:00
scripts Renamed fetch-price to show-price 2022-01-19 12:11:19 +00:00
tests Adding an option to use different rpc http and ws addresses for one cluster url 2022-01-21 06:40:00 +01:00
.dockerignore Updated git+docker ignore files. 2021-11-18 18:37:13 +00:00
.envrc Added MaximumQuantityElement and MinimumQuantityElement. 2021-11-18 12:51:57 +00:00
.flake8 Preliminary use of DataFrame calculations on Accounts. 2022-01-06 16:34:18 +00:00
.gitignore Added .venv to ignored list. 2021-11-18 18:52:35 +00:00
.mypy.ini Added some experimental JSON output for feedback. 2021-11-19 17:36:25 +00:00
Dockerfile Removed Solana CLI from Dockerfile. 2022-01-19 19:24:14 +00:00
LICENSE Initial import. 2021-04-14 16:51:39 +01:00
Makefile Refactor of code to work with mypy --strict 2021-11-09 13:23:36 +00:00
README.md Merge pull request #22 from AaronCritchley/patch-1 2021-12-30 16:07:55 +00:00
poetry.lock Updated dependencies. 2022-01-19 12:12:00 +00:00
pyproject.toml v3.3.0 2022-01-20 16:49:40 +00:00

README.md

🥭 Mango Explorer

⚠ Warning

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Introduction

mango-explorer provides Python code to interface with Mango Markets, along with a functional marketmaker.

Installation

PyPI

mango-explorer is available as a Python package on Pypi and can be installed as:

pip install mango-explorer

(Other ways of installing it or adding it as a dependency are available and will depend on the particular tools you are using.)

mango-explorer is also available as a docker container with the name opinionatedgeek/mango-explorer-v3.

Branches

The latest version of the code is in the main branch on Github.

Code to integrate with Version 2 of Mango is in the v2 branch.

Example

Here's a brief but complete example of how to place and cancel an order. This example is runnable in your browser!

import decimal
import mango
import os
import time

# Load the wallet from the environment variable 'KEYPAIR'. (Other mechanisms are available.)
wallet = mango.Wallet(os.environ.get("KEYPAIR"))

# Create a 'devnet' Context
context = mango.ContextBuilder.build(cluster_name="devnet")

# Load the wallet's account
group = mango.Group.load(context)
accounts = mango.Account.load_all_for_owner(context, wallet.address, group)
account = accounts[0]

# Load the market
stub = context.market_lookup.find_by_symbol("SOL-PERP")
market = mango.ensure_market_loaded(context, stub)

market_operations = mango.create_market_operations(context, wallet, account, market, dry_run=False)

print("Initial order book:\n\t", market_operations.load_orderbook())
print("Your current orders:\n\t", market_operations.load_my_orders())

# Go on - try to buy 1 SOL-PERP contract for $10.
order = mango.Order.from_basic_info(side=mango.Side.BUY,
                                    price=decimal.Decimal(10),
                                    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\nSleeping for 10 seconds...")
time.sleep(10)

print("\n\nOrder book (including our new order):\n", market_operations.load_orderbook())
print("Your current orders:\n\t", market_operations.load_my_orders())

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\nOrder book (without our order):\n", market_operations.load_orderbook())
print("Your current orders:\n\t", market_operations.load_my_orders())

Many more examples are provided in a separate Github repo and can be run in your browser (no installation required!) at Binder.

Running the marketmaker

There is a Marketmaking Quickstart - a walkthrough of setting up and running the marketmaker on devnet, from setting up the account, depositing tokens, to running the marketmaker itself.

It can take around 30 minutes to run through.

Requirements:

  • A server with docker installed

Note This walkthrough is devnet-only so no actual funds are used or at-risk.

References

Support

🥭 Mango Markets support is available at: Docs | Discord | Twitter | Github | Email