Skip to content

Commit

Permalink
TRAD-325 dont submit txs in normal examples (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Chen authored Jan 4, 2023
1 parent f607da7 commit f9b6080
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 11 deletions.
4 changes: 0 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ jobs:
name: testnet
command: |
export AUTH_HEADER=$AUTH_HEADER_TESTNET
export WALLET_SECRET_KEY=$PRIVATE_KEY
export WALLET_PUBLIC_KEY=$PUBLIC_KEY
export API_ENV="testnet"
export RUN_LIFECYCLE="false"
npm start
Expand All @@ -79,8 +77,6 @@ jobs:
name: mainnet
command: |
export AUTH_HEADER=$AUTH_HEADER_MAINNET
export WALLET_SECRET_KEY=$PRIVATE_KEY
export WALLET_PUBLIC_KEY=$PUBLIC_KEY
export API_ENV="mainnet"
export RUN_LIFECYCLE="false"
npm start
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ First, you need to set `AUTH_HEADER` in your .env file to be able to authenticat

For any methods involving transaction creation you will need to provide your
Solana private key. You can provide this via the .env file - variable
`WALLET_SECRET_KEY`. Also, please set your `WALLET_PUBLIC_KEY` to your main SOL wallet address.
See samples for more information.
`PRIVATE_KEY`. See samples for more information.

A general note on this: methods named `post*` (e.g. `postorder`) typically
do not sign/submit the transaction, only return the raw unsigned transaction.
This isn't very useful to most users (unless you want to write a signer in a
Expand All @@ -42,8 +42,7 @@ a proper `.env` file looks like something like this.

```
AUTH_HEADER="ZDIxYzE0NmItZWYxNi00ZmFmLTg5YWUtMzYwMTk4YzUyZmM4OjEwOWE5MzEzZDc2Yjg3M......................"
WALLET_SECRET_KEY="3EhZ4Epe6QrcDKQRucdftv6vWXMnpTKDV4mekSPWZEcZnJV4huzesLHwASdVUzo......................"
WALLET_PUBLIC_KEY="2JJQHAYdogfB1fE1ftcvFcsQAX................."
PRIVATE_KEY="3EhZ4Epe6QrcDKQRucdftv6vWXMnpTKDV4mekSPWZEcZnJV4huzesLHwASdVUzo......................"
```

## Development
Expand Down
51 changes: 48 additions & 3 deletions examples/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,19 +197,19 @@ async function doRequests(provider: BaseProvider) {
console.info(" ")
console.info(" ")

await callSubmitOrder(provider)
await callPostOrder(provider)
console.info(" ")
console.info(" ")

await delay(60000)

await callSubmitCancelByClientOrderID(provider)
await callPostCancelByClientOrderID(provider)
console.info(" ")
console.info(" ")

await delay(60000)

await callSettleFunds(provider)
await callPostSettleFunds(provider)
console.info(" ")
console.info(" ")

Expand Down Expand Up @@ -779,6 +779,18 @@ async function callGetRecentBlockHashStream(provider: BaseProvider) {
}

//POST requests
async function callPostOrder(provider: BaseProvider) {
try {
console.info("generating New Order transaction")
const clientOrderID = getRandom()
testOrder.clientOrderID = clientOrderID.toLocaleString("fullwide", { useGrouping: false })
const req = await provider.postOrder(testOrder)
console.info(req)
} catch (error) {
console.error("Failed to generate a New Order transaction", error)
}
}

async function callSubmitOrder(provider: BaseProvider) {
try {
console.info("Generating and submitting a New Order transaction")
Expand All @@ -791,6 +803,22 @@ async function callSubmitOrder(provider: BaseProvider) {
}
}

async function callPostCancelByClientOrderID(provider: BaseProvider) {
try {
console.info("Generating and Cancel by Client Order ID transaction")
const req = await provider.postCancelByClientOrderID({
marketAddress: marketAddress,
ownerAddress: ownerAddress,
openOrdersAddress: openOrdersAddress,
clientOrderID: testOrder.clientOrderID,
project: "P_OPENBOOK",
})
console.info(req)
} catch (error) {
console.error("Failed to generate a Cancel by Client Order ID transaction", error)
}
}

async function callSubmitCancelByClientOrderID(provider: BaseProvider) {
try {
console.info("Generating and submitting a Cancel by Client Order ID transaction")
Expand All @@ -807,6 +835,23 @@ async function callSubmitCancelByClientOrderID(provider: BaseProvider) {
}
}

async function callPostSettleFunds(provider: BaseProvider) {
try {
console.info("Generating a Settle transaction")
const req = await provider.postSettle({
market: marketAddress,
openOrdersAddress: openOrdersAddress,
baseTokenWallet: baseTokenWallet,
quoteTokenWallet: quoteTokenWallet,
ownerAddress: ownerAddress,
project: "P_OPENBOOK",
})
console.info(req)
} catch (error) {
console.error("Failed to generate a Settle transaction", error)
}
}

async function callSettleFunds(provider: BaseProvider) {
try {
console.info("Generating and submitting a Settle transaction")
Expand Down

0 comments on commit f9b6080

Please sign in to comment.