UNPKG

@algodex/algodex-sdk

Version:

API calls for interacting with the Algorand blockchain

140 lines (114 loc) • 4.03 kB
# ℹ Placing an Order [WIP] > 🧰 You can think of {@link AlgodexApi#placeOrder} as a toolbox: it's got everything you need to tackle order execution ## 🪜 Steps 1. āš— Create a `new` instance of the {@link AlgodexApi} 2. šŸ”§ Set a default {@link Wallet} using {@link AlgodexApi#setWallet} 3. šŸ— Generate an {@link Order} compatible object 4. šŸ’ø Pass in the {@link Order} object to {@link AlgodexApi#placeOrder} # šŸ’± Order Executions > šŸ’” If you are unsure of which execution type to choose input `execution:'both'` and we'll handle the rest šŸ˜Ž ### Details: The {@link Order} object has an `execution` key that determines how the SDK will handle the {@link Order}. Each `execution` will interact with the {@tutorial Orderbook} in different ways. Algodex supports the following executions: ### Executions: <center>šŸ“„ [Maker](#maker) | šŸ“¤ [Taker](#taker) | šŸ” [Both](#both)</center> # <a name="maker"></a> šŸ“„ Maker Order A {@tutorial MakerOrder} will always be placed into the {@tutorial Orderbook}. They can be either Buy or Sell order types. ### Buy Order ```javascript //Buy Example: const res = await api.placeOrder({ 'asset': { 'id': 15322902, 'decimals': 6, }, 'address': 'WYWRYK42XADLY3O62N52BOLT27DMPRA3WNBT2OBRT65N6OEZQWD4OSH6PI', 'price': 3.22, // Limit price for the asset 'amount': 1, // Amount willing to purchase (The total amount sent will be price * amount) 'execution': 'maker', 'type': 'buy', }); ``` ### Sell Order ```javascript // Sell Example: const res = await api.placeOrder({ 'asset': { 'id': 15322902, 'decimals': 6, }, 'address': 'WYWRYK42XADLY3O62N52BOLT27DMPRA3WNBT2OBRT65N6OEZQWD4OSH6PI', 'price': 80000, // Limit price for the asset to sell 'amount': 1, // Amount of the asset for sale 'execution': 'maker', 'type': 'sell', }); ``` # <a name="taker"></a> šŸ“¤ Taker Order A {@tutorial TakerOrder} will always execute existing orders in the {@tutorial Orderbook}. They can be either Buy or Sell order types. ### Buy Order ```javascript // Buy Example const res = await api.placeOrder({ 'asset': { 'id': 15322902, 'decimals': 6, }, 'address': 'WYWRYK42XADLY3O62N52BOLT27DMPRA3WNBT2OBRT65N6OEZQWD4OSH6PI', 'price': 3.22, 'amount': 1, 'execution': 'taker', 'type': 'buy', }); ``` ### Sell Order ```javascript // Sell Example const res = await api.placeOrder({ 'asset': { 'id': 15322902, 'decimals': 6, }, 'address': 'WYWRYK42XADLY3O62N52BOLT27DMPRA3WNBT2OBRT65N6OEZQWD4OSH6PI', 'price': 80000, 'amount': 1, 'execution': 'taker', 'type': 'sell', }); ``` # <a name="both"></a> šŸ” Maker/Taker Order Maker/Taker will first check the {@tutorial Orderbook} for existing orders that match the current order. ### Buy Order ```javascript const res = await api.placeOrder({ 'asset': { 'id': 15322902, 'decimals': 6, }, 'address': 'WYWRYK42XADLY3O62N52BOLT27DMPRA3WNBT2OBRT65N6OEZQWD4OSH6PI', 'price': 3.22, 'amount': 1, 'execution': 'both', 'type': 'buy', }); ``` ### Sell Order ```javascript const res = await api.placeOrder({ 'asset': { 'id': 15322902, 'decimals': 6, }, 'address': 'WYWRYK42XADLY3O62N52BOLT27DMPRA3WNBT2OBRT65N6OEZQWD4OSH6PI', 'price': 80000, 'amount': 1, 'execution': 'both', 'type': 'sell', }); ``` # 🧮 Advanced ### šŸ”ØšŸ”©šŸŖ“ &nbsp;&nbsp; There are multiple ways to place an order using our SDK. &nbsp;&nbsp; šŸ”§šŸŖ›ā› &nbsp;&nbsp; šŸŽ“ &nbsp;&nbsp; If you are curious about the internal processes of placing an order and how they relate to the different execution types, the [Structure Module]{@link module:order/structure} is a great place to start šŸ‘·ā€ā™€ļøšŸ‘· &nbsp;&nbsp;Some people find it clunky to lug around a toolbox if they only need one or two tools šŸ‘·ā€ā™€ļøšŸ‘· &nbsp;&nbsp;If that sounds like you, we recommend checking out [Buy]{@link module:txns/buy} & [Sell]{@link module:txns/sell} modules to get a better sense of what methods fit your use case