Bentrix Docs
HomePricingDashboard

Go: trading

Every method of client.Trade in the Go SDK.

ExportDeals#

Export a workbench's deals to a file · tool export_deals

scope: readplan: freesince 1.0.0

Writes every deal of the workbench's venue, oldest first, as its History tab lists them, as CSV into the export folder under this agent's name; answers the file's path, uri, rows and bytes.

Declaration

client.Trade
func (a *TradeAPI) ExportDeals(ctx context.Context, args TradeExportDealsArgs) (any, error)

Parameters

NameTypeWhat it is
Benchstringrequired

Returns

(any, error) — the tool’s answer as maps and slices (any).

What it answers

What the tool's description says.

Example

client.Trade.ExportDeals(ctx, mcp.TradeExportDealsArgs{Bench: bench})

OrderClose#

Close a position or cancel an order · tool order_close

scope: labplan: plussince 1.0.0

Closes a position (all of it, or volume lots of it) or cancels a pending order on a laboratory or paper workbench, as the Toolbox's Close does; a close is never refused for being a close. Answers the book. On a real account it goes through the account's agents' mode: proposed in the trade panel for the person's Send (outcome awaiting_person), or under the person's One-click, with real:send, sent as their One-click sends (outcome sent); refused expired past its validity and refused_by_cap past the account's caps.

Declaration

client.Trade
func (a *TradeAPI) OrderClose(ctx context.Context, args TradeOrderCloseArgs) (any, error)

Parameters

NameTypeWhat it is
Benchstringrequired
Ticketint64required
Volume*float64optionalLots to close; absent closes all of it (a pending order is cancelled).

Returns

(any, error) — the tool’s answer as maps and slices (any).

What it answers

Recorded from a running Bentrix 0.1.382 on a laboratory of generated markets (long lists cut to their first rows):

{
  "bench": "bentrix://lab/lab-1/bench/bench-2",
  "last_answer": {
    "accepted": "close 1"
  },
  "orders": [],
  "positions": [
    {
      "magic": 0,
      "price_current": 0.96831,
      "price_open": 0.96848,
      "profit": -1.7000000000000348,
      "side": "buy",
      "sl": 0.9587952,
      "symbol": "SYN-DOCS",
      "ticket": 1,
      "tp": 0.9781648,
      "volume": 0.1
    },
    {
      "magic": 0,
      "price_current": 5.76316,
      "price_open": 5.76189,
      "profit": -12.699999999998823,
      "side": "sell",
      "sl": 0.0,
      "symbol": "SYN-DOCS2",
      "ticket": 2,
      "tp": 0.0,
      "volume": 0.1
    }
  ]
}

Example

client.Trade.OrderClose(ctx, mcp.TradeOrderCloseArgs{Bench: bench, Ticket: 1})

OrderCloseAll#

Close every position · tool order_close_all

scope: labplan: plussince 1.1.0

Closes every open position on a workbench, or every one of one market, as the trade panel's Close all does; pending orders stay. Answers the book. On a real account it goes through the account's agents' mode: proposed in the trade panel for the person's Send (outcome awaiting_person), or under the person's One-click, with real:send, sent as their One-click sends (outcome sent).

Declaration

client.Trade
func (a *TradeAPI) OrderCloseAll(ctx context.Context, args TradeOrderCloseAllArgs) (any, error)

Parameters

NameTypeWhat it is
Benchstringrequired
Symbol*stringoptionalOne market's positions only; absent closes every position on the workbench.

Returns

(any, error) — the tool’s answer as maps and slices (any).

What it answers

Recorded from a running Bentrix 0.1.382 on a laboratory of generated markets (long lists cut to their first rows):

{
  "bench": "bentrix://lab/lab-1/bench/bench-2",
  "last_answer": {
    "accepted": "close 2"
  },
  "orders": [],
  "positions": [
    {
      "magic": 0,
      "price_current": 0.96831,
      "price_open": 0.96848,
      "profit": -1.7000000000000348,
      "side": "buy",
      "sl": 0.9587952,
      "symbol": "SYN-DOCS",
      "ticket": 1,
      "tp": 0.9781648,
      "volume": 0.1
    },
    {
      "magic": 0,
      "price_current": 5.76316,
      "price_open": 5.76189,
      "profit": -12.699999999998823,
      "side": "sell",
      "sl": 0.0,
      "symbol": "SYN-DOCS2",
      "ticket": 2,
      "tp": 0.0,
      "volume": 0.1
    }
  ]
}

