Skip to content

feat: add peg, chaser, and trailing-stop order types#23

Open
vkbalakrishnan wants to merge 1 commit into
BitMEX:masterfrom
vkbalakrishnan:feat/peg-chaser-order-types
Open

feat: add peg, chaser, and trailing-stop order types#23
vkbalakrishnan wants to merge 1 commit into
BitMEX:masterfrom
vkbalakrishnan:feat/peg-chaser-order-types

Conversation

@vkbalakrishnan

Copy link
Copy Markdown
Contributor

What

Adds first-class support for BitMEX pegged, chaser, and trailing-stop orders — on the CLI and as MCP tools.

Why

order buy|sell already forwarded --order-type/--exec-inst as freeform strings, so the labels Pegged/Fixed/ChaserClassic were reachable — but there were no flags for pegPriceType or pegOffsetValue, the two fields every one of these order types requires. As a result none of them could actually be placed via the CLI or its MCP tools.

What changed

Primitive flags (thin pass-through) on buy/sell:

  • --peg-price-type <PrimaryPeg|MarketPeg|TrailingStopPeg|LastPeg|MidPricePeg>
  • --peg-offset-value <N>
  • --peg-offset-value also added to amend (amend a live peg without cancel/replace).

Guided subcommands that set ordType/execInst and validate the offset sign locally:

  • order chase <symbol> <side> <qty> --offset N [--bothways]Pegged + ChaserClassic/ChaserBothways; re-prices to follow the top of book.
  • order trailing-stop <symbol> <side> <qty> --offset N [--limit-price P] [--trigger T]Stop/StopLimit + TrailingStopPeg.

Sign-convention safety

The two guided commands enforce the pegOffsetValue sign client-side, returning a validation error before the order reaches the exchange. The rules are opposite, which is exactly the footgun this guards:

  • Chaser: Buy offset ≤ 0, Sell offset ≥ 0 (rests passively behind the touch; max 5/account).
  • Trailing stop: Sell offset ≤ 0, Buy offset ≥ 0.

MCP + docs

  • agents/tool-catalog.json: peg params on order buy/order sell, peg_offset_value on amend, and new order chase / order trailing-stop entries with oneOf enums. Also fixes pre-existing drift where the order sell entry was missing tif/exec_inst (needed for chaser/pegged via the primitive path over MCP).
  • Docs: README.md, CONTEXT.md, AGENTS.md, CLAUDE.md.

Examples

# Pegged limit (requires exec_inst Fixed)
bitmex order buy XBTUSD 100 --order-type Pegged --exec-inst Fixed \
  --peg-price-type PrimaryPeg --peg-offset-value -1

# Chaser
bitmex order chase XBTUSD Buy  100 --offset -1
bitmex order chase XBTUSD Sell 100 --offset  1 --bothways

# Trailing stop
bitmex order trailing-stop XBTUSD Sell 100 --offset -100
bitmex order trailing-stop XBTUSD Sell 100 --offset -100 --limit-price 49000

Testing

  • Unit (order.rs): as_api mappings, build_order_body peg fields, chase/trailing sign rules, ordType/execInst selection.
  • MCP (registry.rs, server.rs): new tools registered with correct schema; full MCP→CLI arg routing for the side positional + hyphen-value --offset.
  • Integration (cli_tests.rs): --help for the new subcommands; --validate dry-runs assert the emitted body and sign rejection.
  • cargo test (112 lib + 22 integration) green; cargo clippy clean on order.rs.

Semantics grounded in BitMEX's swagger.json, the engine's NewOrderChaserValidator, and the Chaser order blog post.

order buy|sell forwarded --order-type/--exec-inst as freeform strings, so the
Pegged/Fixed/ChaserClassic labels were reachable — but pegPriceType and
pegOffsetValue had no flags, so none of these order types could actually be placed.

Add first-class support:
- Primitive --peg-price-type / --peg-offset-value flags on buy/sell (and
  --peg-offset-value on amend), mapping straight to the API fields.
- order chase <symbol> <side> <qty> --offset N [--bothways] — Pegged +
  ChaserClassic/ChaserBothways; re-prices to follow the top of book.
- order trailing-stop <symbol> <side> <qty> --offset N [--limit-price P]
  [--trigger T] — Stop/StopLimit + TrailingStopPeg.

Both guided commands enforce the pegOffsetValue sign convention client-side
(chaser: buy <= 0, sell >= 0; trailing: sell <= 0, buy >= 0 — the opposite),
returning a validation error before the order reaches the exchange.

Expose the new params/commands as MCP tools in agents/tool-catalog.json (also
fixes the order sell entry's missing tif/exec_inst). Docs updated in README,
CONTEXT, AGENTS, and CLAUDE.

Tests: unit coverage for sign rules, body construction, and MCP arg routing;
integration --help and --validate dry-run tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants