πPlace an Order - Openbook
Summary
After you get the market information and locate a trading opportunity, the next step is to place an order.
Creating Transactions
**bloXroute Labs will NEVER ask you for your private key. In general, no blockchain project should ask you for your private keys, as that would give them full control over your Solana account.
You can use the following endpoints to create partial signed transactions for any actions you want to take in Serum:
Create Order
Cancel Order
Cancel Order by ClientID
Settle
Note that these transactions are partially signed, and you will need to complete signing with your private keys for this transaction to be valid.
The easiest way of doing this is to use the Go & Python SDKs, which simplifies the step of fetching the partially signed transaction, signing it, and submitting the transaction to the network. By default, the SDKs require you to set an PRIVATE_KEY
environment variable to load your private key, though hooks are included (see sample code) for specifying the private keys in other ways (for example loading from a file). The code for both of these SDKs is open-sourced, and you can vet the implementation yourself to understand how your keys are handled in the SDK.
Example of Create Order Transaction(Go SDK)
Example of Create Order Transaction(Python SDK)
More technically, all Solana transactions consist of a message blob (bytes) and an array of signatures. Serum API returns a transaction with the message blob and an array of all other signatures, with an empty slot left for you to generate a signature with your private key against the message blob. The SDKs find this slot and complete this step for you ββ if you intend to do this step manually you might have to write some special handling with whatever Solana library you're using to create signatures.
Submitting Transaction
Once the transaction is signed, you can use our Submit Signed Transaction endpoint to propagate the transaction to the Solana network.
You need to submit transactions fairly soon after creating them: each transaction includes a reference to a recently generated Solana block hash. This reference only remains valid for a limited amount of time (150 blocks or ~1 minute 19 seconds). If you don't submit the transaction within this time frame it will no longer be valid. Again, the SDKs we provide will simplify this step for you if you choose to use them.
You might also find it useful to turn on the skipPreflight
flag in some cases for this endpoint. By default, we simulate all transaction execution before submitting them to the network to prevent transactions with errors from being submitted, since that would waste transaction fees. For high-frequency trading applications, however, you may find that transaction simulation results don't match actual execution, which might hamper what you're trying to do. In our experience, this often happens fairly frequently with canceled instructions.
Last updated