Add stop limit order helper
This commit is contained in:
parent
722254140b
commit
85da22cf2b
@ -1,23 +1,33 @@
|
|||||||
from .instrument_type import EQUITY_OPTION
|
from .instrument_type import EQUITY_OPTION
|
||||||
from .order_action import SELL_TO_OPEN, BUY_TO_OPEN
|
from .order_action import BUY_TO_CLOSE, BUY_TO_OPEN, SELL_TO_CLOSE, SELL_TO_OPEN
|
||||||
from .order_type import LIMIT
|
from .order_type import LIMIT, STOP_LIMIT
|
||||||
from .price_effect import CREDIT
|
from .price_effect import CREDIT, DEBIT
|
||||||
from .time_in_force import GTC
|
from .time_in_force import GTC
|
||||||
|
|
||||||
def create_leg(instrument_type: str, symbol: str, action: str, quantity: int):
|
def create_leg(instrument_type: str, symbol: str, action: str, quantity: int):
|
||||||
return {'instrument-type': instrument_type, 'symbol': symbol, 'action': action, 'quantity': quantity}
|
return {'instrument-type': instrument_type, 'symbol': symbol, 'action': action, 'quantity': quantity}
|
||||||
|
|
||||||
def create_order(order_type: str, time_in_force: str, price: float, price_effect: str, legs: list):
|
def create_order(order_type: str, time_in_force: str, price: float, price_effect: str, legs: list,
|
||||||
return {
|
stop_trigger: float = None):
|
||||||
|
order = {
|
||||||
'order-type': order_type,
|
'order-type': order_type,
|
||||||
'time-in-force': time_in_force,
|
'time-in-force': time_in_force,
|
||||||
'price': price,
|
'price': price,
|
||||||
'price-effect': price_effect,
|
'price-effect': price_effect,
|
||||||
'legs': legs
|
'legs': legs
|
||||||
}
|
}
|
||||||
|
if stop_trigger:
|
||||||
|
order['stop-trigger'] = stop_trigger
|
||||||
|
return order
|
||||||
|
|
||||||
def create_credit_spread(short_contract: str, long_contract: str, price: float, quantity: int,
|
def create_credit_spread(short_contract: str, long_contract: str, price: float, quantity: int,
|
||||||
instrument_type: str = EQUITY_OPTION, time_in_force: str = GTC):
|
instrument_type: str = EQUITY_OPTION, time_in_force: str = GTC):
|
||||||
short_leg = create_leg(instrument_type, short_contract, SELL_TO_OPEN, quantity)
|
short_leg = create_leg(instrument_type, short_contract, SELL_TO_OPEN, quantity)
|
||||||
long_leg = create_leg(instrument_type, long_contract, BUY_TO_OPEN, quantity)
|
long_leg = create_leg(instrument_type, long_contract, BUY_TO_OPEN, quantity)
|
||||||
return create_order(LIMIT, time_in_force, price, CREDIT, [short_leg, long_leg])
|
return create_order(LIMIT, time_in_force, price, CREDIT, [short_leg, long_leg])
|
||||||
|
|
||||||
|
def create_stop_limit_order(short_contract: str, long_contract: str, stop_trigger: float, limit_price: float,
|
||||||
|
quantity: int, instrument_type: str = EQUITY_OPTION, time_in_force: str = GTC):
|
||||||
|
short_leg = create_leg(instrument_type, short_contract, BUY_TO_CLOSE, quantity)
|
||||||
|
long_leg = create_leg(instrument_type, long_contract, SELL_TO_CLOSE, quantity)
|
||||||
|
return create_order(STOP_LIMIT, time_in_force, limit_price, DEBIT, [short_leg, long_leg], stop_trigger)
|
Loading…
Reference in New Issue
Block a user