Exemplo n.º 1
0
def option_positions(account, options={}):
    token = _get_token(account["username"], account["password"])
    all_option_positions = OptionPosition.all(token)
    open_option_positions = list(
        filter(lambda p: float(p["quantity"]) > 0.0, all_option_positions))
    bearer = _get_bearer(token)
    results = OptionPosition.append_marketdata(bearer, open_option_positions)
    return results
Exemplo n.º 2
0
def option_positions(client, options={}):
    '''
    options:
        - only_open. Default = True
    '''
    x = OptionPosition.all(client)
    only_open = util.get_key(options, "only_open", True)
    if only_open:
        x = list(filter(lambda p: float(p["quantity"]) > 0.0, x))
        x = OptionPosition.mergein_marketdata_list(client, x)
        x = OptionPosition.mergein_instrumentdata_list(client, x)
        x = OptionPosition.humanize_numbers(x)
    return x
Exemplo n.º 3
0
    def test_fetch_fields(self):
        client = gen_client()
        with gen_vcr().use_cassette('option_position_all.yaml'):
            option_positions = OptionPosition.all(client)
            option_position = option_positions[0]

            expected_fields = [
                'intraday_average_open_price', 'account', 'intraday_quantity',
                'option', 'created_at', 'updated_at', 'average_price',
                'chain_id', 'pending_expired_quantity', 'pending_buy_quantity',
                'url', 'pending_sell_quantity', 'chain_symbol', 'type', 'id',
                'quantity']

            actual_fields = list(option_position.keys())

            assert(set(expected_fields) == set(actual_fields))
Exemplo n.º 4
0
#
# get auth_data (see https://github.com/westonplatter/fast_arrow_auth)
#
with open("fast_arrow_auth.json") as f:
    auth_data = json.loads(f.read())

#
# initialize client with auth_data
#
client = Client(auth_data)

#
# fetch option_positions
#
all_option_positions = OptionPosition.all(client)

#
# filter to get open option_positions
#
ops = list(filter(lambda p: float(p["quantity"]) > 0.0, all_option_positions))
#
msg = "There are {} open option positions".format(len(ops))
print(msg)

#
# append marketdata to each position
#
ops = OptionPosition.mergein_marketdata_list(client, ops)

#
Exemplo n.º 5
0
# get auth_data (see https://github.com/westonplatter/fast_arrow_auth)
#
with open("fast_arrow_auth.json") as f:
    auth_data = json.loads(f.read())


#
# initialize client with auth_data
#
client = Client(auth_data)


#
# fetch option_positions
#
all_option_positions = OptionPosition.all(client)


#
# filter to get open option_positions
#
open_option_positions = list(filter(lambda p: float(p["quantity"]) > 0.0, all_option_positions))


#
# append marketdata to each position
#
option_position_with_marketdata = OptionPosition.mergein_marketdata_list(client, open_option_positions)


#
Exemplo n.º 6
0
from datatype_tools.lib import *
from print_tools.printer import Printer
from fast_arrow import Client, OptionChain, Option, OptionPosition, OptionOrder

#: Login

p = Printer()
client = Client()
client.authenticate()

#: Get Positions

positions = OptionPosition.all(client)
positions = list(filter(lambda p: float(p["quantity"]) > 0.0, positions))

if (len(positions) > 0):
    positions = OptionPosition.mergein_marketdata_list(client, positions)
    positions = OptionPosition.mergein_instrumentdata_list(client, positions)
    positions = OptionPosition.mergein_orderdata_list(client, positions)

    #: Get Most Recent Order

    symbol = positions[0]['chain_symbol']
    strat = positions[0]['option_type']
    effect = positions[0]['type']
    buy_price = positions[0]['average_price']
    bid_price = positions[0]['bid_price']
    expiration_date = positions[0]['expiration_date']
    quantity = positions[0]['quantity']
    url = positions[0]['instrument']