Skip to main content

Python integration for https://mango.markets

Project description

🥭 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mango-explorer-3.3.0.tar.gz (671.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mango_explorer-3.3.0-py3-none-any.whl (837.1 kB view details)

Uploaded Python 3

File details

Details for the file mango-explorer-3.3.0.tar.gz.

File metadata

  • Download URL: mango-explorer-3.3.0.tar.gz
  • Upload date:
  • Size: 671.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.9.6 Linux/5.11.0-1025-azure

File hashes

Hashes for mango-explorer-3.3.0.tar.gz
Algorithm Hash digest
SHA256 0fcffc99080fec00212d1440dbaf0f9a9d039ae5dd40938827683e84119f5335
MD5 b01bec8e729e4363e44a2dba9fdc7461
BLAKE2b-256 dca778335104b093f14224a5c135713a7cafb75b1cada7dc44e2e4f577ac5c19

See more details on using hashes here.

File details

Details for the file mango_explorer-3.3.0-py3-none-any.whl.

File metadata

  • Download URL: mango_explorer-3.3.0-py3-none-any.whl
  • Upload date:
  • Size: 837.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.9.6 Linux/5.11.0-1025-azure

File hashes

Hashes for mango_explorer-3.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 04f5fbbcc4bc72a927f686acae54933e7817bfff3af7c775130915f214978b78
MD5 27f3d7fceebf03a3b80d137331570ff8
BLAKE2b-256 522438ddfe7d53057f9ba908a5d2204f450c6372817877928b1e4bc8e99c3707

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page