Skip to content

serum-community/pyserum

Repository files navigation

Actions StatusCodecov

PySerum

Python client library for interacting with the Project Serum DEX.

Install

pip install pyserum

Getting Started

Mainnet Market Addresses

frompyserum.connectionimportget_live_markets, get_token_mintsprint("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

frompyserum.connectionimportconnfrompyserum.marketimportMarketcc=conn("https://api.mainnet-beta.solana.com/") market_address="5LgJphS6D5zXwUVPU7eCryDBkyta3AidrJ5vjNU6BcGW"# Address for BTC/USDC# Load the given marketmarket=Market.load(cc, market_address) asks=market.load_asks() # Show all current ask orderprint("Ask Orders:") foraskinasks: print("Order id: %d, price: %f, size: %f."% ( ask.order_id, ask.info.price, ask.info.size)) print("\n") # Show all current bid orderprint("Bid Orders:") bids=market.load_bids() forbidinbids: print(f"Order id: {bid.order_id}, price: {bid.info.price}, size: {bid.info.size}.")

Get Orderbook (Async)

importasynciofrompyserum.async_connectionimportasync_connfrompyserum.marketimportAsyncMarketasyncdefmain(): market_address="5LgJphS6D5zXwUVPU7eCryDBkyta3AidrJ5vjNU6BcGW"# Address for BTC/USDCasyncwithasync_conn("https://api.mainnet-beta.solana.com/") ascc: # Load the given marketmarket=awaitAsyncMarket.load(cc, market_address) asks=awaitmarket.load_asks() # Show all current ask orderprint("Ask Orders:") foraskinasks: print(f"Order id: {ask.order_id}, price: {ask.info.price}, size: {ask.info.size}.") print("\n") # Show all current bid orderprint("Bid Orders:") bids=awaitmarket.load_bids() forbidinbids: 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.

About

Pyserum is client library to interact with Serum DEX

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 13