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