Example

client.Trade.OrderCloseAll(ctx, mcp.TradeOrderCloseAllArgs{Bench: bench})

OrderMarket#

Send a market order · tool order_market

scope: labplan: plussince 1.0.0

Sends a market order on a laboratory or paper workbench through the trade panel's own door; it fills on the workbench's next tick. Refused in the venue's own words where a press would be (a closed market, the stops level, the trade mode). Answers the book and the venue's last answer. On a real account it goes through the account's agents' mode: proposed in the trade panel for the person's Send (outcome awaiting_person), or under the person's One-click, with real:send, sent as their One-click sends (outcome sent); refused expired past its validity and refused_by_cap past the account's caps.

Declaration

client.Trade
func (a *TradeAPI) OrderMarket(ctx context.Context, args TradeOrderMarketArgs) (any, error)

Parameters

NameTypeWhat it is
Benchstringrequired
Symbolstringrequired
Sidestringrequired
Volumefloat64required
Sl*float64optionalThe stop, a price; absent for none.
Tp*float64optionalThe target, a price; absent for none.

Returns

(any, error) — the tool’s answer as maps and slices (any).

What it answers

Recorded from a running Bentrix 0.1.382 on a laboratory of generated markets (long lists cut to their first rows):

{
  "bench": "bentrix://lab/lab-1/bench/bench-2",
  "last_answer": {
    "accepted": "buy 0.1"
  },
  "orders": [],
  "positions": []
}

Example

client.Trade.OrderMarket(ctx, mcp.TradeOrderMarketArgs{Bench: bench, Symbol: "SYN-DOCS", Side: "buy", Volume: 0.1})

OrderModify#

Move a stop, a target or a pending price · tool order_modify

scope: labplan: plussince 1.0.0

