Skip to content

Add pending order cancellation and multi-order support #88

@Significant-Hacks

Description

@Significant-Hacks

Proposal

Add pending order cancellation functionality to the PocketOption API, including support for multiple concurrent pending orders and batch cancellation operations.

Problem Statement

The current pending order implementation in PendingTradesHandle only supports creating and retrieving pending orders, but lacks cancellation capabilities 1 . Additionally, the module is designed for single pending order workflows, stating "at most one OpenPendingOrder request is in-flight at any given time per client" 2 . This prevents implementation of complex trading strategies like martingale that require managing multiple pending orders simultaneously and canceling them when earlier levels succeed.

Suggested Implementation

  1. Add cancellation method to Rust core: Implement cancel_pending_order(ticket: String) in PendingTradesHandle
  2. Add batch cancellation: Implement cancel_pending_orders(tickets: Vec<String>) for multiple orders
  3. Update state management: Modify the last_req_id tracking to support multiple concurrent pending orders
  4. Add Python bindings: Expose cancellation methods in both synchronous and asynchronous Python APIs
  5. Update PendingOrder type: Ensure order status tracking for cancellation confirmation

Use Case

import asyncio
from BinaryOptionsToolsV2 import PocketOptionAsync

async def martingale_strategy():
    client = PocketOptionAsync(ssid="your_ssid")
    
    # Place initial pending order
    order1 = await client.open_pending_order(
        open_type=0, amount=10.0, asset="GBP/AUD_otc",
        open_time=1642695900, open_price=1.8450,
        timeframe=300, min_payout=80, command=0
    )
    
    # Place martingale level orders
    order2 = await client.open_pending_order(
        open_type=0, amount=20.0, asset="GBP/AUD_otc",
        open_time=1642696200, open_price=1.8450,
        timeframe=300, min_payout=80, command=0
    )
    
    order3 = await client.open_pending_order(
        open_type=0, amount=40.0, asset="GBP/AUD_otc", 
        open_time=1642696500, open_price=1.8450,
        timeframe=300, min_payout=80, command=0
    )
    
    # Monitor first order result
    result = await client.check_win(order1["id"])
    
    # If first order wins, cancel remaining martingale levels
    if result["profit"] > 0:
        await client.cancel_pending_order(order2["ticket"])
        await client.cancel_pending_order(order3["ticket"])
        print("Martingale levels cancelled - initial order won")
    else:
        print("Continuing with martingale strategy")

asyncio.run(martingale_strategy())

Benefits

  1. Enables complex trading strategies: Martingale, grid trading, and multi-level strategies require order cancellation capabilities
  2. Risk management: Allows traders to limit exposure by canceling unneeded orders
  3. API completeness: Cancellation is a standard feature in trading APIs and its absence limits the library's utility
  4. Competitive advantage: Other trading libraries support order cancellation, making this essential for adoption
  5. Resource efficiency: Prevents unnecessary order execution and reduces broker-side load

The pending order feature is currently marked as BETA 3 , making this an ideal time to enhance it with full CRUD operations before stable release.

Wiki pages you might want to explore:

Citations

File: README.md (L242-244)

- [x] **PocketOption**: Quick Trading
- [x] **PocketOption**: Pending Orders (BETA)
- [ ] **Platform**: Expert Options Integration

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions