> For the complete documentation index, see [llms.txt](https://dexible.gitbook.io/dexible-sdk-v1.0/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dexible.gitbook.io/dexible-sdk-v1.0/policy-overview/custom-algos.md).

# Custom Algos

Since Dexible views algos as a name plus a collection of policies, you have tremendous flexibility over order execution. Every algo requires the gasPolicy and slippage policies. Beyond that, the Limit, StopLimit, and TWAP algos have specific policy requirements as well (namely, LimitPrice, StopPrice, and BoundedDelay). If you truly want to start from scratch, you can apply policies to a Market algo to express to Dexible how you want the order to execute.

### PriceRange Market Order

Suppose you want to simply specify a price range for an order. Unlike limit, you want to execute if the price is above or below a certain price point (often called price 'bands'). Here is what you can do:

```
import {Algos, Price, Policies, SDK} from 'dexible-sdk';

const {GasCost, Slippage, PriceBounds} = Policies;

const main = async () => {
   //create SDK instance since we'll need it later
   let sdk = new SDK(...);
   
   let tokenIn = await sdk.token.lookup(...);
   let tokenOut = await sdk.token.lookup(...);
   
   let policies = [
      new GasCost({
         gasType: sdk.gasPolicyTypes.RELATIVE,
         deviation: 0
      }),
      new Slippage({
         amount: .5
      }),
      new PriceBounds({
         basePrice: new Price({
            inToken: tokenIn,
            outToken: tokenOut,
            inUnits: 1,
            outUnits: 2500
         }),
         lowerBoundPercent: 2,
         upperBoundPercent: 2 
      })
   ];
   
   let algo = new Algos.Market({
      //maxRounds: 10,
      policies
   });
}

main();
```

Even though this is labeled as a "market" order, it will not behave like a market order because we've added specific policies that tell Dexible how to execute. It will restrict the execution to a specific price band.

### Order Matters

The order of the policies array is the exact order of evaluation within Dexible's infrastructure. The first non-passing policy will stop evaluation for the order. In certain cases, the policy will force a cancel. We recommend putting those policies ahead of others to short circuit evaluation.

### Extending Policies

We will add more policy types as we expand Dexible. If you find that you need a policy that is missing, please contact us and we will evaluate your use case and add policies accordingly.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://dexible.gitbook.io/dexible-sdk-v1.0/policy-overview/custom-algos.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
