Skip to content

Commit 37cf309

Browse files
luisleo526claude
andcommitted
Merge pull request 751 (honor quantity grids in default entry size queries)
Merges the head d150f41 of the branch fix/default-entry-quantity-query into engine main 819b200. The merge is a plain merge commit: no rebase, no conflict resolution. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2 parents 819b200 + d150f41 commit 37cf309

4 files changed

Lines changed: 400 additions & 0 deletions

File tree

‎include/pineforge/source/pine_strategy_host.hpp‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,15 @@ class PineStrategyHost : public NativeStrategyHost, public BrokerStateHashProvid
13991399
#ifdef PINEFORGE_HAS_AUX_SECURITY_FEED_V1
14001400
void release_aux_security_chart_ranges();
14011401
#endif
1402+
1403+
public:
1404+
// During a source calculation, query the configured default entry units
1405+
// at the supplied fill price, using the current sizing equity, FX, point
1406+
// value, fee policy and quantity grid. Fixed sizing ignores the supplied
1407+
// price; money sizing returns zero for NaN or zero and signed grid units
1408+
// for a negative price. Observation only: no order is placed and no driver
1409+
// point advances.
1410+
double default_entry_qty(double fill_price) const;
14021411
};
14031412

14041413
using PineNativeHost = PineStrategyHost;

‎src/source/pine_adapter.cpp‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28794,6 +28794,29 @@ void PineExecutionAdapter::begin_position_tail_summary() {
2879428794
}
2879528795
}
2879628796

28797+
double PineStrategyHost::default_entry_qty(double fill_price) const {
28798+
// TradingView does not validate this query's hypothetical price before
28799+
// applying the declared sizing mode: fixed sizing ignores it, while
28800+
// money sizing returns zero for NaN/zero and a signed grid quantity for
28801+
// a negative price. Observation only: no order or driver state changes.
28802+
if (adapter_.config_.default_qty_type == static_cast<int>(QtyType::FIXED)) {
28803+
return floor_quantity_grid(adapter_.config_.default_qty_value,
28804+
adapter_.staged_.quantity_grid);
28805+
}
28806+
auto sizing = adapter_.sizing_snapshot();
28807+
sizing.price = fill_price;
28808+
if (!std::isfinite(fill_price) || fill_price == 0.0) return 0.0;
28809+
if (fill_price > 0.0) return adapter_.default_sizing_units(sizing);
28810+
sizing.price = -fill_price;
28811+
const auto sized = adapter_.default_sizing_shape(sizing);
28812+
if (!sized) return 0.0;
28813+
const auto units = native_sized_units(
28814+
*sized, -fill_price, sizing.equity, sizing.fx);
28815+
// The core computes the positive-magnitude quotient once; apply the source
28816+
// lot floor before restoring the negative hypothetical price's sign.
28817+
return units ? -adapter_.default_sizing_lot_floor(*units) : 0.0;
28818+
}
28819+
2879728820
} // namespace pineforge::source
2879828821

2879928822
#include "exit_payload_codec.inc"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Source-host default entry quantity observation unit test.
2+
if(PINEFORGE_BUILD_SOURCE_LAYER)
3+
list(APPEND TEST_SOURCES test_default_entry_qty)
4+
pineforge_add_unit_test(test_default_entry_qty)
5+
endif()

0 commit comments

Comments
 (0)