curl --request POST \
--url https://tx-builder-testnet.avantisfi.com/v2/trade/open-coin \
--header 'Content-Type: application/json' \
--data '
{
"trader": "<string>",
"collateralUsdc": "<string>",
"leverage": "<string>",
"coinExposure": "<string>",
"pairIndex": 1,
"pair": "<string>",
"delegate": "<string>",
"orderType": "market",
"slippagePercent": "1",
"openPrice": "<string>",
"takeProfit": "<string>",
"stopLoss": "<string>",
"executionFeeWei": "<string>",
"skipValidation": false,
"minLeverage": "<string>",
"maxLeverage": "<string>"
}
'import requests
url = "https://tx-builder-testnet.avantisfi.com/v2/trade/open-coin"
payload = {
"trader": "<string>",
"collateralUsdc": "<string>",
"leverage": "<string>",
"coinExposure": "<string>",
"pairIndex": 1,
"pair": "<string>",
"delegate": "<string>",
"orderType": "market",
"slippagePercent": "1",
"openPrice": "<string>",
"takeProfit": "<string>",
"stopLoss": "<string>",
"executionFeeWei": "<string>",
"skipValidation": False,
"minLeverage": "<string>",
"maxLeverage": "<string>"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
trader: '<string>',
collateralUsdc: '<string>',
leverage: '<string>',
coinExposure: '<string>',
pairIndex: 1,
pair: '<string>',
delegate: '<string>',
orderType: 'market',
slippagePercent: '1',
openPrice: '<string>',
takeProfit: '<string>',
stopLoss: '<string>',
executionFeeWei: '<string>',
skipValidation: false,
minLeverage: '<string>',
maxLeverage: '<string>'
})
};
fetch('https://tx-builder-testnet.avantisfi.com/v2/trade/open-coin', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://tx-builder-testnet.avantisfi.com/v2/trade/open-coin",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'trader' => '<string>',
'collateralUsdc' => '<string>',
'leverage' => '<string>',
'coinExposure' => '<string>',
'pairIndex' => 1,
'pair' => '<string>',
'delegate' => '<string>',
'orderType' => 'market',
'slippagePercent' => '1',
'openPrice' => '<string>',
'takeProfit' => '<string>',
'stopLoss' => '<string>',
'executionFeeWei' => '<string>',
'skipValidation' => false,
'minLeverage' => '<string>',
'maxLeverage' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://tx-builder-testnet.avantisfi.com/v2/trade/open-coin"
payload := strings.NewReader("{\n \"trader\": \"<string>\",\n \"collateralUsdc\": \"<string>\",\n \"leverage\": \"<string>\",\n \"coinExposure\": \"<string>\",\n \"pairIndex\": 1,\n \"pair\": \"<string>\",\n \"delegate\": \"<string>\",\n \"orderType\": \"market\",\n \"slippagePercent\": \"1\",\n \"openPrice\": \"<string>\",\n \"takeProfit\": \"<string>\",\n \"stopLoss\": \"<string>\",\n \"executionFeeWei\": \"<string>\",\n \"skipValidation\": false,\n \"minLeverage\": \"<string>\",\n \"maxLeverage\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://tx-builder-testnet.avantisfi.com/v2/trade/open-coin")
.header("Content-Type", "application/json")
.body("{\n \"trader\": \"<string>\",\n \"collateralUsdc\": \"<string>\",\n \"leverage\": \"<string>\",\n \"coinExposure\": \"<string>\",\n \"pairIndex\": 1,\n \"pair\": \"<string>\",\n \"delegate\": \"<string>\",\n \"orderType\": \"market\",\n \"slippagePercent\": \"1\",\n \"openPrice\": \"<string>\",\n \"takeProfit\": \"<string>\",\n \"stopLoss\": \"<string>\",\n \"executionFeeWei\": \"<string>\",\n \"skipValidation\": false,\n \"minLeverage\": \"<string>\",\n \"maxLeverage\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://tx-builder-testnet.avantisfi.com/v2/trade/open-coin")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"trader\": \"<string>\",\n \"collateralUsdc\": \"<string>\",\n \"leverage\": \"<string>\",\n \"coinExposure\": \"<string>\",\n \"pairIndex\": 1,\n \"pair\": \"<string>\",\n \"delegate\": \"<string>\",\n \"orderType\": \"market\",\n \"slippagePercent\": \"1\",\n \"openPrice\": \"<string>\",\n \"takeProfit\": \"<string>\",\n \"stopLoss\": \"<string>\",\n \"executionFeeWei\": \"<string>\",\n \"skipValidation\": false,\n \"minLeverage\": \"<string>\",\n \"maxLeverage\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"ok": true,
"data": {
"to": "0x0000000000000000000000000000000000000000",
"from": "0x0000000000000000000000000000000000000000",
"data": "<string>",
"value": "0x0",
"chainId": 123,
"description": "<string>",
"meta": {
"pair": "<string>",
"pairIndex": 123,
"delegated": true,
"executionFeeWei": "<string>",
"orderType": "<string>",
"isPnl": true,
"isLong": true,
"collateralUsdc": "<string>",
"leverage": "<string>",
"slippagePercent": "<string>",
"openPrice": 123,
"takeProfit": "<string>",
"stopLoss": "<string>",
"validation": {
"positionSizeUsdc": 123,
"pairAvailableUsdc": 123,
"groupAvailableUsdc": 123,
"availableUsdc": 123,
"minLeverage": 123,
"maxLeverage": 123,
"minPositionUsdc": 123,
"isPnl": true,
"marketOpen": true,
"nextOpenSec": 123,
"nextCloseSec": 123
},
"coinExposure": "<string>",
"minLeverage": "<string>",
"maxLeverage": "<string>"
}
}
}{
"ok": false,
"error": {
"code": "BAD_REQUEST",
"message": "<string>",
"details": "<unknown>"
}
}Build an open-position transaction targeting a fixed base-asset exposure
Like /v2/trade/open, but the fill targets an exact exposure in base-asset units (e.g. exactly 0.5 ETH) instead of a USD notional; the fill leverage floats within [minLeverage, maxLeverage]. Only market and market_pnl order types are supported.
curl --request POST \
--url https://tx-builder-testnet.avantisfi.com/v2/trade/open-coin \
--header 'Content-Type: application/json' \
--data '
{
"trader": "<string>",
"collateralUsdc": "<string>",
"leverage": "<string>",
"coinExposure": "<string>",
"pairIndex": 1,
"pair": "<string>",
"delegate": "<string>",
"orderType": "market",
"slippagePercent": "1",
"openPrice": "<string>",
"takeProfit": "<string>",
"stopLoss": "<string>",
"executionFeeWei": "<string>",
"skipValidation": false,
"minLeverage": "<string>",
"maxLeverage": "<string>"
}
'import requests
url = "https://tx-builder-testnet.avantisfi.com/v2/trade/open-coin"
payload = {
"trader": "<string>",
"collateralUsdc": "<string>",
"leverage": "<string>",
"coinExposure": "<string>",
"pairIndex": 1,
"pair": "<string>",
"delegate": "<string>",
"orderType": "market",
"slippagePercent": "1",
"openPrice": "<string>",
"takeProfit": "<string>",
"stopLoss": "<string>",
"executionFeeWei": "<string>",
"skipValidation": False,
"minLeverage": "<string>",
"maxLeverage": "<string>"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
trader: '<string>',
collateralUsdc: '<string>',
leverage: '<string>',
coinExposure: '<string>',
pairIndex: 1,
pair: '<string>',
delegate: '<string>',
orderType: 'market',
slippagePercent: '1',
openPrice: '<string>',
takeProfit: '<string>',
stopLoss: '<string>',
executionFeeWei: '<string>',
skipValidation: false,
minLeverage: '<string>',
maxLeverage: '<string>'
})
};
fetch('https://tx-builder-testnet.avantisfi.com/v2/trade/open-coin', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://tx-builder-testnet.avantisfi.com/v2/trade/open-coin",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'trader' => '<string>',
'collateralUsdc' => '<string>',
'leverage' => '<string>',
'coinExposure' => '<string>',
'pairIndex' => 1,
'pair' => '<string>',
'delegate' => '<string>',
'orderType' => 'market',
'slippagePercent' => '1',
'openPrice' => '<string>',
'takeProfit' => '<string>',
'stopLoss' => '<string>',
'executionFeeWei' => '<string>',
'skipValidation' => false,
'minLeverage' => '<string>',
'maxLeverage' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://tx-builder-testnet.avantisfi.com/v2/trade/open-coin"
payload := strings.NewReader("{\n \"trader\": \"<string>\",\n \"collateralUsdc\": \"<string>\",\n \"leverage\": \"<string>\",\n \"coinExposure\": \"<string>\",\n \"pairIndex\": 1,\n \"pair\": \"<string>\",\n \"delegate\": \"<string>\",\n \"orderType\": \"market\",\n \"slippagePercent\": \"1\",\n \"openPrice\": \"<string>\",\n \"takeProfit\": \"<string>\",\n \"stopLoss\": \"<string>\",\n \"executionFeeWei\": \"<string>\",\n \"skipValidation\": false,\n \"minLeverage\": \"<string>\",\n \"maxLeverage\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://tx-builder-testnet.avantisfi.com/v2/trade/open-coin")
.header("Content-Type", "application/json")
.body("{\n \"trader\": \"<string>\",\n \"collateralUsdc\": \"<string>\",\n \"leverage\": \"<string>\",\n \"coinExposure\": \"<string>\",\n \"pairIndex\": 1,\n \"pair\": \"<string>\",\n \"delegate\": \"<string>\",\n \"orderType\": \"market\",\n \"slippagePercent\": \"1\",\n \"openPrice\": \"<string>\",\n \"takeProfit\": \"<string>\",\n \"stopLoss\": \"<string>\",\n \"executionFeeWei\": \"<string>\",\n \"skipValidation\": false,\n \"minLeverage\": \"<string>\",\n \"maxLeverage\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://tx-builder-testnet.avantisfi.com/v2/trade/open-coin")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"trader\": \"<string>\",\n \"collateralUsdc\": \"<string>\",\n \"leverage\": \"<string>\",\n \"coinExposure\": \"<string>\",\n \"pairIndex\": 1,\n \"pair\": \"<string>\",\n \"delegate\": \"<string>\",\n \"orderType\": \"market\",\n \"slippagePercent\": \"1\",\n \"openPrice\": \"<string>\",\n \"takeProfit\": \"<string>\",\n \"stopLoss\": \"<string>\",\n \"executionFeeWei\": \"<string>\",\n \"skipValidation\": false,\n \"minLeverage\": \"<string>\",\n \"maxLeverage\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"ok": true,
"data": {
"to": "0x0000000000000000000000000000000000000000",
"from": "0x0000000000000000000000000000000000000000",
"data": "<string>",
"value": "0x0",
"chainId": 123,
"description": "<string>",
"meta": {
"pair": "<string>",
"pairIndex": 123,
"delegated": true,
"executionFeeWei": "<string>",
"orderType": "<string>",
"isPnl": true,
"isLong": true,
"collateralUsdc": "<string>",
"leverage": "<string>",
"slippagePercent": "<string>",
"openPrice": 123,
"takeProfit": "<string>",
"stopLoss": "<string>",
"validation": {
"positionSizeUsdc": 123,
"pairAvailableUsdc": 123,
"groupAvailableUsdc": 123,
"availableUsdc": 123,
"minLeverage": 123,
"maxLeverage": 123,
"minPositionUsdc": 123,
"isPnl": true,
"marketOpen": true,
"nextOpenSec": 123,
"nextCloseSec": 123
},
"coinExposure": "<string>",
"minLeverage": "<string>",
"maxLeverage": "<string>"
}
}
}{
"ok": false,
"error": {
"code": "BAD_REQUEST",
"message": "<string>",
"details": "<unknown>"
}
}Body
The trader (position owner). USDC collateral is pulled from and paid out to this address.
Position direction: long or short.
long, short Collateral (margin) in USDC, human units — e.g. 100 = 100 USDC. Position size = collateral × leverage.
Leverage as a plain multiplier (10 = 10x).
Position exposure in base-asset units (e.g. 0.5 = 0.5 ETH on ETH/USD).
Pair index (alternative to pair).
x >= 0Pair symbol, e.g. ETH/USD (separators /, -, _ accepted; case-insensitive).
1Optional pre-authorized delegate. When set, the call is wrapped in delegatedAction(trader, …) and from becomes this address — the delegate signs the transaction and pays gas. Register one via /v2/delegate/set.
Open order type: market (immediate), limit / stop_limit (queued at openPrice), or market_pnl (zero-fee, profit-share on close).
market, stop_limit, limit, market_pnl, market_zero_fee Max slippage in percent (1 = 1%).
Entry price in USD. Market orders: optional override, resolved from the live price feed when omitted. Limit / stop-limit orders: the trigger price (required).
Take-profit price in USD. 0 or omitted = no take-profit (0 also removes an existing one on updates).
Stop-loss price in USD. 0 or omitted = no stop-loss (0 also removes an existing one on updates).
ETH (wei) attached as msg.value and forwarded to the Avantis operator that fulfills the order. Defaults to the service value shown in /v2/meta → defaults.executionFeeWei.
Skip server-side pre-trade validation (listing, min position, leverage bounds, liquidity, market hours) and just encode the call. The chain still enforces all limits.
Lowest fill leverage you accept; defaults to the pair minimum.
Highest fill leverage you accept; defaults to the pair maximum.
Response
Success envelope: ok is true and data carries the payload documented below.