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
Python Programmma DarkMap.py

DarkMap Python Programmma DarkMap.py O'rganish va rasmlarni ko'riosh https://drive.google.com/drive/folders/1l1zybs_0Zy9z_trZYz5R72WrwsE6mFOh?usp=shar

Og'abek 0 May 06, 2022
Chat meetup

FLiP-Meetup-Chat Chat meetup create function bin/pulsar-admin functions create --auto-ack true --jar pulsardjlexample-1.0.jar --classname "dev.pulsarf

Timothy Spann 1 Dec 09, 2021
Batch generate asset browser previews

When dealing with hundreds of library files it becomes tedious to mark their contents as assets. Using python to automate the process is a perfect fit

54 Dec 24, 2022
A domonic-like wrapper around selectolax

A domonic-like wrapper around selectolax

byteface 3 Jun 23, 2022
Basic infrastructure for writing scripts in Python

Base Script Python is an excellent language that makes writing scripts very straightforward. Over the course of writing many scripts, we realized that

Deep Compute, LLC 9 Jan 07, 2023
TB Set color display - Add-on for Blender to set multiple objects and material Display Color at once.

TB_Set_color_display Add-on for Blender with operations to transfer name between object, data, materials and action names Set groups of object's or ma

1 Jun 01, 2022
A basic tic tac toe game on python!

A basic tic tac toe game on python!

Shubham Kumar Chandrabansi 1 Nov 18, 2021
一个可以自动生成PTGen,MediaInfo,截图,并且生成发布所需内容的脚本

Differential 差速器 一个可以自动生成PTGen,MediaInfo,截图,并且生成发种所需内容的脚本 为什么叫差速器 差速器是汽车上的一种能使左、右轮胎以不同转速转动的结构。使用同样的动力输入,差速器能够输出不同的转速。就如同这个工具之于PT资源,差速器帮你使用同一份资源,输出不同PT

Lei Shi 96 Dec 15, 2022
Inverted-pendulum-with-fuzzy-control - Inverted pendulum with fuzzy control

Fuzzy Inverted Pendulum Basically, this project consists of an inverted pendulum

Mahan Ahmadvand 1 Aug 25, 2022
Dotfiles for my configurations!

Dotfiles Repo Welcome! Over here, you can find my dotfiles for various applications, including QTile, Alacritty, Kitty, LunarVim, and more! Make sure

class PythonAddict 3 Jan 10, 2022
Um pequeno painel de consulta

Spynel Um pequeno painel com consultas de: IP CEP PLACA CNPJ OBS: caso execute o script pelo termux, recomendo que use o da F-Droid por ser mais atual

Spyware 12 Oct 25, 2022
Mmr image postbot - Бот для создания изображений с новыми релизами в сообщество ВК MMR Aggregator

Mmr image postbot - Бот для создания изображений с новыми релизами в сообщество ВК MMR Aggregator

Max 3 Jan 07, 2022
This is an implementation of NeuronJ work with python.

NeuronJ This is an implementation of NeuronJ work with python. NeuronJ is a plug-in for ImageJ that allows you to create and edit neurons masks. Image

Mohammad Mahdi Samei 3 Aug 28, 2022
An easy way to access to your EPITECH subjects based on the Roslyn's database.

An easy way to access to your EPITECH subjects based on the Roslyn's database.

Mathias 1 Feb 09, 2022
Auto-ropper is a tool that aims to automate the exploitation of ROP.

Auto-ropper is a tool that aims to automate the exploitation of ROP. Its goal is to become a tool that no longer requires user interaction.

Zerotistic 16 Nov 13, 2022
Python with braces. Because Python is awesome, but whitespace is awful.

Bython Python with braces. Because Python is awesome, but whitespace is awful. Bython is a Python preprosessor which translates curly brackets into in

1 Nov 04, 2021
🛠️ Learn a technology X by doing a project - Search engine of project-based learning

Learn X by doing Y 🛠️ Learn a technology X by doing a project Y Website You can contribute by adding projects to the CSV file.

William 408 Dec 20, 2022
A frontend to ease the use of pulseaudio's routing capabilities, mimicking voicemeeter's workflow

Pulsemeeter A frontend to ease the use of pulseaudio's routing capabilities, mimicking voicemeeter's workflow Features Create virtual inputs and outpu

Gabriel Carneiro 164 Jan 04, 2023
Zotero references script (and app)

A little script (and PyInstaller build) for a very specific, somewhat hack-ish purpose: managing and exporting project references with Zotero and its API.

Marius Rödder 0 Dec 05, 2021
Install JetBrains Toolbox

ansible-role-jetbrains-toolbox Install JetBrains Toolbox Example Playbook This example is taken from molecule/default/converge.yml and is tested on ea

Antoine Mace 2 Feb 04, 2022