Exemple #1
0
def order_option_spread(direction, price, symbol, quantity, spread, timeInForce='gfd'):
    """Submits a limit order for an option spread. i.e. place a debit / credit spread

    :param direction: credit or debit spread
    :type direction: str
    :param price: The limit price to trigger a trade of the option.
    :type price: float
    :param symbol: The stock ticker of the stock to trade.
    :type symbol: str
    :param quantity: The number of options to trade.
    :type quantity: int
    :param spread: A dictionary of spread options with the following keys: \n
        - expirationDate: The expiration date of the option in 'YYYY-MM-DD' format.\n
        - strike: The strike price of the option.\n
        - optionType: This should be 'call' or 'put'
    :type spread: dict
    :param timeInForce: Changes how long the order will be in effect for.
     'gtc' = good until cancelled. \
     'gfd' = good for the day. 'ioc' = immediate or cancel. 'opg' execute at opening.
    :type timeInForce: Optional[str]
    :returns: Dictionary that contains information regarding the selling of options, \
    such as the order id, the state of order (queued,confired,filled, failed, canceled, etc.), \
    the price, and the quantity.
    """
    try:
        symbol = symbol.upper().strip()
    except AttributeError as message:
        print(message)
        return None
    legs = []
    for each in spread:
        optionID = helper.id_for_option(symbol,
                                        each['expirationDate'],
                                        each['strike'],
                                        each['optionType'])
        legs.append({'position_effect': each['effect'],
                     'side' : each['action'],
                     'ratio_quantity': 1,
                     'option': urls.option_instruments(optionID)})

    payload = {
        'account': profiles.load_account_profile(info='url'),
        'direction': direction,
        'time_in_force': timeInForce,
        'legs': legs,
        'type': 'limit',
        'trigger': 'immediate',
        'price': price,
        'quantity': quantity,
        'override_day_trade_checks': False,
        'override_dtbp_checks': False,
        'ref_id': str(uuid4()),
    }

    url = urls.option_orders()
    data = helper.request_post(url,payload, json=True)

    return(data)
def order_sell_option_limit(positionEffect, price, symbol, quantity, expirationDate, strike, optionType='both', timeInForce='gfd'):
    """Submits a limit order for an option. i.e. place a short call or a short put.

    :param positionEffect: Either 'open' for a sell to open effect or 'close' for a sell to close effect.
    :type positionEffect: str
    :param price: The limit price to trigger a sell of the option.
    :type price: float
    :param symbol: The stock ticker of the stock to trade.
    :type symbol: str
    :param quantity: The number of options to sell.
    :type quantity: int
    :param expirationDate: The expiration date of the option in 'YYYY-MM-DD' format.
    :type expirationDate: str
    :param strike: The strike price of the option.
    :type strike: float
    :param optionType: This should be 'call' or 'put'
    :type optionType: str
    :param timeInForce: Changes how long the order will be in effect for. 'gtc' = good until cancelled. \
    'gfd' = good for the day. 'ioc' = immediate or cancel. 'opg' execute at opening.
    :type timeInForce: Optional[str]
    :returns: Dictionary that contains information regarding the selling of options, \
    such as the order id, the state of order (queued,confired,filled, failed, canceled, etc.), \
    the price, and the quantity.

    """
    try:
        symbol = symbol.upper().strip()
    except AttributeError as message:
        print(message)
        return None

    optionID = helper.id_for_option(symbol, expirationDate, strike, optionType)
	
    if (positionEffect == 'close'):
        direction = 'debit'
    else:
        direction = 'credit'

    payload = {
    'account': profiles.load_account_profile(info='url'),
    'direction': direction,
    'time_in_force': timeInForce,
    'legs': [
        {'position_effect': positionEffect, 'side' : 'sell', 'ratio_quantity': 1, 'option': urls.option_instruments(optionID) },
    ],
    'type': 'limit',
    'trigger': 'immediate',
    'price': price,
    'quantity': quantity,
    'override_day_trade_checks': False,
	'override_dtbp_checks': False,
    'ref_id': str(uuid4()),
    }

    url = urls.option_orders()
    data = helper.request_post(url, payload, json=True)

    return(data)
Exemple #3
0
def get_option_order_info(order_id):
    """Returns the information for a single option order.

    :param order_id: The ID associated with the option order.
    :type order_id: str
    :returns: Returns a list of dictionaries of key/value pairs for the order.

    """
    url = urls.option_orders(order_id)
    data = helper.request_get(url)
    return data
Exemple #4
0
def order_option_by_id(option_id,
                       price,
                       quantity,
                       direction='credit',
                       effect='close',
                       side='sell',
                       time_in_force='gfd'):
    """

    :param option_id:
    :param price:
    :param quantity:
    :param direction:
    :param effect:
    :param side:
    :param time_in_force:
    :return:
    """

    payload = {
        'account':
        profiles.load_account_profile(info='url'),
        'direction':
        direction,
        'time_in_force':
        time_in_force,
        'legs': [
            {
                'position_effect': effect,
                'side': side,
                'ratio_quantity': 1,
                'option': urls.option_instruments(option_id)
            },
        ],
        'type':
        'limit',
        'trigger':
        'immediate',
        'price':
        price,
        'quantity':
        quantity,
        'override_day_trade_checks':
        False,
        'override_dtbp_checks':
        False,
        'ref_id':
        str(uuid4()),
    }

    url = urls.option_orders()
    data = helper.request_post(url, payload, json=True)
    print(data)
    return data
Exemple #5
0
def get_all_option_orders(info = None):
    """Returns a list of all the option orders that have been processed for the account.

    :param info: Will filter the results to get a specific value.
    :type info: Optional[str]
    :returns: Returns a list of dictionaries of key/value pairs for each option order. If info parameter is provided, \
    a list of strings is returned where the strings are the value of the key that matches info.

    """
    url = urls.option_orders()
    data = helper.request_get(url, 'pagination')
    return(helper.filter(data,info))
Exemple #6
0
def get_market_options(info=None):
    """Returns a list of all options.

    :param info: Will data_filter the results to get a specific value.
    :type info: Optional[str]
    :returns: Returns a list of dictionaries of key/value pairs for each option. If info parameter is provided, \
    a list of strings is returned where the strings are the value of the key that matches info.

    """
    url = urls.option_orders()
    data = helper.request_get(url, 'pagination')

    return helper.data_filter(data, info)
Exemple #7
0
def get_all_open_option_orders(info=None):
    """Returns a list of all the orders that are currently open.
    :param info: Will filter the results to get a specific value.
    :type info: Optional[str]
    :returns: Returns a list of dictionaries of key/value pairs for each order. If info parameter is provided, \
    a list of strings is returned where the strings are the value of the key that matches info.
    """
    url = urls.option_orders()
    data = helper.request_get(url, 'pagination')

    data = [item for item in data if item['cancel_url'] is not None]

    return (helper.filter(data, info))
Exemple #8
0
def get_order_info(orderID, option=True):
    """Returns the information for a single order.

    :param orderID: The ID associated with the order. Can be found using get_all_orders(info=None) or get_all_orders(info=None).
    :type orderID: str
    :returns: Returns a list of dictionaries of key/value pairs for the order.

    """
    if option:
        url = urls.option_orders(orderID)
    else:
        url = urls.orders(orderID)
    data = helper.request_get(url)
    return (data)