const res = await fetch('https://app.trdrs.co/api/venues/{venueId}/hedging-policies/{hedgingPolicyId}/script', {
method: 'POST',
headers: {
'content-type': 'application/json',
Authorization: `Bearer ${process.env.TRDRS_VENUE_KEY}`,
"Idempotency-Key": "example-request-1",
},
body: JSON.stringify({
"source": "import type { HedgeAnswer, HedgeInput } from '@trdrs/script-sdk'\n\n// Hold each hedge until it is off by more than START dollars, then bring it to within TARGET dollars.\nconst START = 1_000_000\nconst TARGET = 400_000\n\nexport default function hedge(input: HedgeInput): HedgeAnswer {\n const hedges: Record<string, number> = {}\n for (const market of input.instruments) {\n if (!market.hedgeable) continue\n const has = market.held + market.pending\n // Where the policy can't size it now, keep what the hedge holds.\n hedges[market.instrumentId] = has\n if (market.price === null || market.policyTarget === null) continue\n const target = market.policyTarget\n const off = target - has\n // A net that calls for no hedge closes it at once.\n if (target === 0 || off === 0) { hedges[market.instrumentId] = target; continue }\n const perUnit = Math.abs(market.price) * market.contractMultiplier\n if (Math.abs(off) * perUnit <= START) continue\n // What is left off once the order goes: TARGET dollars, in whole steps.\n const left = Math.floor(TARGET / perUnit / market.step) * market.step\n if (left >= Math.abs(off)) continue\n hedges[market.instrumentId] = off > 0 ? target - left : target + left\n }\n return { hedges }\n}\n",
"resultsDays": [
30
],
"expectedRevision": null
}),
})
const data = await res.json()curl -X POST 'https://app.trdrs.co/api/venues/{venueId}/hedging-policies/{hedgingPolicyId}/script' \
-H "Authorization: Bearer $TRDRS_VENUE_KEY" \
-H 'Idempotency-Key: example-request-1' \
-H 'content-type: application/json' \
-d '{"source":"import type { HedgeAnswer, HedgeInput } from '@trdrs/script-sdk'\n\n// Hold each hedge until it is off by more than START dollars, then bring it to within TARGET dollars.\nconst START = 1_000_000\nconst TARGET = 400_000\n\nexport default function hedge(input: HedgeInput): HedgeAnswer {\n const hedges: Record<string, number> = {}\n for (const market of input.instruments) {\n if (!market.hedgeable) continue\n const has = market.held + market.pending\n // Where the policy can't size it now, keep what the hedge holds.\n hedges[market.instrumentId] = has\n if (market.price === null || market.policyTarget === null) continue\n const target = market.policyTarget\n const off = target - has\n // A net that calls for no hedge closes it at once.\n if (target === 0 || off === 0) { hedges[market.instrumentId] = target; continue }\n const perUnit = Math.abs(market.price) * market.contractMultiplier\n if (Math.abs(off) * perUnit <= START) continue\n // What is left off once the order goes: TARGET dollars, in whole steps.\n const left = Math.floor(TARGET / perUnit / market.step) * market.step\n if (left >= Math.abs(off)) continue\n hedges[market.instrumentId] = off > 0 ? target - left : target + left\n }\n return { hedges }\n}\n","resultsDays":[30],"expectedRevision":null}'import requests
url = "https://app.trdrs.co/api/venues/{venueId}/hedging-policies/{hedgingPolicyId}/script"
payload = {
"source": "import type { HedgeAnswer, HedgeInput } from '@trdrs/script-sdk'
// Hold each hedge until it is off by more than START dollars, then bring it to within TARGET dollars.
const START = 1_000_000
const TARGET = 400_000
export default function hedge(input: HedgeInput): HedgeAnswer {
const hedges: Record<string, number> = {}
for (const market of input.instruments) {
if (!market.hedgeable) continue
const has = market.held + market.pending
// Where the policy can't size it now, keep what the hedge holds.
hedges[market.instrumentId] = has
if (market.price === null || market.policyTarget === null) continue
const target = market.policyTarget
const off = target - has
// A net that calls for no hedge closes it at once.
if (target === 0 || off === 0) { hedges[market.instrumentId] = target; continue }
const perUnit = Math.abs(market.price) * market.contractMultiplier
if (Math.abs(off) * perUnit <= START) continue
// What is left off once the order goes: TARGET dollars, in whole steps.
const left = Math.floor(TARGET / perUnit / market.step) * market.step
if (left >= Math.abs(off)) continue
hedges[market.instrumentId] = off > 0 ? target - left : target + left
}
return { hedges }
}
",
"resultsDays": [30],
"expectedRevision": None
}
headers = {
"Idempotency-Key": "<idempotency-key>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://app.trdrs.co/api/venues/{venueId}/hedging-policies/{hedgingPolicyId}/script",
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([
'source' => 'import type { HedgeAnswer, HedgeInput } from \'@trdrs/script-sdk\'
// Hold each hedge until it is off by more than START dollars, then bring it to within TARGET dollars.
const START = 1_000_000
const TARGET = 400_000
export default function hedge(input: HedgeInput): HedgeAnswer {
const hedges: Record<string, number> = {}
for (const market of input.instruments) {
if (!market.hedgeable) continue
const has = market.held + market.pending
// Where the policy can\'t size it now, keep what the hedge holds.
hedges[market.instrumentId] = has
if (market.price === null || market.policyTarget === null) continue
const target = market.policyTarget
const off = target - has
// A net that calls for no hedge closes it at once.
if (target === 0 || off === 0) { hedges[market.instrumentId] = target; continue }
const perUnit = Math.abs(market.price) * market.contractMultiplier
if (Math.abs(off) * perUnit <= START) continue
// What is left off once the order goes: TARGET dollars, in whole steps.
const left = Math.floor(TARGET / perUnit / market.step) * market.step
if (left >= Math.abs(off)) continue
hedges[market.instrumentId] = off > 0 ? target - left : target + left
}
return { hedges }
}
',
'resultsDays' => [
30
],
'expectedRevision' => null
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json",
"Idempotency-Key: <idempotency-key>"
],
]);
$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://app.trdrs.co/api/venues/{venueId}/hedging-policies/{hedgingPolicyId}/script"
payload := strings.NewReader("{\n \"source\": \"import type { HedgeAnswer, HedgeInput } from '@trdrs/script-sdk'\\n\\n// Hold each hedge until it is off by more than START dollars, then bring it to within TARGET dollars.\\nconst START = 1_000_000\\nconst TARGET = 400_000\\n\\nexport default function hedge(input: HedgeInput): HedgeAnswer {\\n const hedges: Record<string, number> = {}\\n for (const market of input.instruments) {\\n if (!market.hedgeable) continue\\n const has = market.held + market.pending\\n // Where the policy can't size it now, keep what the hedge holds.\\n hedges[market.instrumentId] = has\\n if (market.price === null || market.policyTarget === null) continue\\n const target = market.policyTarget\\n const off = target - has\\n // A net that calls for no hedge closes it at once.\\n if (target === 0 || off === 0) { hedges[market.instrumentId] = target; continue }\\n const perUnit = Math.abs(market.price) * market.contractMultiplier\\n if (Math.abs(off) * perUnit <= START) continue\\n // What is left off once the order goes: TARGET dollars, in whole steps.\\n const left = Math.floor(TARGET / perUnit / market.step) * market.step\\n if (left >= Math.abs(off)) continue\\n hedges[market.instrumentId] = off > 0 ? target - left : target + left\\n }\\n return { hedges }\\n}\\n\",\n \"resultsDays\": [\n 30\n ],\n \"expectedRevision\": null\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Idempotency-Key", "<idempotency-key>")
req.Header.Add("Authorization", "Bearer <token>")
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://app.trdrs.co/api/venues/{venueId}/hedging-policies/{hedgingPolicyId}/script")
.header("Idempotency-Key", "<idempotency-key>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"source\": \"import type { HedgeAnswer, HedgeInput } from '@trdrs/script-sdk'\\n\\n// Hold each hedge until it is off by more than START dollars, then bring it to within TARGET dollars.\\nconst START = 1_000_000\\nconst TARGET = 400_000\\n\\nexport default function hedge(input: HedgeInput): HedgeAnswer {\\n const hedges: Record<string, number> = {}\\n for (const market of input.instruments) {\\n if (!market.hedgeable) continue\\n const has = market.held + market.pending\\n // Where the policy can't size it now, keep what the hedge holds.\\n hedges[market.instrumentId] = has\\n if (market.price === null || market.policyTarget === null) continue\\n const target = market.policyTarget\\n const off = target - has\\n // A net that calls for no hedge closes it at once.\\n if (target === 0 || off === 0) { hedges[market.instrumentId] = target; continue }\\n const perUnit = Math.abs(market.price) * market.contractMultiplier\\n if (Math.abs(off) * perUnit <= START) continue\\n // What is left off once the order goes: TARGET dollars, in whole steps.\\n const left = Math.floor(TARGET / perUnit / market.step) * market.step\\n if (left >= Math.abs(off)) continue\\n hedges[market.instrumentId] = off > 0 ? target - left : target + left\\n }\\n return { hedges }\\n}\\n\",\n \"resultsDays\": [\n 30\n ],\n \"expectedRevision\": null\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://app.trdrs.co/api/venues/{venueId}/hedging-policies/{hedgingPolicyId}/script")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Idempotency-Key"] = '<idempotency-key>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"source\": \"import type { HedgeAnswer, HedgeInput } from '@trdrs/script-sdk'\\n\\n// Hold each hedge until it is off by more than START dollars, then bring it to within TARGET dollars.\\nconst START = 1_000_000\\nconst TARGET = 400_000\\n\\nexport default function hedge(input: HedgeInput): HedgeAnswer {\\n const hedges: Record<string, number> = {}\\n for (const market of input.instruments) {\\n if (!market.hedgeable) continue\\n const has = market.held + market.pending\\n // Where the policy can't size it now, keep what the hedge holds.\\n hedges[market.instrumentId] = has\\n if (market.price === null || market.policyTarget === null) continue\\n const target = market.policyTarget\\n const off = target - has\\n // A net that calls for no hedge closes it at once.\\n if (target === 0 || off === 0) { hedges[market.instrumentId] = target; continue }\\n const perUnit = Math.abs(market.price) * market.contractMultiplier\\n if (Math.abs(off) * perUnit <= START) continue\\n // What is left off once the order goes: TARGET dollars, in whole steps.\\n const left = Math.floor(TARGET / perUnit / market.step) * market.step\\n if (left >= Math.abs(off)) continue\\n hedges[market.instrumentId] = off > 0 ? target - left : target + left\\n }\\n return { hedges }\\n}\\n\",\n \"resultsDays\": [\n 30\n ],\n \"expectedRevision\": null\n}"
response = http.request(request)
puts response.read_body{
"script": {
"hedgingPolicyId": "00000000-0000-0000-0000-000000000001",
"mode": "watch",
"revision": 3,
"version": {
"id": "00000000-0000-0000-0000-000000000005",
"version": 2,
"sdkVersion": "0.1.0",
"resultsDays": [
30
],
"createdBy": "user-owner",
"createdAt": "2026-11-13T09:00:00.000Z",
"running": true,
"source": "import type { HedgeAnswer, HedgeInput } from '@trdrs/script-sdk'\n\n// Hold each hedge until it is off by more than START dollars, then bring it to within TARGET dollars.\nconst START = 1_000_000\nconst TARGET = 400_000\n\nexport default function hedge(input: HedgeInput): HedgeAnswer {\n const hedges: Record<string, number> = {}\n for (const market of input.instruments) {\n if (!market.hedgeable) continue\n const has = market.held + market.pending\n // Where the policy can't size it now, keep what the hedge holds.\n hedges[market.instrumentId] = has\n if (market.price === null || market.policyTarget === null) continue\n const target = market.policyTarget\n const off = target - has\n // A net that calls for no hedge closes it at once.\n if (target === 0 || off === 0) { hedges[market.instrumentId] = target; continue }\n const perUnit = Math.abs(market.price) * market.contractMultiplier\n if (Math.abs(off) * perUnit <= START) continue\n // What is left off once the order goes: TARGET dollars, in whole steps.\n const left = Math.floor(TARGET / perUnit / market.step) * market.step\n if (left >= Math.abs(off)) continue\n hedges[market.instrumentId] = off > 0 ? target - left : target + left\n }\n return { hedges }\n}\n"
},
"changedBy": "user-owner",
"changedAt": "2026-11-13T09:05:00.000Z",
"failuresInARow": 0,
"lastFailureAt": null,
"lastFailureReason": null
}
}{
"error": "invalid_instrument"
}{
"error": "invalid_instrument"
}{
"error": "invalid_instrument"
}{
"error": "invalid_instrument"
}{
"error": "invalid_instrument"
}{
"error": "invalid_instrument"
}{
"error": "invalid_instrument"
}{
"error": "invalid_instrument"
}Save a hedging policy's script
Compiles source and saves it as the next version of the policy’s script, which the policy runs from now in the mode it has: off for a first save, so a new script trades nothing until you set its mode. A source that doesn’t compile is refused, and nothing is saved. Send expectedRevision null for a policy with no script yet, and the revision you read after. Where the script is on and the policy is active, saving also needs hedge:execute, as changing an active policy’s terms does. resultsDays are the windows of whole UTC days whose results the script reads for each account, at most 4, each from 1 to 365; [30] where you send none. Required scope: hedge:manage. Preview: served on the sandbox to every venue, and production availability is arranged when a venue qualifies. Trading API keys and pre-registration keys do not authorize these routes.
const res = await fetch('https://app.trdrs.co/api/venues/{venueId}/hedging-policies/{hedgingPolicyId}/script', {
method: 'POST',
headers: {
'content-type': 'application/json',
Authorization: `Bearer ${process.env.TRDRS_VENUE_KEY}`,
"Idempotency-Key": "example-request-1",
},
body: JSON.stringify({
"source": "import type { HedgeAnswer, HedgeInput } from '@trdrs/script-sdk'\n\n// Hold each hedge until it is off by more than START dollars, then bring it to within TARGET dollars.\nconst START = 1_000_000\nconst TARGET = 400_000\n\nexport default function hedge(input: HedgeInput): HedgeAnswer {\n const hedges: Record<string, number> = {}\n for (const market of input.instruments) {\n if (!market.hedgeable) continue\n const has = market.held + market.pending\n // Where the policy can't size it now, keep what the hedge holds.\n hedges[market.instrumentId] = has\n if (market.price === null || market.policyTarget === null) continue\n const target = market.policyTarget\n const off = target - has\n // A net that calls for no hedge closes it at once.\n if (target === 0 || off === 0) { hedges[market.instrumentId] = target; continue }\n const perUnit = Math.abs(market.price) * market.contractMultiplier\n if (Math.abs(off) * perUnit <= START) continue\n // What is left off once the order goes: TARGET dollars, in whole steps.\n const left = Math.floor(TARGET / perUnit / market.step) * market.step\n if (left >= Math.abs(off)) continue\n hedges[market.instrumentId] = off > 0 ? target - left : target + left\n }\n return { hedges }\n}\n",
"resultsDays": [
30
],
"expectedRevision": null
}),
})
const data = await res.json()curl -X POST 'https://app.trdrs.co/api/venues/{venueId}/hedging-policies/{hedgingPolicyId}/script' \
-H "Authorization: Bearer $TRDRS_VENUE_KEY" \
-H 'Idempotency-Key: example-request-1' \
-H 'content-type: application/json' \
-d '{"source":"import type { HedgeAnswer, HedgeInput } from '@trdrs/script-sdk'\n\n// Hold each hedge until it is off by more than START dollars, then bring it to within TARGET dollars.\nconst START = 1_000_000\nconst TARGET = 400_000\n\nexport default function hedge(input: HedgeInput): HedgeAnswer {\n const hedges: Record<string, number> = {}\n for (const market of input.instruments) {\n if (!market.hedgeable) continue\n const has = market.held + market.pending\n // Where the policy can't size it now, keep what the hedge holds.\n hedges[market.instrumentId] = has\n if (market.price === null || market.policyTarget === null) continue\n const target = market.policyTarget\n const off = target - has\n // A net that calls for no hedge closes it at once.\n if (target === 0 || off === 0) { hedges[market.instrumentId] = target; continue }\n const perUnit = Math.abs(market.price) * market.contractMultiplier\n if (Math.abs(off) * perUnit <= START) continue\n // What is left off once the order goes: TARGET dollars, in whole steps.\n const left = Math.floor(TARGET / perUnit / market.step) * market.step\n if (left >= Math.abs(off)) continue\n hedges[market.instrumentId] = off > 0 ? target - left : target + left\n }\n return { hedges }\n}\n","resultsDays":[30],"expectedRevision":null}'import requests
url = "https://app.trdrs.co/api/venues/{venueId}/hedging-policies/{hedgingPolicyId}/script"
payload = {
"source": "import type { HedgeAnswer, HedgeInput } from '@trdrs/script-sdk'
// Hold each hedge until it is off by more than START dollars, then bring it to within TARGET dollars.
const START = 1_000_000
const TARGET = 400_000
export default function hedge(input: HedgeInput): HedgeAnswer {
const hedges: Record<string, number> = {}
for (const market of input.instruments) {
if (!market.hedgeable) continue
const has = market.held + market.pending
// Where the policy can't size it now, keep what the hedge holds.
hedges[market.instrumentId] = has
if (market.price === null || market.policyTarget === null) continue
const target = market.policyTarget
const off = target - has
// A net that calls for no hedge closes it at once.
if (target === 0 || off === 0) { hedges[market.instrumentId] = target; continue }
const perUnit = Math.abs(market.price) * market.contractMultiplier
if (Math.abs(off) * perUnit <= START) continue
// What is left off once the order goes: TARGET dollars, in whole steps.
const left = Math.floor(TARGET / perUnit / market.step) * market.step
if (left >= Math.abs(off)) continue
hedges[market.instrumentId] = off > 0 ? target - left : target + left
}
return { hedges }
}
",
"resultsDays": [30],
"expectedRevision": None
}
headers = {
"Idempotency-Key": "<idempotency-key>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://app.trdrs.co/api/venues/{venueId}/hedging-policies/{hedgingPolicyId}/script",
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([
'source' => 'import type { HedgeAnswer, HedgeInput } from \'@trdrs/script-sdk\'
// Hold each hedge until it is off by more than START dollars, then bring it to within TARGET dollars.
const START = 1_000_000
const TARGET = 400_000
export default function hedge(input: HedgeInput): HedgeAnswer {
const hedges: Record<string, number> = {}
for (const market of input.instruments) {
if (!market.hedgeable) continue
const has = market.held + market.pending
// Where the policy can\'t size it now, keep what the hedge holds.
hedges[market.instrumentId] = has
if (market.price === null || market.policyTarget === null) continue
const target = market.policyTarget
const off = target - has
// A net that calls for no hedge closes it at once.
if (target === 0 || off === 0) { hedges[market.instrumentId] = target; continue }
const perUnit = Math.abs(market.price) * market.contractMultiplier
if (Math.abs(off) * perUnit <= START) continue
// What is left off once the order goes: TARGET dollars, in whole steps.
const left = Math.floor(TARGET / perUnit / market.step) * market.step
if (left >= Math.abs(off)) continue
hedges[market.instrumentId] = off > 0 ? target - left : target + left
}
return { hedges }
}
',
'resultsDays' => [
30
],
'expectedRevision' => null
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json",
"Idempotency-Key: <idempotency-key>"
],
]);
$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://app.trdrs.co/api/venues/{venueId}/hedging-policies/{hedgingPolicyId}/script"
payload := strings.NewReader("{\n \"source\": \"import type { HedgeAnswer, HedgeInput } from '@trdrs/script-sdk'\\n\\n// Hold each hedge until it is off by more than START dollars, then bring it to within TARGET dollars.\\nconst START = 1_000_000\\nconst TARGET = 400_000\\n\\nexport default function hedge(input: HedgeInput): HedgeAnswer {\\n const hedges: Record<string, number> = {}\\n for (const market of input.instruments) {\\n if (!market.hedgeable) continue\\n const has = market.held + market.pending\\n // Where the policy can't size it now, keep what the hedge holds.\\n hedges[market.instrumentId] = has\\n if (market.price === null || market.policyTarget === null) continue\\n const target = market.policyTarget\\n const off = target - has\\n // A net that calls for no hedge closes it at once.\\n if (target === 0 || off === 0) { hedges[market.instrumentId] = target; continue }\\n const perUnit = Math.abs(market.price) * market.contractMultiplier\\n if (Math.abs(off) * perUnit <= START) continue\\n // What is left off once the order goes: TARGET dollars, in whole steps.\\n const left = Math.floor(TARGET / perUnit / market.step) * market.step\\n if (left >= Math.abs(off)) continue\\n hedges[market.instrumentId] = off > 0 ? target - left : target + left\\n }\\n return { hedges }\\n}\\n\",\n \"resultsDays\": [\n 30\n ],\n \"expectedRevision\": null\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Idempotency-Key", "<idempotency-key>")
req.Header.Add("Authorization", "Bearer <token>")
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://app.trdrs.co/api/venues/{venueId}/hedging-policies/{hedgingPolicyId}/script")
.header("Idempotency-Key", "<idempotency-key>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"source\": \"import type { HedgeAnswer, HedgeInput } from '@trdrs/script-sdk'\\n\\n// Hold each hedge until it is off by more than START dollars, then bring it to within TARGET dollars.\\nconst START = 1_000_000\\nconst TARGET = 400_000\\n\\nexport default function hedge(input: HedgeInput): HedgeAnswer {\\n const hedges: Record<string, number> = {}\\n for (const market of input.instruments) {\\n if (!market.hedgeable) continue\\n const has = market.held + market.pending\\n // Where the policy can't size it now, keep what the hedge holds.\\n hedges[market.instrumentId] = has\\n if (market.price === null || market.policyTarget === null) continue\\n const target = market.policyTarget\\n const off = target - has\\n // A net that calls for no hedge closes it at once.\\n if (target === 0 || off === 0) { hedges[market.instrumentId] = target; continue }\\n const perUnit = Math.abs(market.price) * market.contractMultiplier\\n if (Math.abs(off) * perUnit <= START) continue\\n // What is left off once the order goes: TARGET dollars, in whole steps.\\n const left = Math.floor(TARGET / perUnit / market.step) * market.step\\n if (left >= Math.abs(off)) continue\\n hedges[market.instrumentId] = off > 0 ? target - left : target + left\\n }\\n return { hedges }\\n}\\n\",\n \"resultsDays\": [\n 30\n ],\n \"expectedRevision\": null\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://app.trdrs.co/api/venues/{venueId}/hedging-policies/{hedgingPolicyId}/script")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Idempotency-Key"] = '<idempotency-key>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"source\": \"import type { HedgeAnswer, HedgeInput } from '@trdrs/script-sdk'\\n\\n// Hold each hedge until it is off by more than START dollars, then bring it to within TARGET dollars.\\nconst START = 1_000_000\\nconst TARGET = 400_000\\n\\nexport default function hedge(input: HedgeInput): HedgeAnswer {\\n const hedges: Record<string, number> = {}\\n for (const market of input.instruments) {\\n if (!market.hedgeable) continue\\n const has = market.held + market.pending\\n // Where the policy can't size it now, keep what the hedge holds.\\n hedges[market.instrumentId] = has\\n if (market.price === null || market.policyTarget === null) continue\\n const target = market.policyTarget\\n const off = target - has\\n // A net that calls for no hedge closes it at once.\\n if (target === 0 || off === 0) { hedges[market.instrumentId] = target; continue }\\n const perUnit = Math.abs(market.price) * market.contractMultiplier\\n if (Math.abs(off) * perUnit <= START) continue\\n // What is left off once the order goes: TARGET dollars, in whole steps.\\n const left = Math.floor(TARGET / perUnit / market.step) * market.step\\n if (left >= Math.abs(off)) continue\\n hedges[market.instrumentId] = off > 0 ? target - left : target + left\\n }\\n return { hedges }\\n}\\n\",\n \"resultsDays\": [\n 30\n ],\n \"expectedRevision\": null\n}"
response = http.request(request)
puts response.read_body{
"script": {
"hedgingPolicyId": "00000000-0000-0000-0000-000000000001",
"mode": "watch",
"revision": 3,
"version": {
"id": "00000000-0000-0000-0000-000000000005",
"version": 2,
"sdkVersion": "0.1.0",
"resultsDays": [
30
],
"createdBy": "user-owner",
"createdAt": "2026-11-13T09:00:00.000Z",
"running": true,
"source": "import type { HedgeAnswer, HedgeInput } from '@trdrs/script-sdk'\n\n// Hold each hedge until it is off by more than START dollars, then bring it to within TARGET dollars.\nconst START = 1_000_000\nconst TARGET = 400_000\n\nexport default function hedge(input: HedgeInput): HedgeAnswer {\n const hedges: Record<string, number> = {}\n for (const market of input.instruments) {\n if (!market.hedgeable) continue\n const has = market.held + market.pending\n // Where the policy can't size it now, keep what the hedge holds.\n hedges[market.instrumentId] = has\n if (market.price === null || market.policyTarget === null) continue\n const target = market.policyTarget\n const off = target - has\n // A net that calls for no hedge closes it at once.\n if (target === 0 || off === 0) { hedges[market.instrumentId] = target; continue }\n const perUnit = Math.abs(market.price) * market.contractMultiplier\n if (Math.abs(off) * perUnit <= START) continue\n // What is left off once the order goes: TARGET dollars, in whole steps.\n const left = Math.floor(TARGET / perUnit / market.step) * market.step\n if (left >= Math.abs(off)) continue\n hedges[market.instrumentId] = off > 0 ? target - left : target + left\n }\n return { hedges }\n}\n"
},
"changedBy": "user-owner",
"changedAt": "2026-11-13T09:05:00.000Z",
"failuresInARow": 0,
"lastFailureAt": null,
"lastFailureReason": null
}
}{
"error": "invalid_instrument"
}{
"error": "invalid_instrument"
}{
"error": "invalid_instrument"
}{
"error": "invalid_instrument"
}{
"error": "invalid_instrument"
}{
"error": "invalid_instrument"
}{
"error": "invalid_instrument"
}{
"error": "invalid_instrument"
}Authorizations
The Venue key (trdrs_vk_sandbox_… or trdrs_vk_production_…), in preview. It belongs to one venue in one environment and carries the scopes it was created with. The venue's verified owner creates it while signed in. It works on the /api/venues/{venueId} routes and, with trader:read or trader:trade, on the account, market and trading routes, reading the venue's own traders' accounts and routing their orders, each request naming its trader in x-trdrs-trader. A trdrs_sk_… key can't be used in its place. It reaches its venue's routes and its venue's own traders, and the owner manages keys from a signed-in session. Keep it on your server.