Go to file
waterquarks 5d91691480 Extend fills 2023-04-25 04:47:04 +00:00
.github/workflows Add async support (#82) 2021-08-12 20:36:28 +01:00
.vscode Set up repo 2020-08-29 17:28:24 -05:00
docs Set up docs (#47) 2020-10-05 21:12:53 -05:00
notebooks Changes for pypi release (#44) 2020-10-01 10:37:32 -05:00
pyserum Extend fills 2023-04-25 04:47:04 +00:00
scripts chore: use latest validator version 2022-10-18 18:19:18 +02:00
tests Added support for init and close open_orders_accounts instructions (#99) 2021-12-23 18:16:09 +08:00
.codecov.yml Set up code coverage (#38) 2020-09-19 19:09:40 -05:00
.flake8 Set up repo 2020-08-29 17:28:24 -05:00
.gitignore Patch fills 2023-04-25 03:52:34 +00:00
.pydocstyle Set up repo 2020-08-29 17:28:24 -05:00
.pylintrc Add async support (#82) 2021-08-12 20:36:28 +01:00
LICENSE Set up docs (#47) 2020-10-05 21:12:53 -05:00
Makefile Extend fills 2023-04-25 04:47:04 +00:00
Pipfile update solanapy 2022-10-18 16:53:45 +02:00
Pipfile.lock update solanapy 2022-10-18 16:53:45 +02:00
README.md Add async support (#82) 2021-08-12 20:36:28 +01:00
docker-compose.yml Support Serum v3. (#65) 2021-03-01 17:49:04 +08:00
pytest.ini Add async support (#82) 2021-08-12 20:36:28 +01:00
setup.py Extend fills 2023-04-25 04:47:04 +00:00

README.md

ActionsStatus 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.