PageSourceSearch

https://docs.optalgo.com/assets/js/1db0c0b1.c366eb87.js

js optalgo.com collected 2026-10-05 23:21:15 UTC 11,482 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunkfreedx_docs=self.webpackChunkfreedx_docs||[]).push([[5896],{7331:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>t,contentTitle:()=>r,default:()=>h,frontMatter:()=>o,metadata:()=>a,toc:()=>c});var i=s(4848),l=s(8453);const o={title:"Closing Positions",sidebar_position:3},r="Closing Positions",a={id:"signal-params/position-types/closing",title:"Closing Positions",description:"Position types for closing existing positions, either fully or partially.",source:"@site/docs/signal-params/position-types/closing.mdx",sourceDirName:"signal-params/position-types",slug:"/signal-params/position-types/closing",permalink:"/signal-params/position-types/closing",draft:!1,unlisted:!1,tags:[],version:"current",sidebarPosition:3,frontMatter:{title:"Closing Positions",sidebar_position:3},sidebar:"docsSidebar",previous:{title:"Opening Positions",permalink:"/signal-params/position-types/opening"},next:{title:"Position Management",permalink:"/signal-params/position-types/management"}},t={},c=[{value:"<code>CLOSE</code>",id:"close",level:2},{value:"Example",id:"example",level:3},{value:"When to Use",id:"when-to-use",level:3},{value:"<code>CLOSE_PARTIAL</code>",id:"close_partial",level:2},{value:"Required Parameters",id:"required-parameters",level:3},{value:"Examples",id:"examples",level:3},{value:"Scaling Out Strategy",id:"scaling-out-strategy",level:3},{value:"<code>CLOSE_ALL</code>",id:"close_all",level:2},{value:"Example",id:"example-1",level:3},{value:"When to Use",id:"when-to-use-1",level:3},{value:"Behavior",id:"behavior",level:3},{value:"Aliases",id:"aliases",level:2},{value:"<code>FLAT</code>",id:"flat",level:3},{value:"<code>CANCEL</code>",id:"cancel",level:3},{value:"<code>CLOSE_LONG</code>",id:"close_long",level:3},{value:"<code>CLOSE_SHORT</code>
1",id:"close_short",level:3},{value:"Automatic CLOSE_PARTIAL Conversion",id:"automatic-close_partial-conversion",level:2},{value:"Complete Examples",id:"complete-examples",level:2},{value:"Simple Close",id:"simple-close",level:3},{value:"Partial Close with Reason",id:"partial-close-with-reason",level:3},{value:"Emergency Close All",id:"emergency-close-all",level:3},{value:"Best Practices",id:"best-practices",level:2},{value:"1. Always Use trade_id for Specific Closes",id:"1-always-use-trade_id-for-specific-closes",level:3},{value:"2. Scale Out of Winners",id:"2-scale-out-of-winners",level:3},{value:"3. Use CLOSE_ALL for Emergencies Only",id:"3-use-close_all-for-emergencies-only",level:3},{value:"Next Steps",id:"next-steps",level:2}];function d(e){const n={a:"a",code:"code",h1:"h1",h2:"h2",h3:"h3",hr:"hr",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,l.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.h1,{id:"closing-positions",children:"Closing Positions"}),"\n",(0,i.jsx)(n.p,{children:"Position types for closing existing positions, either fully or partially."}),"\n",(0,i.jsx)(n.h2,{id:"close",children:(0,i.jsx)(n.code,{children:"CLOSE"})}),"\n",(0,i.jsx)(n.p,{children:"Close a specific position completely."}),"\n",(0,i.jsx)(n.h3,{id:"example",children:"Example"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-json",children:'{\n  "strategy_key": "your_key",\n  "position_side": "CLOSE",\n  "trade_id": "abc123"\n}\n'})}),"\n",(0,i.jsx)(n.h3,{id:"when-to-use",children:"When to Use"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsxs)(n.li,{children:["Close a specific trade by ",(0,i.jsx)(n.code,{children:"trade_id"})]}),"\n",(0,i.jsx)(n.li,{children:"Exit position at market price"}),"\n",(0,i.jsx)(n.li,{children:"Simple, immediate close"}),"\n"]}),"\n",(0,i.jsx)(n.hr,{}),"\n",(0,i.jsx)(n.h2,{id:"close_partial",children:(0,i.jsx)(n.code,{children:"CLOSE_PARTIAL"})}),"\n",(0,i.jsxs)(n.p,{children:["Close a portion of an open position based on ",(0,i.jsx)(n.code,{children:"close_ratio"}),"."]}),"\n",(0,i.jsx)(n.h3,{id:"required-parameters",children:"Required Parameters"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.code,{children:"close_ratio"}),": Percentage to close (0.0 - 1.0)"]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.code,{children:"trade_id"}),": Which position to partially close"]}),"\n"]}),"\n",(0,i.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,i.jsx)(n.p,{children:(0,i.jsx)(n.strong,{children:"Close 50% of position:"})}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-json",children:'{\n  "strategy_key": "your_key",\n  "position_side": "CLOSE_PARTIAL",\n  "close_ratio": 0.5,\n  "trade_id": "abc123"\n}\n'})}),"\n",(0,i.jsx)(n.p,{children:(0,i.jsx)(n.strong,{children:"Close 25% of position:"})}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-json",children:'{\n  "strategy_key": "your_key",\n  "position_side": "CLOSE_PARTIAL",\n  "close_ratio": 0.25,\n  "trade_id": "abc123"\n}\n'})}),"\n",(0,i.jsx)(n.h3,{id:"scaling-out-strategy",children:"Scaling Out Strategy"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-json",children:'// Take profit 1: Close 33%\n{\n  "position_side": "CLOSE_PARTIAL",\n  "close_ratio": 0.33,\n  "trade_id": "BTC_LONG"\n}\n\n// Take profit 2: Close 50% of remaining\n{\n  "position_side": "CLOSE_PARTIAL",\n  "close_ratio": 0.5,\n  "trade_id": "BTC_LONG"\n}\n\n// Take profit 3: Close remaining\n{\n  "position_side": "CLOSE",\n  "trade_id": "BTC_LONG"\n}\n'})}),"\n",(0,i.jsx)(n.hr,{}),"\n",(0,i.jsx)(n.h2,{id:"close_all",children:(0,i.jsx)(n.code,{children:"CLOSE_ALL"})}),"\n",(0,i.jsxs)(n.p,{children:["Close all open positions for the strategy, regardless of ",(0,i.jsx)(n.code,{children:"trade_id"}),"."]}),"\n",(0,i.jsx)(n.h3,{id:"example-1",children:"Example"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-json",children:'{\n  "strategy_key": "your_key",\n  "position_side": "CLOSE_ALL"\n}\n'})}),"\n",(0,i.jsx)(n.h3,{id:"when-to-use-1",children:"When to Use"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:"Emergency close all positions"}),"\n",(0,i.jsx)(n.li,{children:"End of trading session"}),"\n",(0,i.jsx)(n.li,{children:"Risk management trigger"}),"\n",(0,i.jsx)(n.li,{children:"Strategy shutdown"}),"\n"]}),"\n",(0,i.jsx)(n.h3,{id:"behavior",children:"Behavior"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:"Closes every open trade for the strategy"}),"\n",(0,i.jsx)(n.li,{children:"Processes all trades in parallel"}),"\n",(0,i.jsxs)(n.li,{children:["Ignores ",(0,i.jsx)(n.code,{children:"trade_id"})," if provided"]}),"\n",(0,i.jsx)(n.li,{children:"Deletes cached leverage settings"}),"\n"]}),"\n",(0,i.jsx)(n.hr,{}),"\n",(0,i.jsx)(n.h2,{id:"aliases",children:"Aliases"}),"\n",(0,i.jsxs)(n.p,{children:["These position types are converted to ",(0,i.jsx)(n.code,{children:"CLOSE"}),":"]}),"\n",(0,i.jsx)(n.h3,{id:"flat",children:(0,i.jsx)(n.code,{children:"FLAT"})}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-json",children:'{"position_side": "FLAT"}\n// Converted to: {"position_side": "CLOSE"}\n'})}),"\n",(0,i.jsx)(n.h3,{id:"cancel",children:(0,i.jsx)(n.code,{children:"CANCEL"})}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-json",children:'{"position_side": "CANCEL"}\n// Converted to: {"position_side": "CLOSE"}\n'})}),"\n",(0,i.jsx)(n.h3,{id:"close_long",children:(0,i.jsx)(n.code,{children:"CLOSE_LONG"})}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-json",children:'{"position_side": "CLOSE_LONG"}\n// Converted to: {"position_side": "CLOSE"}\n'})}),"\n",(0,i.jsx)(n.h3,{id:"close_short",children:(0,i.jsx)(n.code,{children:"CLOSE_SHORT"})}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-json",children:'{"position_side": "CLOSE_SHORT"}\n// Converted to: {"position_side": "CLOSE"}\n'})}),"\n",(0,i.jsx)(n.hr,{}),"\n",(0,i.jsx)(n.h2,{id:"automatic-close_partial-conversion",children:"Automatic CLOSE_PARTIAL Conversion"}),"\n",(0,i.jsxs)(n.p,{children:["If you send ",(0,i.jsx)(n.code,{children:"CLOSE"})," with ",(0,i.jsx)(n.code,{children:"close_ratio < 1.0"}),", it's automatically converted to ",(0,i.jsx)(n.code,{children:"CLOSE_PARTIAL"}),":"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-json",children:'// This signal:\n{\n  "position_side": "CLOSE",\n  "close_ratio": 0.5,\n  "trade_id": "abc123"\n}\n\n// Becomes:\n{\n  "position_side": "CLOSE_PARTIAL",\n  "close_ratio": 0.5,\n  "trade_id": "abc123"\n}\n'})}),"\n",(0,i.jsx)(n.hr,{}),"\n",(0,i.jsx)(n.h2,{id:"complete-examples",children:"Complete Examples"}),"\n",(0,i.jsx)(n.h3,{id:"simple-close",children:"Simple Close"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-json",children:'{\n  "strategy_key": "your_key",\n  "position_side": "CLOSE",\n  "trade_id": "BTC_LONG_001"\n}\n'})}),"\n",(0,i.jsx)(n.h3,{id:"partial-close-with-reason",children:"Partial Close with Reason"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-json",children:'{\n  "strategy_key": "your_key",\n  "position_side": "CLOSE_PARTIAL",\n  "close_ratio": 0.5,\n  "trade_id": "BTC_LONG_001",\n  "reason": "First take profit target reached"\n}\n'})}),"\n",(0,i.jsx)(n.h3,{id:"emergency-close-all",children:"Emergency Close All"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-json",children:'{\n  "strategy_key": "your_key",\n  "position_side": "CLOSE_ALL",\n  "reason": "High volatility - closing all positions"\n}\n'})}),"\n",(0,i.jsx)(n.hr,{}),"\n",(0,i.jsx)(n.h2,{id:"best-practices",children:"Best Practices"}),"\n",(0,i.jsx)(n.h3,{id:"1-always-use-trade_id-for-specific-closes",children:"1. Always Use trade_id for Specific Closes"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-json",children:'// \u2705 Good\n{\n  "position_side": "CLOSE",\n  "trade_id": "BTC_001"\n}\n\n// \u26a0\ufe0f Risky (may close wrong trade)\n{\n  "position_side": "CLOSE"\n}\n'})}),"\n",(0,i.jsx)(n.h3,{id:"2-scale-out-of-winners",children:"2. Scale Out of Winners"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-json",children:'// Take partial profits along the way\n{"close_ratio": 0.33}  // At TP1\n{"close_ratio": 0.5}   // At TP2\n{"close_ratio": 1.0}   // At TP3\n'})}
1),"\n",(0,i.jsx)(n.h3,{id:"3-use-close_all-for-emergencies-only",children:"3. Use CLOSE_ALL for Emergencies Only"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-json",children:'// Emergency situations\n{\n  "position_side": "CLOSE_ALL",\n  "reason": "Market crash - emergency close"\n}\n'})}),"\n",(0,i.jsx)(n.hr,{}),"\n",(0,i.jsx)(n.h2,{id:"next-steps",children:"Next Steps"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.a,{href:"./management",children:"Position Management"})," - Update orders without closing"]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.a,{href:"../examples/partial-close",children:"Examples"})," - Partial close examples"]}),"\n"]})]})}function h(e={}){const{wrapper:n}={...(0,l.R)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.jsx)(d,{...e})}):d(e)}},8453:(e,n,s)=>{s.d(n,{R:()=>r,x:()=>a});var i=s(6540);const l={},o=i.createContext(l);function r(e){const n=i.useContext(o);return i.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(l):e.components||l:r(e.components),i.createElement(o.Provider,{value:n},e.children)}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.