Sets a position's or a pending order's stop and target (and a pending order's trigger) on a laboratory or paper workbench, as a drag on its chart line does; the venue answers at once. Answers the book. On a real account it goes through the account's agents' mode: proposed in the trade panel for the person's Send (outcome awaiting_person), or under the person's One-click, with real:send, sent as their One-click sends (outcome sent); refused expired past its validity and refused_by_cap past the account's caps.

Declaration

client.Trade
func (a *TradeAPI) OrderModify(ctx context.Context, args TradeOrderModifyArgs) (any, error)

Parameters

NameTypeWhat it is
Benchstringrequired
Ticketint64requiredA position's or a pending order's ticket.
Slfloat64requiredThe new stop, a price; 0 removes it.
Tpfloat64requiredThe new target, a price; 0 removes it.
Price*float64optionalA pending order's new trigger; absent leaves it where it is.

Returns

(any, error) — the tool’s answer as maps and slices (any).

What it answers

Recorded from a running Bentrix 0.1.382 on a laboratory of generated markets (long lists cut to their first rows):

{
  "bench": "bentrix://lab/lab-1/bench/bench-2",
  "last_answer": {
    "filled": "modify 1",
    "stops_rewritten": false,
    "ticket": 1
  },
  "orders": [],
  "positions": [
    {
      "magic": 0,
      "price_current": 0.96831,
      "price_open": 0.96848,
      "profit": -1.7000000000000348,
      "side": "buy",
      "sl": 0.9587952,
      "symbol": "SYN-DOCS",
      "ticket": 1,
      "tp": 0.9781648,
      "volume": 0.1
    },
    {
      "magic": 0,
      "price_current": 5.76316,
      "price_open": 5.76189,
      "profit": -12.699999999998823,
      "side": "sell",
      "sl": 0.0,
      "symbol": "SYN-DOCS2",
      "ticket": 2,
      "tp": 0.0,
      "volume": 0.1
    }
  ]
}

Example

client.Trade.OrderModify(ctx, mcp.TradeOrderModifyArgs{Bench: bench, Ticket: 1, Sl: 0.9587952, Tp: 0.9781648000000001})

OrderPending#

Place a pending order · tool order_pending

scope: labplan: plussince 1.0.0

Places a limit, stop or stop-limit order on a laboratory or paper workbench through the trade panel's own door; the venue answers at once - it rests, or it is refused in its own words (the side rule, the stops level). Answers the book. On a real account it goes through the account's agents' mode: proposed in the trade panel for the person's Send (outcome awaiting_person), or under the person's One-click, with real:send, sent as their One-click sends (outcome sent); refused expired past its validity and refused_by_cap past the account's caps.

Declaration

client.Trade
func (a *TradeAPI) OrderPending(ctx context.Context, args TradeOrderPendingArgs) (any, error)

Parameters

NameTypeWhat it is
Benchstringrequired
Symbolstringrequired
Kindstringrequired
Pricefloat64requiredThe trigger price.
Volumefloat64required
Sl*float64optional
StopLimit*float64optionalA stop-limit's limit price; absent for every other kind.
Tp*float64optional

Returns

(any, error) — the tool’s answer as maps and slices (any).

What it answers

Recorded from a running Bentrix 0.1.382 on a laboratory of generated markets (long lists cut to their first rows):

{
  "bench": "bentrix://lab/lab-1/bench/bench-2",
  "last_answer": {
    "reason": "buy_limit at 1 is on the wrong side of the market (0.9853700000000001)",
    "refused": "buy_limit 0.1"
  },
  "orders": [],
  "positions": [
    {
      "magic": 0,
      "price_current": 0.98529,
      "price_open": 0.98698,
      "profit": -1.6899999999999693,
      "side": "buy",
      "sl": 0.0,
      "symbol": "SYN-DOCS",
      "ticket": 1,
      "tp": 0.0,
      "volume": 0.01
    }
  ]
}

Example

client.Trade.OrderPending(ctx, mcp.TradeOrderPendingArgs{Bench: bench, Symbol: "SYN-DOCS", Kind: "buy_limit", Price: 1.0, Volume: 0.1})

OrderPreview#

Preview an order · tool order_preview

scope: readplan: freesince 1.0.0

Answers what a market order would cost on a laboratory or paper workbench now, from its venue: the fill price, the margin, the commissions, the spread on this size, the nightly swaps and what one point is worth on one lot. Sends nothing.

Declaration

client.Trade
func (a *TradeAPI) OrderPreview(ctx context.Context, args TradeOrderPreviewArgs) (any, error)

Parameters

NameTypeWhat it is
Benchstringrequired
Symbolstringrequired
Sidestringrequired
Volumefloat64required

Returns

(any, error) — the tool’s answer as maps and slices (any).

What it answers

Recorded from a running Bentrix 0.1.382 on a laboratory of generated markets (long lists cut to their first rows):

{
  "commission_close": 0.24,
  "commission_open": 0.24,
  "margin": 96.85,
  "money_per_point": 1.0,
  "price": 0.96849,
  "side": "buy",
  "spread_money": 1.0,
  "swap_long_night": 0.0,
  "swap_short_night": 0.0,
  "symbol": "SYN-DOCS",
  "triple_day": "Wednesday",
  "volume": 0.1
}

Example

client.Trade.OrderPreview(ctx, mcp.TradeOrderPreviewArgs{Bench: bench, Symbol: "SYN-DOCS", Side: "buy", Volume: 0.1})

OrderReverse#

Reverse a position · tool order_reverse

scope: labplan: plussince 1.1.0

Turns a position the other way at the same size, as the trade panel's Reverse does: on a hedging account it is closed and a market order of its size opened the other way; on a netting account one market order of twice its size. Answers the book. On a real account it goes through the account's agents' mode: proposed in the trade panel for the person's Send (outcome awaiting_person), or under the person's One-click, with real:send, sent as their One-click sends (outcome sent); refused expired past its validity and refused_by_cap past the account's caps.

Declaration

client.Trade
func (a *TradeAPI) OrderReverse(ctx context.Context, args TradeOrderReverseArgs) (any, error)

Parameters

NameTypeWhat it is
Benchstringrequired
Ticketint64requiredThe position to turn the other way.

Returns

(any, error) — the tool’s answer as maps and slices (any).

What it answers

Answers the book.

Example

client.Trade.OrderReverse(ctx, mcp.TradeOrderReverseArgs{Bench: bench, Ticket: 1})

OrderTrail#

Trail a position's stop · tool order_trail

scope: labplan: plussince 1.0.0

Arms a trailing stop on a position, the trade panel's own: the stop follows the price at this distance in points, moved by Bentrix while it runs and stopping when Bentrix is shut. Answers the book and the trails armed. On a real account it goes through the account's agents' mode: proposed in the trade panel for the person's Send (outcome awaiting_person), or under the person's One-click, with real:send, armed (outcome sent).

Declaration

client.Trade
func (a *TradeAPI) OrderTrail(ctx context.Context, args TradeOrderTrailArgs) (any, error)

Parameters

NameTypeWhat it is
Benchstringrequired
Ticketint64required
Pointsfloat64requiredThe trail's distance from the price, in the market's points.

Returns

(any, error) — the tool’s answer as maps and slices (any).

What it answers

Answers the book and the trails armed.

Example

client.Trade.OrderTrail(ctx, mcp.TradeOrderTrailArgs{Bench: bench, Ticket: 1, Points: 1.0})

OrderUntrail#

Stop trailing a position's stop · tool order_untrail

scope: labplan: plussince 1.0.0

Disarms a position's trailing stop; the stop stays where the trail last put it. Sends nothing, so on a real account it needs only real. Answers the book and the trails armed.

Declaration

client.Trade
func (a *TradeAPI) OrderUntrail(ctx context.Context, args TradeOrderUntrailArgs) (any, error)

Parameters

NameTypeWhat it is
Benchstringrequired
Ticketint64required

Returns

(any, error) — the tool’s answer as maps and slices (any).

What it answers

Answers the book and the trails armed.

Example

client.Trade.OrderUntrail(ctx, mcp.TradeOrderUntrailArgs{Bench: bench, Ticket: 1})

OrderValidate#

Ask what an order would meet, sending nothing · tool order_validate

scope: labplan: plussince 1.22.0

Answers what an order of this volume would meet on a workbench, and sends and proposes nothing: on a real account its agents' mode (confirm or one_click), whether it would be sent, proposed in the panel's sheet for the person's Send, or refused and why (its validity, the volume cap, the orders and lots of the rolling hour), the caps and what of them is used, whether a proposal already waits, the daily loss cap; on a laboratory or paper workbench that Bentrix's venue answers it at send.

Declaration

client.Trade
func (a *TradeAPI) OrderValidate(ctx context.Context, args TradeOrderValidateArgs) (any, error)

Parameters

NameTypeWhat it is
Benchstringrequired
Volumefloat64requiredThe lots the order would carry.
Market*booloptionalA market order (validity of a market order); false for a pending order, a modify or a close.
Opens*float64optionalThe lots it would open: the volume for a new order (the default), 0 for a close or a modify.

Returns

(any, error) — the tool’s answer as maps and slices (any).

What it answers

Recorded from a running Bentrix 0.1.382 on a laboratory of generated markets (long lists cut to their first rows):

{
  "bench": "bentrix://lab/lab-1/bench/bench-2",
  "venue": "Bentrix's own venue answers the order when it is sent: its volume bounds, its stops, its margin.",
  "would": "send"
}

Example

client.Trade.OrderValidate(ctx, mcp.TradeOrderValidateArgs{Bench: bench, Volume: 0.1})

AgentMode#

Read a real account's Automations mode · tool trade_agent_mode

scope: readplan: freesince 1.0.0

Answers, read only, a real account's Automations mode for this sitting - confirm or one_click - its caps (lots an order, orders and lots opened an hour), what of them this hour has used, a proposal standing, and whether this agent holds real and real:send. Never sets anything: the mode and the caps are the person's.

Declaration

client.Trade
func (a *TradeAPI) AgentMode(ctx context.Context, args TradeAgentModeArgs) (any, error)

Parameters

NameTypeWhat it is
AccountstringrequiredThe account's uri, as get_state gives it.

Returns

(any, error) — the tool’s answer as maps and slices (any).

What it answers

What the tool's description says.

Example

client.Trade.AgentMode(ctx, mcp.TradeAgentModeArgs{Account: account})

Bentrix 0.1.382Every number, name and default on these pages is read from the application itself.What is comingWhat changed