trade29.sc.SCBridge.get_filled_orders#

SCBridge.get_filled_orders(key: str) FilledOrdersResponse#

Gets data on filled orders from Sierra Chart.

Given a key, this method gets information on the filled orders from the same chart on which the SC-dX study with the matching key is applied.

Parameters:
keystr

The key matching the key given to the SC-dX custom study in Sierra Chart.

Returns:
FilledOrdersResponse

Examples

>>> from trade29.sc import SCBridge, constants
>>> bridge = SCBridge()
running bridge v0.17.0--------2024/08/07 18:11:45
connecting to sc
starting receiver
starting sender
sc version: 2666, scdx version 208, connection: t29scdx2, keys: xx
>>> bridge.submit_order(key = "xx", is_buy = False, quantity = 5, order_type = constants.OrderType.MARKET)
>>> # Submit a market order that gets filled immediately
>>> ret0 = bridge.get_filled_orders(key = "xx")
>>> # One order shows as filled
>>> ret0.as_df()
                            Symbol TradeAccount  ...  IsSimulated                                  OrderActionSource  Note
FillDateTime                                     ...
2024-08-07 18:11:47.518736  XAUUSD         Sim1  ...            1  Trade simulation fill. Bid: 2388.95 Ask: 2389....
>>> # Submit a limit order below the current price
>>> # NOTE: reversals were disabled in study settings for this example
>>> bridge.submit_order(key = "xx", is_buy = True, quantity = 7, order_type = constants.OrderType.LIMIT, price1 = 2378)
>>> ret1 = bridge.get_filled_orders(key = "xx")
>>> # Limit order hasn't been filled, so it doesn't show
>>> ret1.as_df()
                            Symbol TradeAccount  ...  IsSimulated                                  OrderActionSource  Note
FillDateTime                                     ...
2024-08-07 18:11:47.518736  XAUUSD         Sim1  ...            1  Trade simulation fill. Bid: 2388.95 Ask: 2389....
>>> from trade29.sc import SCBridge, constants
>>> bridge = SCBridge()
running bridge v0.17.0--------2024/08/07 18:19:31
connecting to sc
starting receiver
starting sender
sc version: 2666, scdx version 208, connection: t29scdx2, keys: xx
>>> bridge.submit_order(key = "xx", is_buy = False, quantity = 4, order_type = constants.OrderType.MARKET)
>>> # Reverse the position. This will create 2 orders, one to flatten and one to enter a long position of quantity 5
>>> bridge.submit_order(key = "xx", is_buy = True, quantity = 5, order_type = constants.OrderType.MARKET)
>>> ret = bridge.get_filled_orders(key = "xx")
>>> ret.as_df()
                            Symbol TradeAccount  Internal ...  IsSimulated                                  OrderActionSource  Note
FillDateTime                                              ...
2024-08-07 18:20:04.958229  XAUUSD         Sim1           ...            1  Trade simulation fill. Bid: 2387.80 Ask: 2388....
2024-08-07 18:20:18.765551  XAUUSD         Sim1           ...            1  Trade simulation fill. Bid: 2388.30 Ask: 2388....
2024-08-07 18:20:18.765622  XAUUSD         Sim1           ...            1  Trade simulation fill. Bid: 2388.30 Ask: 2388....
>>> # We can sort differently!
>>> ret.as_df(sort_datetime_ascending=False) 
                            Symbol TradeAccount  Internal ...  IsSimulated                                  OrderActionSource  Note
FillDateTime                                              ...
2024-08-07 18:20:18.765622  XAUUSD         Sim1           ...            1  Trade simulation fill. Bid: 2388.30 Ask: 2388....
2024-08-07 18:20:18.765551  XAUUSD         Sim1           ...            1  Trade simulation fill. Bid: 2388.30 Ask: 2388....
2024-08-07 18:20:04.958229  XAUUSD         Sim1           ...            1  Trade simulation fill. Bid: 2387.80 Ask: 2388....
>>> # We can also use integer indices, this will still respect the datetime sort
>>> ret.as_df(sort_datetime_ascending=False, datetime_index=False)   
                FillDateTime  Symbol TradeAccount  ...  IsSimulated                                  OrderActionSource  Note
0 2024-08-07 18:20:18.765622  XAUUSD         Sim1  ...            1  Trade simulation fill. Bid: 2388.30 Ask: 2388....
1 2024-08-07 18:20:18.765551  XAUUSD         Sim1  ...            1  Trade simulation fill. Bid: 2388.30 Ask: 2388....
2 2024-08-07 18:20:04.958229  XAUUSD         Sim1  ...            1  Trade simulation fill. Bid: 2387.80 Ask: 2388....
>>> # The df will still be sorted even if we dont include datetime!
>>> ret.as_df(sort_datetime_ascending=False, datetime_index=False, include_datetime=False)
   Symbol TradeAccount  InternalOrderID ...  IsSimulated                                  OrderActionSource  Note
0  XAUUSD         Sim1              359 ...            1  Trade simulation fill. Bid: 2388.30 Ask: 2388....
1  XAUUSD         Sim1              358 ...            1  Trade simulation fill. Bid: 2388.30 Ask: 2388....    
2  XAUUSD         Sim1              357 ...            1  Trade simulation fill. Bid: 2387.80 Ask: 2388....