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
Sabe is a python framework written for easy web server setup.

Sabe is a python framework written for easy web server setup. Sabe, kolay web sunucusu kurulumu için yazılmış bir python çerçevesidir. Öğrenmesi kola

2 Jan 01, 2022
This is an API to get user details for competitive coding platforms - Codeforces, Codechef, SPOJ, Interviewbit. More Platform will be Added Soon.

Competitive-Programming-Score-API An API to get user details for competitive coding platforms - Codeforces, Codechef, SPOJ, Interviewbit Platforms Ava

Aaditya Prakash 3 Jan 17, 2022
A python script to get your activity

activities A python script to get your activity Not complete Requirements Python (=3.7) Pip (for python = 3.7) Git Pip packages psutil asyncio aioht

StarNumber 3 Nov 07, 2021
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
LanguageCreator - Simple library for easy creation transpilator.

LanguageCreator - Simple library for easy creation transpilator. Create transpilators in one hour! Install. Download code, rename folder to "LanguageC

Ivan Perzhinsky. 2 Dec 31, 2021
Types for the Rasterio package

types-rasterio Types for the rasterio package A work in progress Install Not yet published to PyPI pip install types-rasterio These type definitions

Kyle Barron 7 Sep 10, 2021
Contains a Jupyter Notebook for calculating remaining plants required based on field/lathhouse data.

Davis-Sunflowers-Su21 Project goals: Plants influence their reproduction and mating system in many ways. Various factors such as time of flowering, ab

1 Feb 10, 2022
A python script that changes your desktop background based on current weather and time of the day.

Desktop background wallpaper, based on current weather and time A python script that changes your computer's desktop background based on current weath

Maj Gaberšček 1 Nov 16, 2021
A powerful and user-friendly binary analysis platform!

angr angr is a platform-agnostic binary analysis framework. It is brought to you by the Computer Security Lab at UC Santa Barbara, SEFCOM at Arizona S

6.3k Jan 02, 2023
A simple streamlit webapp with multiple functionality

A simple streamlit webapp with multiple functionality

Omkar Pramod Hankare 2 Nov 24, 2021
A Klipper plugin for accurate Z homing

Stable Z Homing for Klipper A Klipper plugin for accurate Z homing This plugin provides a new G-code command, STABLE_Z_HOME, which homes Z repeatedly

Matthew Lloyd 24 Dec 28, 2022
Track testrail productivity in automated reporting to multiple teams

django_web_app_for_testrail testrail is a test case management tool which helps any organization to track all consumption and testing of manual and au

Vignesh 2 Nov 21, 2021
HSPyLib is a Python library that will elevate your experience to another level.

HomeSetup Python Library - HSPyLib Your mature python application HSPyLib is a Python library that will elevate your experience to another level. It r

Hugo Saporetti Junior 4 Dec 14, 2022
Password manager using MySQL and Python 3.10.2

Password Manager Password manager using MySQL and Python 3.10.2 Installation Install my-project with github git clone https://github.com/AyaanSiddiq

1 Feb 18, 2022
Python Library to get fast extensive Dummy Data for testing

Dumda Python Library to get fast extensive Dummy Data for testing https://pypi.org/project/dumda/ Installation pip install dumda Usage: Cities from d

Oliver B. 0 Dec 27, 2021
The repository for AnyMacro: a Fusion360 Add-In

AnyMacro AnyMacro is an Autodesk® Fusion 360™ add-in for chaining multiple commands in a row to form Macros. Macros are created from a set of commands

1 Jan 07, 2022
A comparison of mesh generators.

This repository creates meshes of the same domains with multiple mesh generators and compares the results.

Nico Schlömer 29 Dec 12, 2022
Repls goes to sleep due to inactivity, but to keep it awake, simply host a webserver and ping it.

Repls goes to sleep due to inactivity, but to keep it awake, simply host a webserver and ping it. This repo will help you make a webserver with a bit of console controls.

2 Mar 01, 2022
A complete python calculator with 2 modes Float and Int numbers.

Python Calculator This program is made for learning purpose. Getting started This Program runs using python, install it via terminal or from thier ofi

Felix Sanchez 1 Jan 18, 2022