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
Domoticz-hyundai-kia - Domoticz Hyundai-Kia plugin for Domoticz home automation system

Domoticz Hyundai-Kia plugin Author: Creasol https://www.creasol.it/domotics For

Creasol 7 Aug 03, 2022
WorldsCollide - Final Fantasy VI Randomizer

FFVI Worlds Collide Worlds Collide is an open worlds randomizer for Final Fantas

8 Jun 13, 2022
Monochrome's API, implemented with Deta Base and Deta Drive.

Monochrome Monochrome's API, implemented with Deta Base and Deta Drive. Create a free account on Deta to test this out! Most users will prefer the Mon

Monochrome 5 Sep 22, 2022
A small Blender addon for changing an object's local orientation while in edit mode

A small Blender addon for changing an object's local orientation while in edit mode.

Jonathan Lampel 50 Jan 06, 2023
Yet another Python Implementation of the Elo rating system.

Python Implementation - Elo Rating System Yet another Python Implementation of the Elo rating system (how innovative am I right?). Only supports 1vs1

Kraktoos 5 Dec 22, 2022
Given tool find related trending keywords of input keyword

blog_generator Given tool find related trending keywords of input keyword (blog_related_to_keyword). Then cretes a mini blog. Currently its customised

Shivanshu Srivastava 2 Nov 30, 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
Control System Packer is a lightweight, low-level program to transform energy equations into the compact libraries for control systems.

Control System Packer is a lightweight, low-level program to transform energy equations into the compact libraries for control systems. Packer supports Python 🐍 , C 💻 and C++ 💻 libraries.

mirnanoukari 31 Sep 15, 2022
A desktop app to check the unlocked courses bases on previously done courses.

Course Picker A desktop app to check the unlocked courses bases on previously done courses. Table of contents About the Project Built with What it doe

Ahmed Symum Swapno 3 Feb 07, 2022
Hexa is an advanced browser.It can carry out all the functions present in a browser.

Hexa is an advanced browser.It can carry out all the functions present in a browser.It is coded in the language Python using the modules PyQt5 and sys mainly.It is gonna get developed more in the fut

1 Dec 10, 2021
Understanding the field usage of any object in Salesforce

Understanding the field usage of any object in Salesforce One of the biggest problems that I have addressed while working with Salesforce is to unders

Sebastian Undurraga 1 Dec 14, 2021
Data on COVID-19 (coronavirus) cases, deaths, hospitalizations, tests • All countries • Updated daily by Our World in Data

COVID-19 Dataset by Our World in Data Find our data on COVID-19 and its documentation in public/data. Documentation Data: complete COVID-19 dataset Da

Our World in Data 5.5k Jan 03, 2023
Drug Discovery App Using Lipinski's Rule-of-Five.

Drug Discovery App A Drug Discovery App Using Lipinski's Rule-of-Five. TAPIWA CHAMBOKO 🚀 About Me I'm a full stack developer experienced in deploying

tapiwa chamboko 3 Nov 08, 2022
Vita Specific Patches and Application for Doki Doki Literature Club (Steam Version) using Ren'Py PSVita

Doki-Doki-Literature-Club-Vita Vita Specific Patches and Application for Doki Doki Literature Club (Steam Version) using Ren'Py PSVita Contains: Modif

Jaylon Gowie 25 Dec 30, 2022
Absolute solvation free energy calculations with OpenFF and OpenMM

ABsolute SOLVantion Free Energy Calculations The absolv framework aims to offer a simple API for computing the change in free energy when transferring

7 Dec 07, 2022
A server shell for you to play with Powered by Django + Nginx + Postgres + Bootstrap + Celery.

A server shell for you to play with Powered by Django + Nginx + Postgres + Bootstrap + Celery.

Mengting Song 1 Jan 10, 2022
The ROS publisher/subscriber example packaged as a snap

publisher-subscriber The ROS publisher/subscriber example packaged as a snap, based on ROS Noetic and Ubuntu Core 20. Strictly confined. This example

3 Dec 03, 2021
Xbox-Flood is for flood anything

Intruduction Installation Usage Installing Python 3 Wiki Getting Started Creating a Key Intruduction Xbox-Flood is for flooding messages (invitations

kayake 4 Feb 18, 2022
python3 scrip for case conversion of source code files writen in fixed form fortran

convert_FORTRAN_case python3 scrip for case conversion of source code files writen in fixed form fortran python3 scrip for case conversion of source c

7 Sep 20, 2022
Bionic is Python Framework for crafting beautiful, fast user experiences for web and is free and open source.

Bionic is Python Framework for crafting beautiful, fast user experiences for web and is free and open source. Getting Started This is an example of ho

14 Apr 10, 2022