Repository navigation
fix(futures-paper): net triggered order margin against opposite-side positions - #56
Closed
theghostmac wants to merge 1 commit into
Closed
theghostmac wants to merge 1 commit into
theghostmac wants to merge 1 commit into
Conversation
Contributor
|
Thanks @theghostmac! This is fixed in v0.5.0. Stop, take-profit and trailing-stop orders now net their margin against an opposite position. We ported your fix to the new |
needaccforwhonix
pushed a commit
to needaccforwhonix/kraken-cli
that referenced
this pull request
Nov 7, 2026
Sign in from the browser to create a restricted, expiring Spot API key. The MCP server and the REPL ship as their own binaries, kraken-mcp and kraken-shell, installed next to kraken. A paper strategy can go live in a budget-fenced workspace, and a finished session packages as a recipe. A timed-out order, cancel, withdrawal or transfer is never resent, and an envelope that may hide an execution carries "verify_first": true. Upgrading from 0.4.1 needs action from scripts, agents and MCP clients: see CHANGELOG.md under 0.5.0. Includes community fixes from krakenfx#50, krakenfx#51, krakenfx#54, krakenfx#55 and krakenfx#56. Co-authored-by: theghostmac <83423188+theghostmac@users.noreply.github.com> Co-authored-by: SashaMIT <33847880+SashaMIT@users.noreply.github.com> Co-authored-by: sashaphmn <122053040+sashaphmn@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Aligns initial margin calculation in
FuturesPaperState::place_triggered_order(stop,take-profit,trailing-stop) withplace_limit_orderandedit_orderby delegating tocompute_margin_delta.Root Cause
place_limit_order(src/futures_paper.rs:424) andedit_order(src/futures_paper.rs:963) both compute required margin viacompute_margin_delta/compute_margin_delta_for_size, which nets order size against any existing opposite-side position ((size - opposite_pos_size).max(0.0)).place_triggered_order(src/futures_paper.rs:671) computednotional / leveragedirectly without callingcompute_margin_delta.reduce_onlystop, take-profit, or trailing-stop order against an existing opposite-side position double-reserved margin (+850.00on a0.1 BTCstop buy at$85,00010xwhile holding a0.1 BTCshort).edit_orderrecalculatedreserved_marginusingcompute_margin_delta_for_size, causingreserved_marginto abruptly drop from850.00to0.00.Fix
FuturesPaperState::place_triggered_order, computeeff_price = params.price.unwrap_or(stop_price)and delegate margin calculation toself.compute_margin_delta(params, eff_price, leverage).triggered_order_nets_margin_against_opposite_position.Verification & CLI Proof
With an open
0.1 BTCShort position onPF_XBTUSDat$82,799.00(10xleverage,Used Margin = 827.99):Before Fix
Used Marginjumped by+850.00from827.99to1677.99:After Fix
Used Marginstays at827.99(net new exposure is0.0), consistent withplace_limit_orderandedit_order:Automated Tests & Lints
cargo +nightly fmt --checkcargo clippy --all-targets -- -D warningscargo test --lib triggered_order_nets_margin_against_opposite_position