Code Monkey home page Code Monkey logo

pyserum's Introduction

Actions Status Codecov

PySerum

Python client library for interacting with the Project Serum DEX.

Install

pip install pyserum

Getting Started

Mainnet Market Addresses

from pyserum.connection import get_live_markets, get_token_mints
print("tokens: ")
print(get_token_mints())
print("markets: ")
print(get_live_markets())

The source of truth of the market addresses can be found here.

Get Orderbook

from pyserum.connection import conn
from pyserum.market import Market

cc = conn("https://api.mainnet-beta.solana.com/")
market_address = "5LgJphS6D5zXwUVPU7eCryDBkyta3AidrJ5vjNU6BcGW" # Address for BTC/USDC

# Load the given market
market = Market.load(cc, market_address)
asks = market.load_asks()
# Show all current ask order
print("Ask Orders:")
for ask in asks:
    print("Order id: %d, price: %f, size: %f." % (
          ask.order_id, ask.info.price, ask.info.size))

print("\n")
# Show all current bid order
print("Bid Orders:")
bids = market.load_bids()
for bid in bids:
    print(f"Order id: {bid.order_id}, price: {bid.info.price}, size: {bid.info.size}.")

Get Orderbook (Async)

import asyncio
from pyserum.async_connection import async_conn
from pyserum.market import AsyncMarket


async def main():
    market_address = "5LgJphS6D5zXwUVPU7eCryDBkyta3AidrJ5vjNU6BcGW"  # Address for BTC/USDC
    async with async_conn("https://api.mainnet-beta.solana.com/") as cc:
        # Load the given market
        market = await AsyncMarket.load(cc, market_address)
        asks = await market.load_asks()
        # Show all current ask order
        print("Ask Orders:")
        for ask in asks:
            print(f"Order id: {ask.order_id}, price: {ask.info.price}, size: {ask.info.size}.")
        print("\n")
        # Show all current bid order
        print("Bid Orders:")
        bids = await market.load_bids()
        for bid in bids:
            print(f"Order id: {bid.order_id}, price: {bid.info.price}, size: {bid.info.size}.")


asyncio.run(main())

Support

Need help? You can find us on the Serum Discord:

Discord Chat

Development

Setup

  1. Install pipenv.
brew install pipenv
  1. Install dev dependencies.
pipenv install --dev
  1. Activate the pipenv shell.
pipenv shell

Format

make format

Lint

make lint

Tests

# Unit tests
make unit-tests
# Integration tests
make int-tests

Using Jupyter Notebook

make notebook

Start Serum in Docker image

./scripts/bootstrap_dex.sh

This will start a docker container with solana image and deploy a serum DEX which you can use for testing.

The market address, program id, and wallet addresses can be found in the new crank.log file after the script runs successfully.

pyserum's People

Contributors

michaelhly avatar leofisg avatar kevinheavey avatar quazzuk avatar candidatek avatar davewk avatar imaclean74 avatar jarry-xiao avatar aqt01 avatar moshemalawach avatar romanagureev avatar sirpalamede avatar 0xtristan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.