|
74 | 74 | # Test 9: no op |
75 | 75 | @test calc_exposure_increase_quantity(0, 0) == 0 |
76 | 76 | end |
| 77 | + |
| 78 | +@testitem "mark_price set on fills and marks" begin |
| 79 | + using Test, Fastback, Dates |
| 80 | + |
| 81 | + acc = Account() |
| 82 | + deposit!(acc, Cash(:USD), 10_000.0) |
| 83 | + inst = register_instrument!(acc, Instrument(Symbol("MK/USD"), :MK, :USD)) |
| 84 | + |
| 85 | + # Fill long; mark should be fill price |
| 86 | + order = Order(oid!(acc), inst, DateTime(2026, 1, 1), 100.0, 1.0) |
| 87 | + trade = fill_order!(acc, order, order.date, order.price) |
| 88 | + pos = get_position(acc, inst) |
| 89 | + @test pos.mark_price == 100.0 |
| 90 | + |
| 91 | + # Update with bid/ask; long uses bid as close |
| 92 | + update_pnl!(acc, inst, 101.0, 102.0) |
| 93 | + @test pos.mark_price == 101.0 |
| 94 | + |
| 95 | + # Flip to short; mark on fill should update |
| 96 | + order2 = Order(oid!(acc), inst, DateTime(2026, 1, 2), 103.0, -2.0) |
| 97 | + fill_order!(acc, order2, order2.date, order2.price) |
| 98 | + @test pos.mark_price == 103.0 |
| 99 | + |
| 100 | + # For short, close price comes from ask |
| 101 | + update_pnl!(acc, inst, 98.0, 99.0) |
| 102 | + @test pos.mark_price == 99.0 |
| 103 | +end |
0 commit comments