A project to explore and provide useful code for Mango Markets

Overview

🥭 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.

Run these notebooks on Binder: Binder

Introduction

I am not yet confident in the figures and calculations. Please don't rely on this code yet!

There are some notebook pages to explore Mango account structures for your own accounts.

There is also a functional liquidator (in the V2 branch) and a functional marketmaker (in the main branch).

Running the marketmaker

There is a Marketmaking Quickstart - a walkthrough of setting up and running the marketmaker, 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.

Running the liquidator

There is a Liquidator Quickstart - a walkthrough of setting up and running the liquidator, from creating the account, 'balancing' the wallet across the different tokens, and running the liquidator itself.

It can take around 30 minutes to run through.

Requirements:

  • A server with docker installed
  • Some SOL to pay for transactions
  • Some USDC to fund the liquidation wallet

Note This is only for liquidating Mango V2. There is no Python V3 liquidator for Mango here (yet).

References

Support

You can contact me @OpinionatedGeek on Twitter.

Comments
  • Faiing to run notebook

    Faiing to run notebook

    I'm trying to run ShowAccount.ipynb, so I cloned the repo and did pip install requirements.txt which worked fine.

    I'm now trying to run the second cell and I get the following error: ModuleNotFoundError: No module named 'solana.keypair'

    Has this dependency been missed from requirements.txt or am I making incorrect use of this repo?

    opened by CharlesFr 12
  • Using different ports for http and ws connections

    Using different ports for http and ws connections

    I would like to use the PR as a manner to discuss a trouble when I want to use different ports for HTTP(S) and WS(S) connections. Currently the cluster_urls can be configured as https and then the protocol is switched for wss when websocket subscription is created : https://github.com/blockworks-foundation/mango-explorer/blob/main/mango/websocketsubscription.py#L62

    What I would need is having chance to define different protocol https vs. ws and/or different port for WS and HTTP connections.

    I'm thinking about changes in code. (The currently proposed ones neither work fully nor are clean for being good to be merged.)

    I was thinking to have instead of cluster_urls: typing.Sequence[str] a dictionary like cluster_urls: typing.Dict[str,str] where would be possible to say cluster_urls = {'https': 'https://localhost:8080', 'ws': 'ws://localhost:8181'}. But this kind of change is more difficult to place to be loaded from command line args (or maybe not and I just need to find how to do it). I took kind of side step here in way to represent the issue.

    If such kind of change would be desirable then I would fix and clean the proposed code in way that will be recommended to me. If such kind of change is not a thing that should be part of this codebase I will delete this PR.

    Thank you for any feedback.

    opened by ochaloup 10
  • `mango-explorer` 'Exception: Cannot find base token or perp market' on devnet

    `mango-explorer` 'Exception: Cannot find base token or perp market' on devnet

    It was working last Friday, but throwing exceptions today on devnet. It still works on mainnet.

    ~$ mango-explorer show-account-balances --cluster-name devnet
    2021-12-13 03:49:08 ⚠ root         
    ⚠ 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.
    
        🥭 Mango Markets: https://mango.markets
        📄 Documentation: https://docs.mango.markets/
        💬 Discord: https://discord.gg/67jySBhxrg
        🐦 Twitter: https://twitter.com/mangomarkets
        🚧 Github: https://github.com/blockworks-foundation
        📧 Email: mailto:[email protected]
    
    Traceback (most recent call last):
      File "/app/bin/show-account-balances", line 30, in <module>
        group: mango.Group = mango.Group.load(context)
      File "/app/mango/group.py", line 343, in load
        return Group.parse(account_info, name, context.instrument_lookup, context.market_lookup)
      File "/app/mango/group.py", line 328, in parse
        return Group.from_layout(layout, name, account_info, Version.V3, instrument_lookup, market_lookup)
      File "/app/mango/group.py", line 295, in from_layout
        raise Exception(f"Cannot find base token or perp market for index {index}")
    Exception: Cannot find base token or perp market for index 10
    
    opened by juicedgrapefruit 8
  • This lib is taking  screenshots ?!

    This lib is taking screenshots ?!

    Once installed, and run :

    • I got security warnings over Ghostscript dev right
    • Once i bypassed this warnings in my own conf, and run an example script, i found... A screenshot of my shell appeared in the working directory !

    I've installed it with pip3, with your source. What's going on ?

    opened by 2Spartiate 7
  • How to get current orderbooks in Mango Markets without both own wallet and account?

    How to get current orderbooks in Mango Markets without both own wallet and account?

    Hi all. I'm a Python programmer and a cryptocurrency trader. I would like to get current orderbooks of any symbol in Mango Markets for trading. If you can, please give me some example. Thank you, your countribution.

    opened by outk 7
  • [orderbook][top-bids] fixing top bids processing

    [orderbook][top-bids] fixing top bids processing

    It seems that the top-bids are wrongly calculated when updated by watchers.

    Based on the comments and code https://github.com/blockworks-foundation/mango-explorer/blob/v3.2.8/mango/orders.py#L238 the top-bid should be at index 0. That's to reverse the order of the list. That's what the init function in OrderBook does. That's what is not done when updated in watchers https://github.com/blockworks-foundation/mango-explorer/blob/v3.2.8/mango/watchers.py#L224 the order reverse is not processed and the top-bid then returns the bid at tail.

    Not sure if reversed is correctly used at pandas dataframe creation - https://github.com/blockworks-foundation/mango-explorer/blob/v3.2.8/mango/orders.py#L284

    opened by ochaloup 7
  • Error when trying to run docker container

    Error when trying to run docker container

    Traceback (most recent call last): File "/opt/conda/bin/jupyter-notebook", line 6, in from notebook.notebookapp import main File "/opt/conda/lib/python3.9/site-packages/notebook/notebookapp.py", line 80, in from .services.contents.manager import ContentsManager File "/opt/conda/lib/python3.9/site-packages/notebook/services/contents/manager.py", line 17, in from nbformat import sign, validate as validate_nb, ValidationError File "/opt/conda/lib/python3.9/site-packages/nbformat/init.py", line 32, in from .validator import validate, ValidationError File "/opt/conda/lib/python3.9/site-packages/nbformat/validator.py", line 12, in from .json_compat import get_current_validator, ValidationError File "/opt/conda/lib/python3.9/site-packages/nbformat/json_compat.py", line 10, in import jsonschema File "/opt/conda/lib/python3.9/site-packages/jsonschema/init.py", line 11, in from jsonschema.exceptions import ( File "/opt/conda/lib/python3.9/site-packages/jsonschema/exceptions.py", line 9, in import attr ModuleNotFoundError: No module named 'attr'

    opened by gregkonush 7
  • Account is not prepared for group exception

    Account is not prepared for group exception

    Great writeup on how to run a liquidator. However, when I get to the dry run for running the liquidator I got the following exception and the liquidator terminates.

    Exception: Account 'Dd8sgey2VD1uo5jBJfwJAdfi2GZAvULcoSqAy87jQGBT' is not prepared for group '2oogpTYm1sp6LPZAWD3bp2wsFpnV2kXL1s52yyFhW5vp'.
    

    Any ideas?

    opened by joemccann 7
  • Adding option to define HTTP timeout for POST requests to RPC nodes

    Adding option to define HTTP timeout for POST requests to RPC nodes

    We do experience a trouble when HTTP request is stuck. The mango explorer market maker is then hanging forever at the requests.post call. The expected processing is that the request is timeouted and processing switches to the next node in the list. This PR proposes a change bringing such a behavior.

    @OpinionatedGeek WDYT?

    opened by ochaloup 6
  • Update the brief example in the README.md

    Update the brief example in the README.md

    The existing example is not functional, due to the change from load_orders -> load_orderbook in this commit.

    This changeset amends the example to be functional, with a small modification 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, but please let me know if you would prefer it be changed to a Python 3.7-esque syntax with f-strings etc.

    Log output from the example included below:
    Orders (initial):
    	 « OrderBook SOL-PERP [spread: 140.94000000, 82.142%]
    	BUY      98,443.41000000 at         171.58000000   :: SELL       9,262.33000000 at         312.52000000
    	BUY           0.01000000 at         100.00000000   :: SELL      10,000.00000000 at         313.24000000
    	BUY           0.01000000 at         100.00000000   :: SELL           0.10000000 at         500.00000000
    	BUY           0.01000000 at         100.00000000   :: 
    	BUY           0.01000000 at         100.00000000   :: 
    »
    
    
    Placed order:
    	 « Order BUY for 1.00000000 at 171.58000000 [ID: 0 / 1640726013288] POST_ONLY »
    
    
    Sleeping for 10 seconds...
    
    
    Orders (including our new order):
     « OrderBook SOL-PERP [spread: 140.94000000, 82.142%]
    	BUY      98,443.41000000 at         171.58000000   :: SELL       9,262.33000000 at         312.52000000
    	BUY           1.00000000 at         171.58000000   :: SELL      10,000.00000000 at         313.24000000
    	BUY           0.01000000 at         100.00000000   :: SELL           0.10000000 at         500.00000000
    	BUY           0.01000000 at         100.00000000   :: 
    	BUY           0.01000000 at         100.00000000   :: 
    »
    
    
    Cancellation signature:
    	 ['2E3etN9jdFC4eV5zhrCEv5P4BdzVq4auHnK4oG1SKbUhyXMMBGT4Jd1T5KXB7c7s6u8FGwz1AA3Y3yAVapWBWvEX']
    
    
    Sleeping for 10 seconds...
    
    
    Orders (without our order):
     « OrderBook SOL-PERP [spread: 140.94000000, 82.142%]
    	BUY      98,443.41000000 at         171.58000000   :: SELL       9,262.33000000 at         312.52000000
    	BUY           0.01000000 at         100.00000000   :: SELL      10,000.00000000 at         313.24000000
    	BUY           0.01000000 at         100.00000000   :: SELL           0.10000000 at         500.00000000
    	BUY           0.01000000 at         100.00000000   :: 
    	BUY           0.01000000 at         100.00000000   :: 
    »
    
    opened by AaronCritchley 6
  • [marketmaker] possible to configure tpu retransmissions (max retries in txn opts) when sending a transaction

    [marketmaker] possible to configure tpu retransmissions (max retries in txn opts) when sending a transaction

    There is a missing way to configure the max retries on sending transaction to RPC node. The attempt of this PR is to fix this deficiency. What do you think @OpinionatedGeek ?

    opened by ochaloup 5
  • PerpAccount.base_token_value display issue

    PerpAccount.base_token_value display issue

    >>> sl.net_value
    « InstrumentValue:        -0.00040000 BTC »
    >>> sl.perp_account.base_token_value
    « InstrumentValue:       400.00000000 BTC »
    >>> sl.perp_account.base_position_raw
    Decimal('400')
    

    Instrument value of perp base token position is shown in raw. Should convert by decimal.

    opened by 0xhipo 0
  • Pip install not working

    Pip install not working

    Hi I tried to install mango-explorer via pip. We got an error

    ERROR: Could not find a version that satisfies the requirement mango-explorer (from versions: none)

    opened by sbhadade 1
  • Getting the average entry price for a perp position

    Getting the average entry price for a perp position

    Hello team,

    I've been going through the sdk, but can't seem to find how to get the average entry price for a perpetual position.

    Can someone let me know what's the way to do that?

    Thanks

    opened by PlamenHristov 0
  • Place-Order error

    Place-Order error

    hello, every time I try to place an order on the devnet i get the following error: I am using the devnet wallet with enough SOL 4xrjGMTBD3SmcWaMHbhXL8nFS3dnF11JD5UfoAYyyfgk

     « TransactionException in 'Mango Explorer' [sendTransaction]: -32002:: Transaction failed with: 'Transaction simulation failed: Attempt to debit an account but found no record of a prior credit.'
         Instructions:
             « Mango Instruction: PlacePerpOrder2: side: SELL, order_type: IOC, price: 100, max_base_quantity: 100, max_quote_quantity: 9223372036854775807, client_order_id: 1650763345486, reduce_only: False, expiry_timestamp: 1970-01-01 00:00:00+00:00, limit: 20
                 Program ID: 4skJ85cdxQAFVKbcGgfun8iZPL7BadVYXG3kGEGkufqA
                 Data: 4000000064000000000000006400000000000000ffffffffffffff7f4eae295980010000000000000000000001010014
                 Key[ 0]: Ec2enZyoC4nGpEfu2sUNAa2nUGJHWxoUWYSEJ2hNTWTA
                 Key[ 1]: 2iHDpuKEZ4XJVe4s5xNJHf6JXx6V8eJgynnxE61BM5pc
                 Key[ 2]: BJ6aXBAMbeZAxDVThRzEEmp3KeiBcMiXK8y9HuHs6hr8
                 Key[ 3]: 8mFQbdXsFXt3R3cu3oSNS3bDZRwJRP18vyzd9J278J9z
                 Key[ 4]: 58vac8i9QXStG1hpaa4ouwE1X7ngeDjY9oY7R15hcbKJ
                 Key[ 5]: 7HRgm8iXEDx2TmSETo3Lq9SXkF954HMVKNiq8t5sKvQS
                 Key[ 6]: 4oNxXQv1Rx3h7aNWjhTs3PWBoXdoPZjCaikSThV4yGb8
                 Key[ 7]: CZ5MCRvkN38d5pnZDDEEyMiED3drgDUVpEUjkuJq31Kf
                 Key[ 8]: 2iHDpuKEZ4XJVe4s5xNJHf6JXx6V8eJgynnxE61BM5pc
                 Key[ 9]: 474RTTzzH5BBw1M8ujxQPiAqKHMMpKPMRx1vRQAqPpRJ
             »
             « Mango Instruction: ConsumeEvents: limit: 5
                 Program ID: 4skJ85cdxQAFVKbcGgfun8iZPL7BadVYXG3kGEGkufqA
                 Data: 0f0000000500000000000000
                 Key[ 0]: Ec2enZyoC4nGpEfu2sUNAa2nUGJHWxoUWYSEJ2hNTWTA
                 Key[ 1]: 8mFQbdXsFXt3R3cu3oSNS3bDZRwJRP18vyzd9J278J9z
                 Key[ 2]: 58vac8i9QXStG1hpaa4ouwE1X7ngeDjY9oY7R15hcbKJ
                 Key[ 3]: CZ5MCRvkN38d5pnZDDEEyMiED3drgDUVpEUjkuJq31Kf
                 Key[ 4]: 2iHDpuKEZ4XJVe4s5xNJHf6JXx6V8eJgynnxE61BM5pc
             »
         Accounts:
             No Accounts
         Errors:
             AccountNotFound
         Logs:
             No Logs
     »
    
    opened by luizfelipevbll 0
Releases(v3.4.10)
Owner
Blockworks Foundation
Blockworks Foundation
This is a database of 180.000+ symbols containing Equities, ETFs, Funds, Indices, Futures, Options, Currencies, Cryptocurrencies and Money Markets.

Finance Database As a private investor, the sheer amount of information that can be found on the internet is rather daunting.

Jeroen Bouma 1.4k Dec 31, 2022
Explore-bikeshare-data - GitHub project as part of the Programming for Data Science with Python Nanodegree from Udacity

Date created February 10, 2022 Project Title Explore US Bikeshare Data Descripti

Thárcyla 1 Feb 14, 2022
A simple project which is a ecm to found a good way to provide a path to img_dir in gooey

ECM to find a good way for img_dir Path in Gooey This code is just an ECM to find a good way to indicate a path of image in image_dir variable. We loo

Jean-Emmanuel Longueville 1 Oct 25, 2021
Explore related sequences in the OEIS

OEIS explorer This is a tool for exploring two different kinds of relationships between sequences in the OEIS: mentions (links) of other sequences on

Alex Hall 6 Mar 15, 2022
An interactive tool with which to explore the possible imaging performance of candidate ngEHT architectures.

ngEHTexplorer An interactive tool with which to explore the possible imaging performance of candidate ngEHT architectures. Welcome! ngEHTexplorer is a

Avery Broderick 7 Jan 28, 2022
A turtlebot auto controller allows robot to autonomously explore environment.

A turtlebot auto controller allows robot to autonomously explore environment.

Yuliang Zhong 1 Nov 10, 2021
Gobigger Explore For Python

Gobigger-Explore ?? GoBigger Challenge 2021 Baseline en/中文 ?? Introduction This is the baseline of GoBigger Multi-Agent Decision Intelligence Challeng

OpenDILab 145 Dec 22, 2022
A code base for python programs the goal is to integrate all the useful and essential functions

Base Dev EN This GitHub will be available in French and English FR Ce GitHub sera disponible en français et en anglais Author License Screen EN ???? D

Pikatsuto 1 Mar 7, 2022
Package to provide translation methods for pyramid, and means to reload translations without stopping the application

Package to provide translation methods for pyramid, and means to reload translations without stopping the application

Grzegorz Śliwiński 4 Nov 20, 2022
Provide Prometheus url_sd compatible API Endpoint with data from Netbox

netbox-plugin-prometheus-sd Provide Prometheus http_sd compatible API Endpoint with data from Netbox. HTTP SD is a new feature in Prometheus and not a

Felix Peters 66 Dec 19, 2022
1cak - An Indonesian web that provide lot of fun.

An unofficial API of 1cak.com 1cak - An Indonesian web that provide lot of fun. Endpoint Lol -> 10 Recent stored posts on database Example: https://on

Dicky Mulia Fiqri 5 Sep 27, 2022
Aerial Ace is a helper bot for poketwo which provide various functionalities on top of being a pokedex.

Aerial Ace is a helper bot for poketwo which provide various functionalities on top of being a pokedex.

Devanshu Mishra 1 Dec 1, 2021
Provide error messages for Python exceptions, even if the original message is empty

errortext is a Python package to provide error messages for Python exceptions, even if the original message is empty.

Thomas Aglassinger 0 Dec 7, 2021
A collection of existing KGQA datasets in the form of the huggingface datasets library, aiming to provide an easy-to-use access to them.

KGQA Datasets Brief Introduction This repository is a collection of existing KGQA datasets in the form of the huggingface datasets library, aiming to

Semantic Systems research group 21 Jan 6, 2023
This collection is to provide an easier way to interact with Juniper

Ansible Collection - cremsburg.apstra Overview The goal of this collection is to provide an easier way to interact with Juniper's Apstra solution. Whi

Calvin Remsburg 1 Jan 18, 2022
Supply Chain will be a SAAS platfom to provide e-logistic facilites with most optimal

Shipp It Welcome To Supply Chain App [ Shipp It ] In "Shipp It" we are creating a full solution[web+app] for a entire supply chain from receiving orde

SAIKAT_CLAW 25 Dec 26, 2022
A beautiful and useful prompt for your shell

A Powerline style prompt for your shell A beautiful and useful prompt generator for Bash, ZSH, Fish, and tcsh: Shows some important details about the

Buck Ryan 6k Jan 8, 2023
Repository, with small useful and functional applications

Repositorio,com pequenos aplicativos uteis e funcionais A ideia e ir deselvolvendo pequenos aplicativos funcionais e adicionar a este repositorio List

GabrielDuke 6 Dec 6, 2021
Blender addon that simplifies access to useful operators and adds missing functionality

Quick Menu is a Blender addon that simplifies common tasks Compatible with Blender 3.x.x Install through Edit -> Preferences -> Addons -> Install... -

passivestar 94 Dec 27, 2022