Skip to content

Conversation

Shiv-Expert2503
Copy link

Issue

Resolves: #207 - GTT orders missing tag parameter support

Problem

Placing regular orders supports the tag parameter, but the place_gtt() method in the Python client does not expose it. This forces users to maintain external mapping to trace GTT-triggered orders back to their strategies.

Solution

Extended place_gtt() and modify_gtt() methods to include an optional tag parameter and forward it to the API request.

Changes Made

Core Implementation (kiteconnect/connect.py)

  • Modified _get_gtt_payload() to accept optional tag parameter
  • Updated place_gtt() method signature to include tag=None
  • Updated modify_gtt() method signature to include tag=None
  • Added conditional logic to include tag in API payload when provided

Testing (tests/unit/test_connect.py)

  • Added test_place_gtt_with_tag() test case
  • Added test_modify_gtt_with_tag() test case
  • All 46 existing tests continue to pass

Documentation (examples/gtt_order.py)

  • Added tag parameter usage examples for both single and OCO GTT orders
  • Included descriptive comments explaining functionality
  • Note: Tag values ("my_strategy_1", "my_strategy_2") are example placeholders

Usage Examples

Single GTT with tag

kite.place_gtt(
    trigger_type=kite.GTT_TYPE_SINGLE,
    tradingsymbol="SBIN",
    exchange="NSE",
    trigger_values=[470],
    last_price=473,
    orders=orders,
    tag="my_trading_strategy"  # NEW: Optional tag parameter
)

kite.place_gtt(
    trigger_type=kite.GTT_TYPE_OCO,
    tradingsymbol="SBIN",
    exchange="NSE",
    trigger_values=[470, 480],
    last_price=473,
    orders=orders,
    tag="risk_management_strategy"  # NEW: Optional tag parameter
)

Backward Compatibility

  • Zero breaking changes - All existing code continues to work
  • Optional parameter - tag=None by default
  • API consistency - Follows same pattern as regular place_order() method

Testing

  • Added 2 new test cases for tag functionality
  • All 46 unit tests pass
  • New tag functionality thoroughly tested
  • Manual testing completed with mock responses

Impact

  • Users can now trace GTT orders to strategies without external mapping
  • Improved order management and debugging capabilities
  • Enhanced integration with trading strategy frameworks

- Add optional tag parameter to place_gtt() and modify_gtt() methods
- Update _get_gtt_payload() to handle tag parameter
- Maintain backward compatibility with tag=None default
- Enable order tracing for GTT-triggered trades

Fixes: zerodha#207 - GTT orders missing tag parameter support
- Add test_place_gtt_with_tag() test case
- Add test_modify_gtt_with_tag() test case
- Ensure tag parameter is properly handled in GTT operations
- Maintain 100% test coverage for new functionality
- Add tag parameter examples for single and OCO GTT orders
- Include descriptive comments explaining tag functionality
- Provide practical usage patterns for strategy identification
- Note: tag values are example placeholders for demonstration
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.

Add tag parameter support in place_gtt() for Python client

1 participant