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 the course repository for the Spring 2022 iteration of MACS 30123 "Large-Scale Computing for the Social Sciences" at the University of Chicago.

Large-Scale Computing for the Social Sciences Spring 2022 - MACS 30123/MAPS 30123/PLSC 30123 Instructor Information TA Information TA Information Cour

6 May 06, 2022
Generate your personal 8-bit avatars using Cellular Automata, a mathematical model that simulates life, survival, and extinction

Try the interactive demo here ✨ ✨ Sprites-as-a-Service is an open-source web application that allows you to generate custom 8-bit sprites using Cellul

Lj Miranda 265 Dec 26, 2022
LAPS module for CrackMapExec

Crackmapexec-LAPS LAPS module for CrackMapExec Make sure to point to the DC Specify the full domain name Be careful the rid 500 might not be "Administ

28 Oct 05, 2022
A wrapper around the python Tkinter library for customizable and modern ui-elements in Tkinter

CustomTkinter With CustomTkinter you can create modern looking user interfaces in python with tkinter. CustomTkinter is a tkinter extension which prov

4.9k Jan 02, 2023
A check numbers python module

Made with Python3 (C) @FayasNoushad Copyright permission under MIT License License - https://github.com/FayasNoushad/Numbers/blob/main/LICENSE Deplo

Fayas Noushad 3 Nov 28, 2021
Python Create Your Own Tool Series

Python Create Your Own Tool Series Hey there! This is an additional Github repository that contains the final product files for each video in my Youtu

Joe Helle 21 Dec 02, 2022
Polypheny Connector for Python

Polypheny Connector for Python This enables Python programs to access Polypheny databases, using an API that is compliant with the Python Database API

Polypheny 3 Jan 03, 2022
Student Management System Built With Python

Student-Management-System Group Members 19BCE183 - Patel Sarthak 19BCE195 - Patel Jinil 19BCE220 - Rana Yash Project Description In our project Studen

Sarthak Patel 6 Oct 20, 2022
This is a far more in-depth and advanced version of "Write user interface to a file API Sample"

Fusion360-Write-UserInterface This is a far more in-depth and advanced version of "Write user interface to a file API Sample" from https://help.autode

4 Mar 18, 2022
An end-to-end Python-based Infrastructure as Code framework for network automation and orchestration.

Nectl An end-to-end Python-based Infrastructure as Code framework for network automation and orchestration. Features Data modelling and validation. Da

Adam Kirchberger 15 Oct 14, 2022
A simple program which gets a file(CSV/Excel) with tasks and creates different variants

TestMakerProject A simple program which gets a file(CSV/Excel) with tasks and creates different variants The main program is QTengine.py You only have

George 3 Nov 18, 2021
A Python library that helps data scientists to infer causation rather than observing correlation.

A Python library that helps data scientists to infer causation rather than observing correlation.

QuantumBlack Labs 1.7k Jan 04, 2023
Stop ask your soraka to ult you, just ult yourself

Lollo's auto-ultimate script Are you tired of your low elo friend who can't ult you with soraka when you ask for it? Use Useless Support and just ult

9 Oct 20, 2022
Tool that adds githuh profile views to ur acc

Tool that adds githuh profile views to ur acc

Lamp 2 Nov 28, 2021
Restaurant-finder - Restaurant finder With Python

restaurant-finder APIs /restaurants query-params: a. filter: column based on whi

Kumar saurav 1 Feb 22, 2022
A basic tic tac toe game on python!

A basic tic tac toe game on python!

Shubham Kumar Chandrabansi 1 Nov 18, 2021
CALPHAD tools for designing thermodynamic models, calculating phase diagrams and investigating phase equilibria.

CALPHAD tools for designing thermodynamic models, calculating phase diagrams and investigating phase equilibria.

pycalphad 189 Dec 13, 2022
A competition for forecasting electricity demand at the country-level using a standard backtesting framework

A competition for forecasting electricity demand at the country-level using a standard backtesting framework

5 Jul 12, 2022
India's own RPA Platform Python Powered

Welcome to My-AutoPylot , Made in India with ❤️ What is My-AutoPylot? PyBots is an Indian firm based in Vadodara, Gujarat. My-AutoPylot is a product d

PyBots Pvt Ltd 28 Sep 12, 2022