Skip to content

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:

FieldTypeRequiredDescription
typestringYesOrder type: "market", "limit", "twap", "stop", "stop-loss"
chainstringYesChain identifier (e.g. "ethereum")
targetAssetstringYesAsset to trade from (contract address)
contraAssetstringYesAsset to trade to (contract address)
qtystringYesAmount to trade
orderSidestringYesTrade direction: "buy" or "sell"
slippageTolerancestringYesMaximum allowed slippage (e.g. "0.01" for 1%)
maxPriceImpactstringYesMaximum 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:

FieldTypeRequiredDescription
limitPricestringYesTarget price for the limit order
limitNotionalPricestringNoOptional notional price in quote asset
limitNotionalAssetstringNoOptional 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:

FieldTypeRequiredDescription
durationSecondsnumberYesDuration of the TWAP order in seconds
targetTWAPBucketsnumberNoOptional 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.

FieldTypeRequiredDescription
orderSidestringYesMust be "buy" for stop-buy orders
triggerTypestringYes"upper" (buy when price goes up) or "lower" (buy when price goes down)
triggerobjectYesPrice trigger condition
limitobjectNoOptional 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
  }
}
Buy USDC when ETH price drops below $1700 (stop-buy with lower trigger):
{
  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
  }
}
Stop-buy with limit price (triggered at $158, but won't pay more than $160):
{
  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
  }
}