0

I'm trying to convert SOL to USDT using pyserum. Here's the code I'm using.

import base58
from pyserum.connection import conn
from pyserum.enums import OrderType, Side
from pyserum.market import Market
from pyserum.connection import get_live_markets, get_token_mints
from solana.publickey import PublicKey
from solana.rpc.types import TxOpts
from solana.keypair import Keypair
from spl.token.client import Token
from spl.token.constants import TOKEN_PROGRAM_ID
from config import PRIVATEKEYPHANTOM

all_mint_address = get_token_mints()
all_market_address = get_live_markets()

if __name__ == '__main__':
    from_coin = 'SOL'
    to_coin = 'USDT'
    symbol = f"{from_coin}/{to_coin}"
    market_address = fetch_market_address(symbol)
    mint_address = fetch_mint_address(symbol)
    
    sender_key_pair = get_keypair(PRIVATEKEYPHANTOM)
    payer = Keypair(sender_key_pair[:32])
    
    cc = conn("https://api.mainnet-beta.solana.com")

    quote_token = Token(
        cc,
        pubkey=PublicKey(mint_address), # mint address of token USDT
        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(market_address) # Address for SOL/USDT
    print(market_address)
    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=0.01,
        max_quantity=1,
        opts = TxOpts(skip_preflight=True)
    )
    print(tx_sig)
    

Although, I receive the following error after execution. ** Transaction failed: Error processing Instruction 1: Unknown instruction error **

Full error can be found here

Noob
  • 117
  • 1
  • 11
  • I get the same error. Did you manage to solve the issue? – alpenmilch411 Dec 31 '21 at 16:30
  • I'm having other errors in my code when placing the order. Could you share how your `fetch_mint_address()` function works? – Jimmy Apr 30 '22 at 09:37
  • @Jimmy `fetch_mint_address()` is basically used to fetch the mint address for the transaction. Here's an example of it https://pastebin.pl/view/ae317ae1 – Noob May 01 '22 at 15:16
  • hi do you have some pyserum examples? there are none on official github – luky Oct 23 '22 at 21:43

1 Answers1

0

I struggled with the same error and finally I found that's a good idea to replicate the order at some Serum based UI. I used https://dex.raydium.io and when I tried to replicate the error I've got

Price must be an increment of 0.1

For SOL/USDC at least, there is a rule that I need to trade at least amount of 0.1. I don't know why this limitation is set at DEX and why pyserum does not show some more readable error but at least changing from 0.01 to 0.1 helped me.

chalda
  • 702
  • 4
  • 18