MT Paste API Doc
The Paste API lets another program drive Medved Trader's trading windows. It works by handing a trading window a block of JSON, either on the Windows clipboard or in a WM_COPYDATA message.
The JSON is the same language that Medved Trader's Hotkeys are written in. Anything a hotkey can do on a Chart, Level II, DOM, Trade Ticket or Account window, a Paste API payload can do on that window. That includes placing, dropping, changing and cancelling orders, flattening positions, and changing the window's symbol, account or quantity.
The simplest way to write a payload is to build the hotkey in Medved Trader's Hotkey editor first. Then right-click it in the hotkey list, choose Copy for Paste API, and add your password (Pwd).
Please contact us at support@medvedtrader.com if you're having any problems with the API.
The Paste API is separate from the WebSocket streaming API, but the two work together:
- The streaming API's
tradeCommandFromHotkeycommand accepts the same hotkey JSON, but without a target window. - An EchoTo of
"api"sends window information back through the streaming API.
Enabling the Paste API
The Paste API is off by default. Two conditions must both be true, or pasted JSON is silently ignored (see Results and errors):
- Premium subscription. The Paste API, like all of Medved Trader's APIs, requires a Premium subscription. A trial subscription includes it. Without it, the Paste API section of the settings page is greyed out.
- Enable PASTE API is checked in Medved Trader Settings → App → API. To change settings on that page you have to enter your Medved Trader account password (or your PIN, if you log in with a social login).
Once it is enabled, the Copy for Paste API item appears on the hotkey list's right-click menu.
How a payload is processed
- Delivery. The text arrives at one trading window, by clipboard paste or
WM_COPYDATA. After leading and trailing whitespace is trimmed, it must start with{or[. Anything else is treated as an ordinary paste, e.g. a symbol. - Gate. The window must be a trading window: Chart, Level II, DOM, Trade Ticket or Account. The Paste API must also be enabled. If either condition fails, the JSON is dropped without any message.
- Password. Every statement must carry a valid
Pwd. - Echo. If the statement asks for it, the window's current state is sent back to you. This happens before any command runs (see EchoTo).
- Split. The payload is split into statements and commands. Disabled commands are removed. Orders for a different account or symbol are separated out, so each can be sent to its own account (see Order).
- Evaluate and run.
Varsare evaluated against the window's current state. Then each command's expressions are evaluated, and the commands run in order.
Commands run asynchronously on a background hotkey thread. Nothing is returned to the caller except the WM_COPYDATA accept/reject result and any echo you asked for. Errors are shown to the user in the target window.
Clipboard paste
Put the JSON on the clipboard as text (CF_UNICODETEXT / CF_TEXT). Then make MT paste it into a trading window by doing either of the following:
- Give the window focus and send Ctrl+V (or whatever key is assigned to the Paste keyboard shortcut).
- Use the window's Paste context-menu item, where it has one (Chart).
The paste goes to the window that has focus. On Trade Ticket and Level II windows, if the cursor is in a text box of the ticket (quantity, price…), the paste goes into that box as ordinary text. It is not treated as a Paste API payload.
WM_COPYDATA
Send a WM_COPYDATA (0x004A) message straight to the trading window's handle. The window does not need focus.
| Field | Content |
|---|---|
| dwData | ignored (any value) |
| cbData | byte length of lpData, including the terminating NUL |
| lpData | the JSON as a NUL-terminated string. UTF-16 (wide) is preferred. MT reads the data as UTF-16 first, and falls back to ANSI if that does not yield text starting with { or [. The JSON must be at least 10 characters long. |
| Value | Meaning |
|---|---|
| 1 | The JSON was parsed and queued for the window. This does not mean the password was accepted or that the commands succeeded. Both are checked afterwards. |
| 0 | Rejected. Possible reasons: not JSON, not a trading window, the Paste API is disabled or not permitted, or the JSON could not be parsed. |
Use the normal Win32 enumeration functions (EnumWindows, FindWindow, matching on the window caption). Once you have talked to a window, the handle field of any echo gives you its handle. A handle stays valid until the window is closed; it is not preserved across layout reloads or restarts.
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
struct COPYDATASTRUCT { public IntPtr dwData; public int cbData; public string lpData; }
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, ref COPYDATASTRUCT cds);
const int WM_COPYDATA = 0x004A;
static bool SendPaste(IntPtr mtWindow, string json)
{
var cds = new COPYDATASTRUCT { dwData = (IntPtr)1, cbData = (json.Length + 1) * 2, lpData = json };
return SendMessage(mtWindow, WM_COPYDATA, IntPtr.Zero, ref cds) == (IntPtr)1;
}Password (Pwd)
Every pasted payload must authenticate:
- A single-object payload carries
"Pwd"at its top level. - An array payload needs
"Pwd"in every element.
The value is the password you use to log into Medved Trader. If you log in with a social login, which has no application password, it is your PIN instead.
- A wrong password rejects the whole payload after a 1-second delay, and the window shows "PASTE Error : Invalid Password".
- For a social login, three consecutive failures lock the API out until Medved Trader is restarted or you log in again. Until then even the correct PIN is refused.
- A valid
Pwdalso takes the place of the per-account trading authorization prompt, but only for the next second. If a payload hasDelaysteps that push an order past that second, the user may be prompted to authorize the account.
Pwd sitting on the clipboard.Results and errors
The Paste API has no response channel. Here is what you can observe:
- Rejected before processing (not enabled, not a trading window, not JSON): nothing happens.
WM_COPYDATAreturns 0. - Password or payload errors: an error tooltip on the target window, e.g. "PASTE Error : Invalid Password" or "Hotkey Error: …".
- Command errors, e.g. an invalid expression, quantity 0, or an account that is not started: an error tooltip on the window. If the window is gone, a notification pop-up appears instead.
- Order outcome: watch it the same way you would for a manual order, in the Account window. Or use the WebSocket API's
tradeCommandUpdate/transactionsUpdate.
If EchoTo is set, the echo tells you the payload got past the password check. That is the only confirmation you get back.
Statements
A payload is one statement object, a JSON array of statements, or several statement objects placed one after another. A statement is exactly what the Hotkey editor saves for one hotkey.
| Name | Req | Type | Content |
|---|---|---|---|
| Pwd | Y | string | see Password |
| Command | Y | object | array | one command object, or an array of them, run in order |
| Vars | N | object | variable declarations, evaluated before the commands (see Vars and If) |
| JSON | N | object | array | if present, the payload is replaced by this member. This lets you paste a whole exported hotkey record (with Pwd added at the top level). |
| EchoTo, EchoClientMsg, hwnd, Change | N | see EchoTo |
Separate, SeparateSym and ALREADYAUTH are reserved for internal use. Do not send them.
{
"Pwd": "mypassword",
"Command": {
"Disabled": false,
"Order": {
"Send": "true",
"Legs": [ { "Action": "Buy", "OrderType": "Limit", "Quantity": "100", "LimitPrice": "Ask" } ]
}
}
}Command objects
Each command object holds one action key (Order, Cancel, TradeQty, …), plus these optional envelope keys:
| Name | Type | Content |
|---|---|---|
| Disabled | bool |
true skips the action. The Hotkey editor writes "Disabled": false in every action.SetIntervar, ShareTrade, SharePos, PlaySound and Locate run only when "Disabled": false is present.
|
| Delay | string |
{"Delay": "0.5"} as a command on its own pauses that many seconds before the following commands run.It only takes effect as the first command of a statement, which is how the editor writes it. |
| ActiveSection | expression |
If it evaluates to false, the action is skipped. It can sit beside the action key or inside the action object. Inside ChangeOrder it is evaluated separately for each order the change applies to.
|
| reqID | string | correlation tag. When a payload arrives through the WebSocket API, result notifications carry it. Put it on the first command. |
Value types
Almost every value is a string, even numbers and booleans ("Quantity": "100", "Drop": "true"). Nearly every string value is an expression that MT evaluates against the window's current state. So "Ask+0.05", "round(PosAbs/2)" and "100" are all valid quantities or prices.
Send and Drop accept either a string ("true", "false", "CancelThenSend"…, in any letter case) or a JSON boolean (true / false).
Key names are case-sensitive, e.g. LimitPrice, not limitprice. Write enumeration values in order legs (Action, OrderType, TIF, ConditionalType) exactly as they are listed under Enumerations. Variable and function names inside expressions are not case-sensitive.
Order
Builds an order and drops it into the window, sends it to the broker, or both.
| Name | Req | Content |
|---|---|---|
| Send | N |
"false" (default) or "true". Or one of the cancel-first variants, which cancel the matching open orders for the symbol and then send:CancelThenSend, CancelBuysThenSend, CancelSellsThenSend, CancelStopsThenSend, CancelBuyStopsThenSend, CancelSellStopsThenSend.Any value other than "false" sends.
|
| Drop | N | "true" puts the order into the window without sending it: into the ticket (Trade Ticket, Level II), or as an order capsule (Chart, DOM). Default "false". Only possible for the window's own account and symbol. |
| Account | N | "Default" or omitted = the window's account. Otherwise an account key ("SCHWAB:12345678"), account ID or display name. Another account's order is sent to that account directly and cannot be dropped. |
| Symbol | N |
"Default" or omitted = the window's symbol."group:Blue" = the symbol currently in that link group.Any other value is a literal symbol; the order is sent for it separately. Real-time prices for another symbol are only available if MT already has an L1 subscription for it. |
| ConditionalType | N | None (default, 1 leg), OCA (2), OTA (2), OTT (3), OTOCA (3), OTOTA (3). The broker must support the type. |
| ConfirmToWindow | N | bool, default true: show an "order sent" confirmation on the window for orders sent to another account or symbol |
| Legs | Y | array of legs |
- On Trade Ticket and Level II windows, an Order must have
DroporSend. A payload may drop at most one order there. - If the window has trading disabled (no account selected), any command that uses the window's account is refused.
Order Legs
| Name | Content |
|---|---|
| Action |
Buy, Sell, or another OrderAction (Short, Cover, option open/close actions).None means the order is not placed. This is useful with an if … then … else 'None' expression.=CurrentAction takes the window's current Buy/Sell side (Trade Ticket, Level II, DOM only).
|
| OrderType | Market, Limit, StopMarket, StopLimit, TStopDLR (trailing, $), TStopPT (trailing, %), TStopTick, TStopLimit, MOO, MOC, LOO, LOC, Bracket, … TStop is treated as TStopDLR. |
| Quantity | number expression. If the first leg has none, the window's default quantity is used. Later legs inherit the first leg's quantity. A result of 0 cancels the order with "Order quantity of 0". |
| LimitPrice | price expression, offset ("+0.05", "-1%") or peg |
| StopPrice |
same forms as LimitPrice.For trailing types, a plain number is the trail amount. For StopLimit, a limit offset is taken relative to the stop price.
|
| TIF |
Time in force. If omitted, the window's current TIF is used. For orders sent to another account or symbol, and on the global hotkey window, the default is Day.
|
| TIFDate | for GTD: M/d/yyyy or yyyy-MM-dd |
| Routing | route name (first leg only). Default = the window's current route. |
| SpInstructions | space- or comma-separated: AON, FOK, DNR, Hidden, PostOnly, Anon. Default = the window's setting. |
| DisplaySize | number (reserve/iceberg display size, where supported) |
| XOnChart | 0–100: horizontal position of a dropped capsule on a chart |
Conditional orders. In a conditional order (OTA, OTOCA…), a secondary leg's price can be an offset from the main leg's limit or stop price. For a main leg with no price (Market…), the base is the last trade.
Leave a field out rather than writing "Default"; the Hotkey editor never writes "Default" into a leg.
Cancel
| Name | Content |
|---|---|
| Open |
which open (working) orders to cancel. One value, a CSV string or an array:None, All, Buys, Sells, LastOpen, BuyStops, SellStops, AllStops, UnderMouse (Chart/DOM: the order under the mouse)
|
| Unsent | which unsent (dropped) capsules to remove. Same values except LastOpen. Chart and DOM only. |
| Symbol |
Default = the window's symbol.Other values: a list of symbols, group:<color>, or AllSymbols.
|
| Account | default = the window's account |
| ConfirmToWindow | bool, default true |
{ "Pwd": "mypassword", "Command": { "Disabled": false, "Cancel": { "Open": "All", "Unsent": "None" } } }Flatten
Cancels the working orders and closes the position with a market order.
| Name | Content |
|---|---|
| Position | Required. Both, Long or Short. Only positions on that side are flattened. With no Position, nothing happens. |
| Symbol |
Default = the window's symbol.Other values: a list, group:<color>, or AllSymbols (every symbol with a position or open order in the account).
|
| Account | default = the window's account |
ChangeOrder
Modifies existing orders or dropped capsules in the window. Its expressions are evaluated once for each order the change applies to. While they are evaluated, these variables are set from that order: OrderQty, OrderPrice, OrderType, OrderIsBuy, OrderIsSell, OrderIsUnsent, CurrentTIF.
| Name | Content |
|---|---|
| AppliesTo |
Selected (default), All, SelectedSymbol, TradeTicket.On Chart, DOM and Level II, SelectedSymbol behaves as All.
|
| NewPrice | an absolute price (25.10), an offset (+0.05, -1%) or an expression. A leading + or - makes it an offset from the order's current price; anything else is an absolute price. With AllLegs: true it must be an offset. Default +0. |
| NewQty | the new total quantity: an absolute quantity (200), an offset (+100, -50) or an expression. Same rule as NewPrice — a leading + or - makes it an offset, anything else is absolute. Any partial fill is kept out of the new remaining quantity. Default +0. |
| NewTIF / NewTIFDate | new time in force / GTD date |
| NewSpInst | new special instructions |
| AllLegs | "true" applies a price offset to every leg of a multi-leg order |
| Send |
"true" sends the change to the broker; for unsent capsules and the ticket, this places the order.On the Account window's Positions tab, Send must be true.
|
{ "Pwd": "mypassword", "Command": { "Disabled": false,
"ChangeOrder": { "AppliesTo": "All", "NewPrice": "+0.02", "Send": "true" } } }TradeQty / Account / Symbol
These change the window itself. Each takes a single string value, directly on the command object:
| Command | Content |
|---|---|
| {"TradeQty": "<expr>"} | sets the window's trade quantity (ribbon or ticket) |
| {"Account": "<key|id|name>"} | selects the window's trading account |
| {"Symbol": "<symbol>"} | changes the window's symbol |
A symbol or account change can itself trigger an echo.
Other actions
| Action | Fields | Content |
|---|---|---|
| Hotkey | Enabled, Hotkey | runs another saved hotkey, identified by its unique ID, when Enabled is "true" |
| SymbolLink | Symbol, Group | puts a symbol (or the window's, with Default) into a link group |
| SetIntervar | Type (Symbol|Global), Name, Value | sets an Intervar. Numeric values are stored as numbers. |
| ShareTrade | Emails, Account, Which (LastExecuted|All|Selected) | shares trades with other Medved Trader users |
| SharePos | Emails, Account, Which (All|Selected) | shares positions |
| PlaySound | Sound | plays a sound by name or file path (beeps if the file is missing) |
| Locate | Reserve, MaxPricePerShare, Prompt, Symbol, Account | requests a short locate (multiple of 100), with brokers that support locates |
| RouteCycle | RouteList | moves the window's route to the next one in the list |
| SetFocus | Field | focuses a ticket field: OrderType, Quantity, LimitPrice, StopPrice, TimeInForce, SpecialInstructions (Trade Ticket, and Level II with the compact ticket) |
Chart-only actions
| Action | Content |
|---|---|
| ChartParameter | changes ChartType, ColorSet, Draw, Period or Frequency |
| Axis | absolute, dynamic, dynamicpadded, window, optionally with Centered |
| DrawType | starts a drawing tool: line, linealert, box, channel, fib, fibexp, fibfan, fibtime, riskreward, text, circle, oval, triangle, arc, curve, spiral, pitch, scroll |
| SetChartVar | {Name, Value}: sets a chart variable readable by chartvar(). It must be the only action in its command object. |
| ShowFills | Chart and DOM. Shows or hides the window's filled orders, the same as the Chart's Show Filled Orders toggle or the DOM's Fills Shown As combo. Saved with the window's layout.true or false; "toggle" flips it; on a DOM, "None", "Arrow", "Circle" or "Diamond" pick the shape (true keeps a shape already shown, or uses Arrow).On a Chart a shape name just turns fills on; the chart's fill shape is the global Charts setting. |
{ "Pwd": "mypassword", "Command": { "ShowFills": "toggle" } }Account-only actions
These work only on an Account window. Sent anywhere else, including the global hotkey window, they are refused with "TransFilter only works on the Account window."
| Action | Fields | Content |
|---|---|---|
| TransFilter | Status |
sets the Status filter of the Transactions tab, the same as choosing it in the ribbon's Status box. If the window is on another tab, it switches to Transactions first.Status is one of ALL (no filter), AllOpen, AllOpenFilled, AllFilled, AllBuyFills, AllSellFills, AllOther. Letter case does not matter, and the text shown in the Status box ("All Open") is accepted too.The choice is saved with the window's layout. The symbol and days filters are left as they are. |
{ "Pwd": "mypassword", "Command": { "TransFilter": { "Status": "AllOpen" } } }Syntax
String values are evaluated as C#-style expressions (+ - * / %, comparisons, && || !, ? :). The syntax is relaxed:
- A leading
=is optional:"=Ask+0.01"and"Ask+0.01"are the same. if A then B else Cis allowed, and must be complete.and,orandnotare allowed.=means equality, and<>means not-equal.- Strings may use single quotes:
'Buy'. Dates can be written asM/d/yyyy. - Variable and function names are not case-sensitive.
- A bare word that is not a variable is taken as text. This is how symbol, route and TIF names pass through unchanged.
Numbers are decimals. A condition is true when it is non-zero.
Offsets and pegs
| Form | Meaning |
|---|---|
| "+0.05" / "-0.05" | offset in points from the base price. The base is the last trade, or for secondary conditional legs, the main leg's price. |
| "+1%" / "-0.5%" | offset in percent |
| offset(x) | turns a computed number into a points offset |
| peg(base, x) | pegged price base + x, where base is bid, ask, price or mid. It must be the whole field. Dropped into a Trade Ticket or Level II, it sets the ticket's peg mode. |
| pegpct(base, x) | pegged price base × (1 + x/100) |
A price expression without a sign is an absolute price: "Bid-0.01" is a price, while "-0.01" is an offset.
Functions
| Function | Content |
|---|---|
| abs, min, max | as usual |
| round(x), round_dig(x,n), round_inc(x,inc) | round to an integer, to n decimals, or to a multiple of inc |
| floor…, ceil… | same three forms: floor, floor_dig, floor_inc, ceil, ceil_dig, ceil_inc |
| symbolprice(s), symbolbid(s), symbolask(s), symbolticksize(s) | quotes for another symbol (it must already be streaming in MT) |
| symbolrecent(s, secs) | recent price of symbol s over the given number of seconds |
| intervar('name'), intervarg('name') | symbol / global Intervar value |
| chartvar('name') | chart variable (Chart) |
| bead(n) | price of chart bead n, 1–20 (Chart) |
| l2bid(n), l2ask(n), l2bidsize(n), l2asksize(n) | Level II book row n, 0–99: price or size (Level II) |
| randint(a,b), randfloat(a,b) | random number |
Variables
Variables come from the target window's current symbol, account and state. Mouse and capsule variables only make sense on a Chart or DOM with the mouse over it; outside that they are 0, and an order that uses them is refused.
| Group | Variables |
|---|---|
| Quote | Price (last), Bid, Ask, Mid, TickSize, CostMult, PrevClose, TodayOpen, TodayHigh, TodayLow |
| Quantity | DefaultQty: the quantity in the window's trading ribbon or ticket |
| Position | Pos (negative if short), PosAbs, PosPaid (base price), CurrencyPos (crypto pairs) |
| Fills | LastFillPrice, LastFillQty, FirstFillPrice, FirstFillQty, each also with a …Bought / …Sold suffix (e.g. LastFillPriceSold) |
| Account | Account, Broker, Cash, AccountValue, DaytradeBP, OvernightBP, IsHTB, LocateReserved, LocateAvailable |
| Window state | CurrentAction (Buy/Sell; Trade Ticket, Level II, DOM), CurrentSpInst, TradeTicketVisible, TicketLimitPrice, TicketStopPrice (Trade Ticket, Level II) |
| Mouse / capsule (Chart, DOM) | PriceAtMouse; for the capsule under the mouse: CapPrice, CapQty, CapAction, CapOrderType |
| Candles (Chart) | BarOpen, BarHigh, BarLow (current candle); BarOpen1..3, BarHigh1..3, BarLow1..3, BarClose1..3 (1–3 candles back); NumBeads |
| Risk/Reward (Chart) | RiskRewardQty, RiskRewardEntry, RiskRewardTarget, RiskRewardStop, taken from the risk/reward annotation (the one under the mouse, or the only one) |
| Time / session | Now, DayStart, DayEnd, SessionStart, SessionEnd (all UTC); PreMarket, RegSession, AfterMarket (true/false); MinIntoSession |
| ChangeOrder only | OrderQty, OrderPrice, OrderType, OrderIsBuy, OrderIsSell, OrderIsUnsent, CurrentTIF |
Vars and If
Vars declares your own variables, which the commands can then use by name. They are evaluated in order, so a later variable can use an earlier one. Global Vars defined in the Hotkey editor are evaluated first. An optional If member (one object or an array) sets variables conditionally:
"Vars": {
"Half": "round(PosAbs/2)",
"Side": "if Pos > 0 then 'Sell' else 'Buy'",
"If": [
{ "Condition": "PreMarket or AfterMarket", "Then": { "Tif": "'Day_ext'" }, "Else": { "Tif": "'Day'" } }
]
}Inside Then / Else, values must be strings: "5", not 5. Numeric JSON values there are ignored.
EchoTo
A statement can ask the target window to report its current state back to you. That report is the echo. It is produced when the statement has passed the password check, and before its commands run.
| Name | Req | Content |
|---|---|---|
| EchoClientMsg | Y | any JSON object; it is returned to you unchanged. No echo is produced without it. {} is enough. |
| EchoTo | N |
where the echo goes:"api" (default): as an APIKeyPressUpdate to every connected WebSocket API session."hwnd": a WM_COPYDATA to the window in hwnd."clipboard": the clipboard.
|
| hwnd | N | for "hwnd": your window's handle, as a decimal integer |
| Change | N | subscribe to window changes; see Change notifications |
For "hwnd", MT sends (not posts) WM_COPYDATA with dwData = 1 and lpData = the echo JSON as a NUL-terminated UTF-16 string. Handle it promptly, because MT's window waits while you process it.
A payload that MT splits into several statements (for example, orders for several accounts) can produce more than one echo.
{ "Pwd": "mypassword", "EchoTo": "hwnd", "hwnd": 3148874, "EchoClientMsg": { "id": "q1" },
"Command": { "Disabled": false, "TradeQty": "DefaultQty" } }A statement needs at least one command that is not disabled, or it is dropped before any echo is made. Setting TradeQty to DefaultQty changes nothing, so it works as a harmless placeholder command.
Change notifications
Add a Change list to a statement that has EchoTo and EchoClientMsg. It can contain any of Symbol, Account, TradeQty, or All, e.g. "Change": "Symbol,TradeQty". From then on, whenever a trading window's symbol, account or trade quantity changes, it sends an echo to the same destination, with "Change" set to "symbol", "account" or "tradeqty".
- The subscription is global. It covers every trading window, not just the one you pasted into.
- Only one subscription exists at a time: the latest
EchoToreceived replaces it. - To stop notifications, send a statement with
EchoToand"Change": "None". - Subscriptions do not survive a Medved Trader restart.
Echo payload
| Name | Type | Content |
|---|---|---|
| window | string | window class: ChartWindow, LevelIIWindow, DOMWindow, TradeTicketWindow, TradeAccountView |
| handle | string | the window's HWND (decimal); use it as a WM_COPYDATA target |
| symbol | string | the window's symbol |
| data | object | the symbol's snapshot: sym, companyName, bid, ask, last, volume, prevClose, open, high, low, … (same fields as the WebSocket API's getSymbolSnapshot) |
| tradeAccount | object | tradingSite, accountID, accountName, accountKey; present if the window has an account |
| priceAtMouse, timeAtMouse | number, string | Chart only |
| position | object | Chart only: qty, paid |
| TradeQty | number | the window's trade quantity (Chart, DOM: ribbon; Trade Ticket, Level II: ticket) |
| Change | string | symbol, account or tradeqty, only in change notifications |
| ClientMsg / clientMsg | object | your EchoClientMsg. It is ClientMsg for hwnd and clipboard echoes, and clientMsg in an APIKeyPressUpdate. |
{
"window": "LevelIIWindow", "handle": "2951610", "symbol": "BAC",
"data": { "sym": "BAC", "companyName": "Bank of America Corp", "bid": "46.12", "ask": "46.13", "last": "46.12", "…": "…" },
"tradeAccount": { "tradingSite": "SCHWAB", "accountID": "12345678", "accountName": "Main", "accountKey": "SCHWAB:12345678" },
"TradeQty": 100,
"Change": "symbol",
"ClientMsg": { "id": "q1" }
}Per-window behaviour
| Window | Behaviour |
|---|---|
| Trade Ticket |
Trading must be enabled. Supports Order (Drop fills the ticket), Cancel ( Open only), ChangeOrder (edits the ticket; Send submits it), TradeQty, RouteCycle and SetFocus.
|
| Level II |
Supports the same actions as Trade Ticket. Orders are always for the window's symbol. ChangeOrder with Send "true" modifies the working order on the book: the only one on that side, the one under the mouse, or the locked one.
|
| Chart |
Drop creates a capsule on the chart; Cancel supports Unsent, UnderMouse and LastOpen; ChangeOrder works on capsules.Adds the chart-only actions, mouse and candle variables, bead() and chartvar().
|
| DOM |
Drop creates a capsule; Cancel supports Unsent and UnderMouse.PriceAtMouse comes from the price row under the mouse.Also supports ShowFills. |
| Account |
Only ChangeOrder and Cancel, on the Transactions or Positions tab, plus TransFilter (any tab; it switches to Transactions). Variables come from the highlighted row's symbol. Cancel Open "All" cancels across every symbol with open orders.
|
Examples
{
"Pwd": "mypassword",
"Vars": { "Half": "round(PosAbs/2)" },
"Command": { "Disabled": false, "Order": { "Send": "true",
"Legs": [ { "Action": "Sell", "OrderType": "Limit", "Quantity": "Half", "LimitPrice": "Ask-0.01", "TIF": "Day" } ] } }
}{
"Pwd": "mypassword",
"Command": { "Disabled": false, "Order": { "Send": "CancelThenSend", "ConditionalType": "OTOCA",
"Legs": [
{ "Action": "Buy", "OrderType": "Limit", "Quantity": "DefaultQty", "LimitPrice": "Ask" },
{ "Action": "Sell", "OrderType": "Limit", "LimitPrice": "+0.50" },
{ "Action": "Sell", "OrderType": "StopMarket", "StopPrice": "-0.25" }
] } }
}{
"Pwd": "mypassword",
"Command": [
{ "Disabled": false, "Symbol": "AAPL" },
{ "Disabled": false, "TradeQty": "50" },
{ "Disabled": false, "Order": { "Drop": "true", "Send": "false",
"Legs": [ { "Action": "Buy", "OrderType": "Limit", "LimitPrice": "Bid" } ] } }
]
}{ "Pwd": "mypassword", "Command": { "Disabled": false,
"Flatten": { "Account": "SCHWAB:12345678", "Symbol": "AllSymbols", "Position": "Both" } } }Enumerations
| Name | Values |
|---|---|
| OrderAction | Buy, Sell, Short, Cover, BuyOpen, BuyClose, SellOpen, SellClose, None (= do not place) |
| OrderType | Market, Limit, StopMarket, StopLimit, TStopDLR, TStopPT, TStopTick, TStopLimit, MOO, MOC, LOO, LOC, Bracket, NetDebit, NetCredit, NetZero |
| TIF | Day, GTC, Day_ext, GTC_ext, GTD, GTD_ext, MOC, AM, PM, IOC, Day_During, Overnight (availability depends on the broker) |
| ConditionalType | None, OCA, OTA, OTT, OTOCA, OTOTA |
| SpInstructions | AON, FOK, DNR, Hidden, PostOnly, Anon |
| Link group colors | Blue, Green, Red, Cyan, Brown, Black, Gray, Pink, Purple, LawnGreen, Maroon, Yellow, Olive, Iris, Tan, Apricot, Beige, Mint, Lime, Salmon, NeonPink, Crimson, Khaki, Teal, Chocolate, Active |