serum-community / pyserum

Pyserum is client library to interact with Serum DEX
MIT License
160 stars 61 forks source link

Does this work with Serum v3? #101

Open jaimindp opened 2 years ago

jaimindp commented 2 years ago

Does Pyserum work with Serum v3?

After following the test code for market.place_order() I am getting the error on the Solana Block Explorer:

Program returned error: invalid program argument Runtime error: invalid program argument

quazzuk commented 2 years ago

Does Pyserum work with Serum v3?

Yes, it does.

jaimindp commented 2 years ago

I am having this error when trying to place a limit order on the SOL/USDC order book and am wondering why?

The transaction goes through, (the quote wallet is created) however the order on the Solana explorer it fails with: invalid program argument

I am wondering how I can fix this?

from pyserum.connection import conn
from pyserum.enums import OrderType, Side
from pyserum.market import Market
from solana.account import Account
from solana.publickey import PublicKey
from solana.rpc.types import TxOpts
from spl.token.client import Token
from spl.token.constants import TOKEN_PROGRAM_ID

cc = conn("https://solana-api.projectserum.com")
payer = keypair

quote_token = Token(
    cc,
    pubkey=PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"), # mint address of token USDC
    program_id=TOKEN_PROGRAM_ID,
    payer=payer,
)

quote_wallet = quote_token.create_account(
  payer.public_key,
  skip_confirmation=True)  # Make sure you send tokens to this address
print("quote wallet: ", str(quote_wallet))

market_address = PublicKey("9wFFyRfZBsuAha4YcuxcXLKwMxJR43S7fPfQLusDBzvT") # Address for SOL/USDC
market = Market.load(cc, market_address)

tx_sig = market.place_order(
    payer=quote_wallet,
    owner=payer,
    side=Side.BUY,
    order_type=OrderType.LIMIT,
    limit_price=179,
    max_quantity=0.01,
    opts = TxOpts(skip_preflight=True)
)
print(tx_sig)
a742377190 commented 2 years ago

I also encountered this problem, could you give me a sample code?thanks

xloem commented 2 years ago

For me this was because my max_quantity was zero. I believe it should be an integer in lamports, so 0.01 would get rounded to zero. Could be wrong, still trying to make it work.