def option_orders(client, options={}): ''' options: - only_filled. Default = True ''' x = OptionOrder.all(client) only_filled = util.get_key(options, "only_filled", True) if only_filled: x = list(filter(lambda j: j["state"] == "filled", x)) x = OptionOrder.humanize_numbers(x) return x
def option_orders(account, options={}): ''' options: - only_filled: ''' client = _init_client(account["username"], account["password"]) x = OptionOrder.all(client) only_filled = util.get_key(options, "only_filled", True) if only_filled: x = list(filter(lambda j: j["state"] == "filled", x)) x = OptionOrder.humanize_numbers(x) return x
# # for a Put Credit spread, set limit price at 1.0 less the full margin # my_bid_price = (vertical["margin"] * 100.0) - 1.00 my_bid_price_rounded = (math.floor(my_bid_price * 100.0)) / 100.0 x = my_bid_price_rounded / 100.0 my_bid_price_formatted = str(x) price = my_bid_price_formatted quantity = 1 time_in_force = "gfd" trigger = "immediate" order_type = "limit" print("Selling a {} {}/{} {} spread for {} (notation value = ${})".format( symbol, vertical["strike_price"].values[0], vertical["strike_price_shifted"].values[0], spread_type, price, my_bid_price_rounded)) oo = OptionOrder.submit(client, direction, legs, price, quantity, time_in_force, trigger, order_type) print("Order submitted ... ref_id = {}".format(oo["ref_id"])) # # cancel the order # print("Canceling order = {}".format(oo["ref_id"])) result = OptionOrder.cancel(client, oo['cancel_url']) print("Order canceled result = {}".format(result))
import configparser from fast_arrow import Client, OptionOrder from datetime import datetime, timedelta print("----- running {}".format(__file__)) # # 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 orders for last 14 days # recent_orders = OptionOrder.all(client, max_fetches=3) print(len(recent_orders))
import configparser from fast_arrow import (Client, Option, OptionChain, OptionOrder, Vertical, Stock) import math print("----- running {}".format(__file__)) # # get the authentication configs # config_file = "config.debug.ini" config = configparser.ConfigParser() config.read(config_file) username = config['account']['username'] password = config['account']['password'] # # initialize and authenticate Client # client = Client(username=username, password=password) client.authenticate() # # fetch option order # # intentionally fake order id order_id = '89f89cde-27a8-4175-b4a8-d19ee87d2eca' option_order = OptionOrder.get(client, order_id)
config = configparser.ConfigParser() config.read('config.debug.ini') # # initialize fast_arrow client and authenticate # client = Client(username=config['account']['username'], password=config['account']['password']) client.authenticate() # # fetch option orders # option_orders_all = OptionOrder.all(client) # # in case you have lots, only use first 25 # (unroll process fetches contract data for each leg) # option_orders = option_orders_all[0:25] # # unroll option orders ... ie, break each option leg into its own row # this is helpful when doing detailed P/L reporting # option_orders_unrolled = OptionOrder.unroll_option_legs(client, option_orders) # # let's print out the results
quantity = positions[0]['quantity'] url = positions[0]['instrument'] p.chevron( f'{symbol}-{expiration_date}-{effect}-{strat}, Quantity: {quantity}, Buy: {buy_price}, Bid: {bid_price}' ) #: Place Order direction = "credit" legs = [{ "side": "sell", "option": url, "position_effect": "close", "ratio_quantity": 1 }] quantity = 1 time_in_force = "gfd" trigger = "immediate" order_type = "limit" order = OptionOrder.submit(client, direction, legs, bid_price, quantity, time_in_force, trigger, order_type) p.bullet('Option order placed.') else: p.bullet('No open positions.') #::: End Program :::
def option_orders(account, options={}): token = _get_token(account["username"], account["password"]) orders = OptionOrder.all(token) if ("only_filled" in options) and options["only_filled"]: orders = list(filter(lambda x: x["state"] == "filled", orders)) return orders
my_bid_price = (vertical["margin"] * 100.0) - 1.00 my_bid_price_rounded = (math.floor(my_bid_price * 100.0)) / 100.0 x = my_bid_price_rounded / 100.0 my_bid_price_formatted = str(x) price = my_bid_price_formatted quantity = 1 time_in_force = "gfd" trigger = "immediate" order_type = "limit" print("Selling a {} {}/{} Put Spread for {} (notional value = ${})".format( symbol, vertical["strike_price"].values[0], vertical["strike_price_shifted"].values[0], price, my_bid_price_rounded)) oo = OptionOrder.submit(client, direction, legs, price, quantity, time_in_force, trigger, order_type) print("Order submitted ... ref_id = {}".format(oo["ref_id"])) my_bid_price = (vertical["margin"] * 100.0) - 1.00 - 1.00 my_bid_price_rounded = (math.floor(my_bid_price * 100.0)) / 100.0 x = my_bid_price_rounded / 100.0 my_bid_price_formatted = str(x) new_price = my_bid_price_formatted print("Replacing order ...") print("... old price = {}".format(price)) print("... new price = {}".format(new_price)) oo_replaced = OptionOrder.replace(client, oo, new_price) print("Order has been replaced ... ref_id = {}".format(oo_replaced["ref_id"]))
config.read('config.debug.ini') # # initialize fast_arrow client and authenticate # client = Client(username=config['account']['username'], password=config['account']['password']) client.authenticate() # # fetch option orders # fetch_options = {"only_filed": True} option_orders_raw = fetch.option_orders(client, fetch_options) option_orders = OptionOrder.unroll_option_legs(client, option_orders_raw) print("Fetched {} option orders".format(len(option_orders))) fn = "option_orders.csv" export_options = dict(filename=fn) export.option_orders(option_orders, export_options) print("Finished writing option_orders to {}".format(fn)) # # option events # fetch_options = {} events = fetch.option_events(client, fetch_options) print("Fetched {} option_events".format(len(events))) fn = "option_events.csv" export_options = dict(filename=fn)