Get Quote
Retrieves a quote for trading between two assets. The request body varies based on the order type.
Request URL
GET https://ddp.definitive.fi/v2/portfolio/trade/quote
Example
Here's a simple market order example:
const json = await AuthHelpers.signAndSend({
path: "/v2/portfolio/trade/quote",
method: "POST",
body: {
type: "market",
chain: "ethereum",
targetAsset: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", // USDC
contraAsset: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", // WETH
qty: "1000",
orderSide: "buy",
slippageTolerance: "0.01",
maxPriceImpact: "0.01",
},
apiKey: process.env.API_KEY,
apiSecret: process.env.API_SECRET,
});
console.log(json);
Base Fields
All order types require these base fields:
Field | Type | Required | Description |
---|---|---|---|
type | string | Yes | Order type: "market", "limit", "twap", "stop", "stop-loss" |
chain | string | Yes | Chain identifier (e.g. "ethereum") |
targetAsset | string | Yes | Asset to trade from (contract address) |
contraAsset | string | Yes | Asset to trade to (contract address) |
qty | string | Yes | Amount to trade |
orderSide | string | Yes | Trade direction: "buy" or "sell" |
slippageTolerance | string | Yes | Maximum allowed slippage (e.g. "0.01" for 1%) |
maxPriceImpact | string | Yes | Maximum allowed price impact (e.g. "0.01" for 1%) |
Market Order
Simplest order type with no additional fields beyond the base fields.
{
type: "market",
chain: "ethereum",
targetAsset: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
contraAsset: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
qty: "1000",
orderSide: "buy",
slippageTolerance: "0.01",
maxPriceImpact: "0.01"
}
Limit Order
Limit orders require additional price-related fields:
Field | Type | Required | Description |
---|---|---|---|
limitPrice | string | Yes | Target price for the limit order |
limitNotionalPrice | string | No | Optional notional price in quote asset |
limitNotionalAsset | string | No | Optional asset for notional price |
{
type: "limit",
chain: "ethereum",
targetAsset: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
contraAsset: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
qty: "1000",
orderSide: "buy",
slippageTolerance: "0.01",
maxPriceImpact: "0.01",
limitPrice: "1800.00",
limitNotionalPrice: "1.00",
limitNotionalAsset: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"
}
TWAP Order
Time-Weighted Average Price (TWAP) orders require duration settings:
Field | Type | Required | Description |
---|---|---|---|
durationSeconds | number | Yes | Duration of the TWAP order in seconds |
targetTWAPBuckets | number | No | Optional number of TWAP buckets |
{
type: "twap",
chain: "ethereum",
targetAsset: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
contraAsset: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
qty: "1000",
orderSide: "buy",
slippageTolerance: "0.01",
maxPriceImpact: "0.01",
durationSeconds: 3600,
targetTWAPBuckets: 6
}
Stop-Buy Order
Stop-buy orders are triggered when the price of an asset reaches a specific threshold, allowing you to buy an asset when it breaks above a certain price level.
Field | Type | Required | Description |
---|---|---|---|
orderSide | string | Yes | Must be "buy" for stop-buy orders |
triggerType | string | Yes | "upper" (buy when price goes up) or "lower" (buy when price goes down) |
trigger | object | Yes | Price trigger condition |
limit | object | No | Optional limit price for the order |
The trigger
and limit
objects have this structure:
type TriggerOrLimit = {
price: string; // The trigger/limit price
isNotional: boolean; // Whether price is notional (default: false)
};
Stop-Buy Examples
Buy SOL when price breaks above $158 (stop-buy with upper trigger):{
type: "stop",
chain: "solana",
targetAsset: "So11111111111111111111111111111111111111112", // SOL
contraAsset: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", // USDC
qty: "0.02",
orderSide: "buy",
slippageTolerance: "0.01",
maxPriceImpact: "0.01",
triggerType: "upper",
trigger: {
price: "158.00",
isNotional: false
}
}
{
type: "stop",
chain: "ethereum",
targetAsset: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", // USDC
contraAsset: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", // WETH
qty: "1000",
orderSide: "buy",
slippageTolerance: "0.01",
maxPriceImpact: "0.01",
triggerType: "lower",
trigger: {
price: "1700.00",
isNotional: false
}
}
{
type: "stop",
chain: "solana",
targetAsset: "So11111111111111111111111111111111111111112", // SOL
contraAsset: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", // USDC
qty: "0.02",
orderSide: "buy",
slippageTolerance: "0.01",
maxPriceImpact: "0.01",
triggerType: "upper",
trigger: {
price: "158.00",
isNotional: false
},
limit: {
price: "160.00",
isNotional: false
}
}
Trigger Types Explained
-
"upper"
: Triggers when price goes above the trigger price (breakout buying)- Use case: Buy when an asset breaks resistance or shows upward momentum
- Example: Buy SOL when it breaks above $158 (expecting continued upward movement)
-
"lower"
: Triggers when price goes below the trigger price (dip buying)- Use case: Buy when an asset falls to a support level or shows a buying opportunity
- Example: Buy ETH when it drops below $1700 (buying the dip)
## Response
The response format is the same for all order types:
```ts
{
quote: {
type: string, // Same as request type
chain: string,
targetAsset: string,
contraAsset: string,
qty: string,
orderSide: string,
quoteId: string,
quotedAmountOut: string,
quotedPriceImpact: string,
maxPriceImpact: string,
slippageTolerance: string,
// Additional fields matching the request type
...orderTypeSpecificFields
},
metadata: {
toNotional: string,
fromNotional: string,
estimatedPriceImpact: string,
estimatedFee: string,
estimatedFeeNotional: string,
buyAmount: string
}
}