Submit stop limit order following successful fill

This commit is contained in:
moshferatu 2023-09-22 08:06:26 -07:00
parent 034769ffc0
commit ec4067deb6

View File

@ -85,7 +85,7 @@ call_credit_spread = create_credit_spread(
call_spread_limit_price, 1 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) put_spread_result = tastytrade_client.submit_order(tastytrade_account, put_credit_spread)
call_spread_result = tastytrade_client.submit_order(tastytrade_account, call_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(): def wait_for_fill():
while True: while True:
positions = tastytrade_client.get_positions(tastytrade_account) 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) print(positions)
# Consider only positions created after the order was submitted. # Consider only positions created after the order was submitted.
new_positions = [position for position in positions if fill_time(position) > entry_time] new_positions = [position for position in positions if fill_time(position) > entry_time]
@ -126,4 +126,28 @@ def wait_for_fill():
put_spread_fill_price, call_spread_fill_price = wait_for_fill() put_spread_fill_price, call_spread_fill_price = wait_for_fill()
print(f'Put Spread Fill Price: {put_spread_fill_price}') print(f'Put Spread Fill Price: {put_spread_fill_price}')
print(f'Call Spread Fill Price: {call_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)