Algodex Documentation
  • Algodex Documentation
  • Algodex
    • Algodex FAQ
    • Trading Guide
    • Trading Bot Guide
    • Token Listing Guide
  • Algodex Mailbox
    • Mailbox FAQ
    • Mailbox User Guide
  • Rewards Program
    • ALGX Liquidity Rewards Program
    • Community Leadership
    • ALGX Tokenomics
  • Developer Tools
    • Algodex SDK v2
      • Tutorial : Placing Orders
      • Tutorial: Order book
      • Tutorial: Closing Orders
    • Algodex API v1
  • Archives
    • Algodex Whitepaper v1
    • ALGX Airdrop Plan
    • Testnet Liquidity Rewards
  • App Links
    • Algodex
    • Algodex Mailbox
    • Rewards
    • Support
  • social media links
    • REDDIT
    • TWITTER
    • DISCORD
    • TELEGRAM
    • GITHUB
Powered by GitBook
On this page
  1. Developer Tools
  2. Algodex SDK v2

Tutorial: Closing Orders

PreviousTutorial: Order bookNextAlgodex API v1

Last updated 2 years ago

Closing an Order from the

To close an order from the order book, a user must be connected to the wallet that created the order.

Cancel a Maker Order [JavaScript]

const orders = await api.placeOrder({
'asset': {
  'id': 15322902,
  'decimals': 6,
},
'address': 'WYWRYK42XADLY3O62N52BOLT27DMPRA3WNBT2OBRT65N6OEZQWD4OSH6PI',
'price': 3.22,
'amount': 1,
'execution': 'maker',
'type': 'buy',
});
await api.closeOrder(orders[0])

Finding a Single Open Order to Cancel [JavaScript]

If you do not have the order that you want to cancel, you can find all open orders under your wallet address by calling the internal method below. From there, cancelling an order is as simple as finding the specific order you would like to cancel, attaching your wallet to the order under the wallet property, and passing it into the closeOrder function.

This process is demonstrated in the example below.

  const openOrders = await api.http.dexd.fetchOrders("wallet", api.wallet.address)

  const mappedOpenOrders = openOrders.map((order) => {
    return { ...order, wallet: api.wallet }
  })

  await api.closeOrder(mappedOpenOrders[0])
}

Keep in mind that in this example, we are cancelling the first order in the open order's array. It is up to you to filter the specific order you wish to cancel.

Cancelling All Existing Orders [JavaScript]

const openOrders = await api.http.dexd.fetchOrders("wallet", order.address)

  const mappedOpenOrders = openOrders.map((order) => {
    return { ...order, wallet: api.wallet }
  })

  await Promise.all(
    mappedOpenOrders.map((order) => {
      api.closeOrder(order)
    })
  )
Order book