Submit stop limit order following successful fill
This commit is contained in:
parent
034769ffc0
commit
ec4067deb6
@ -85,7 +85,7 @@ call_credit_spread = create_credit_spread(
|
||||
call_spread_limit_price, 1
|
||||
)
|
||||
|
||||
entry_time = datetime.now(timezone.utc).isoformat()
|
||||
entry_time = datetime.now(timezone.utc)
|
||||
|
||||
put_spread_result = tastytrade_client.submit_order(tastytrade_account, put_credit_spread)
|
||||
call_spread_result = tastytrade_client.submit_order(tastytrade_account, call_credit_spread)
|
||||
@ -104,7 +104,7 @@ def fill_time(position):
|
||||
def wait_for_fill():
|
||||
while True:
|
||||
positions = tastytrade_client.get_positions(tastytrade_account)
|
||||
positions = positions.get('data', {}).get('items', [])
|
||||
positions = positions.get('data', {}).get('items', []) # TODO: Client should handle this.
|
||||
print(positions)
|
||||
# Consider only positions created after the order was submitted.
|
||||
new_positions = [position for position in positions if fill_time(position) > entry_time]
|
||||
@ -127,3 +127,27 @@ put_spread_fill_price, call_spread_fill_price = wait_for_fill()
|
||||
|
||||
print(f'Put Spread Fill Price: {put_spread_fill_price}')
|
||||
print(f'Call Spread Fill Price: {call_spread_fill_price}')
|
||||
|
||||
put_spread_stop = put_spread_fill_price * 2.0
|
||||
put_spread_stop_order = create_stop_limit_order(
|
||||
contract(PUT, short_put_strike),
|
||||
contract(PUT, long_put_strike),
|
||||
stop_trigger = put_spread_stop - 0.25, # Allow for slippage.
|
||||
limit_price = put_spread_stop,
|
||||
quantity = 1
|
||||
)
|
||||
|
||||
call_spread_stop = call_spread_fill_price * 2.0
|
||||
call_spread_stop_order = create_stop_limit_order(
|
||||
contract(CALL, short_call_strike),
|
||||
contract(CALL, long_call_strike),
|
||||
stop_trigger = call_spread_stop - 0.25, # Allow for slippage.
|
||||
limit_price = call_spread_stop,
|
||||
quantity = 1
|
||||
)
|
||||
|
||||
put_spread_stop_result = tastytrade_client.submit_order(tastytrade_account, put_spread_stop_order)
|
||||
call_spread_stop_result = tastytrade_client.submit_order(tastytrade_account, call_spread_stop_order)
|
||||
|
||||
print(put_spread_stop_result)
|
||||
print(call_spread_stop_result)
|
Loading…
Reference in New Issue
Block a user