Skip to content

Commit

Permalink
add print line to examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
westonplatter committed Apr 13, 2019
1 parent 2a08fab commit ca4f631
Show file tree
Hide file tree
Showing 27 changed files with 144 additions and 96 deletions.
48 changes: 25 additions & 23 deletions examples/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,30 @@
from fast_arrow import Client
from fast_arrow.resources.user import User

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']
#
# get the authentication configs
# client = Client(username=username, password=password)
# result = client.authenticate()
#
config_file = "config.debug.ini"
config = configparser.ConfigParser()
config.read(config_file)
username = config['account']['username']
password = config['account']['password']

client = Client(username=username, password=password)
result = client.authenticate()

print("Authenticated successfully = {}".format(result))

print("Account Url = {}".format(client.account_url))
print("Account Id = {}".format(client.account_id))

user = User.fetch(client)
print("Username = {}".format(user["username"]))

result = client.relogin_oauth2()
print("Re-Authenticated with refresh_token successfully = {}".format(result))

result = client.logout_oauth2()
print("Logged out successfully = {}".format(result))
# print("Authenticated successfully = {}".format(result))
#
# print("Account Url = {}".format(client.account_url))
# print("Account Id = {}".format(client.account_id))
#
# user = User.fetch(client)
# print("Username = {}".format(user["username"]))
#
# result = client.relogin_oauth2()
# print("Re-Authenticated with refresh_token successfully = {}".format(result))
#
# result = client.logout_oauth2()
# print("Logged out successfully = {}".format(result))
50 changes: 26 additions & 24 deletions examples/auth_mfa.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,32 @@
from fast_arrow import Client
from fast_arrow.resources.user import User

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']

mfa_code = "code goes here as a string"

client = Client(username=username, password=password, mfa_code=mfa_code)
result = client.authenticate()

print("Authenticated successfully = {}".format(result))

print("Account Url = {}".format(client.account_url))
print("Account Id = {}".format(client.account_id))

user = User.fetch(client)
print("Username = {}".format(user["username"]))

result = client.relogin_oauth2()
print("Re-Authenticated with refresh_token successfully = {}".format(result))

result = client.logout_oauth2()
print("Logged out successfully = {}".format(result))
# config_file = "config.debug.ini"
# config = configparser.ConfigParser()
# config.read(config_file)
# username = config['account']['username']
# password = config['account']['password']
#
# mfa_code = "code goes here as a string"
#
# client = Client(username=username, password=password, mfa_code=mfa_code)
# result = client.authenticate()
#
# print("Authenticated successfully = {}".format(result))
#
# print("Account Url = {}".format(client.account_url))
# print("Account Id = {}".format(client.account_id))
#
# user = User.fetch(client)
# print("Username = {}".format(user["username"]))
#
# result = client.relogin_oauth2()
# print("Re-Authenticated with refresh_token successfully = {}".format(result))
#
# result = client.logout_oauth2()
# print("Logged out successfully = {}".format(result))
4 changes: 3 additions & 1 deletion examples/historical_option_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
OptionChain,
OptionMarketdata
)
import math

print("----- running {}".format(__file__))

#
# get the authentication configs
Expand Down Expand Up @@ -38,7 +41,6 @@
# get TLT in the middle of the current TLT trading range
#
urls = [op["url"] for op in ops]
import math
middle = math.floor(len(urls)/2)
diff = math.floor(len(urls) * 0.7)
lower_end = middle - diff
Expand Down
1 change: 1 addition & 0 deletions examples/option_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Option,
)

print("----- running {}".format(__file__))

#
# get the authentication configs
Expand Down
1 change: 1 addition & 0 deletions examples/option_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
OptionEvent
)

print("----- running {}".format(__file__))

#
# get the authentication configs
Expand Down
1 change: 1 addition & 0 deletions examples/option_order_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
)
import math

print("----- running {}".format(__file__))

#
# get the authentication configs
Expand Down
70 changes: 35 additions & 35 deletions examples/option_order_place_iron_condor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
Stock
)

print("----- running {}".format(__file__))

#
# get the authentication configs
#
Expand All @@ -35,7 +37,6 @@
#
symbol = "SPY"
stock = Stock.fetch(client, symbol)
stock = Stock.mergein_marketdata_list(client, [stock])[0]

oc = OptionChain.fetch(client, stock["id"], symbol)
ed = oc['expiration_dates'][10]
Expand All @@ -53,39 +54,38 @@
width = 1
put_inner_lte_delta = -0.2
call_inner_lte_delta = 0.1
ic = IronCondor.generate_by_deltas(ops,
width, put_inner_lte_delta, call_inner_lte_delta)

direction = "credit"
legs = ic["legs"]
# @TODO create helper methods to handle floating arith and rounding issues
# for now, it works good enough
price_notional = ic["price"] * 100
price_notional_fourth = price_notional / 4
price_order = price_notional_fourth / 100
price = str(price_order)

quantity = 1
time_in_force = "gfd"
trigger = "immediate"
order_type = "limit"

# @TODO create human description of IC
# 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"]))

# ic = IronCondor.generate_by_deltas(ops,width, put_inner_lte_delta, call_inner_lte_delta)
#
# direction = "credit"
# legs = ic["legs"]
# # @TODO create helper methods to handle floating arith and rounding issues
# # for now, it works good enough
# price_notional = ic["price"] * 100
# price_notional_fourth = price_notional / 4
# price_order = price_notional_fourth / 100
# price = str(price_order)
#
# quantity = 1
# time_in_force = "gfd"
# trigger = "immediate"
# order_type = "limit"
#
# # @TODO create human description of IC
# # 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)
#
# cancel the order
# print("Order submitted ... ref_id = {}".format(oo["ref_id"]))
#
print("Canceling order = {}".format(oo["ref_id"]))
result = OptionOrder.cancel(client, oo['cancel_url'])
print("Order canceled result = {}".format(result))
# #
# # cancel the order
# #
# print("Canceling order = {}".format(oo["ref_id"]))
# result = OptionOrder.cancel(client, oo['cancel_url'])
# print("Order canceled result = {}".format(result))
1 change: 1 addition & 0 deletions examples/option_order_place_single.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
)
import math

print("----- running {}".format(__file__))

#
# get the authentication configs
Expand Down
1 change: 1 addition & 0 deletions examples/option_order_place_vertical.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
)
import math

print("----- running {}".format(__file__))

#
# get the authentication configs
Expand Down
1 change: 1 addition & 0 deletions examples/option_order_replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
)
import math

print("----- running {}".format(__file__))

#
# get the authentication configs
Expand Down
3 changes: 3 additions & 0 deletions examples/option_orders_max_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from datetime import datetime, timedelta


print("----- running {}".format(__file__))


config = configparser.ConfigParser()
config.read('config.debug.ini')

Expand Down
6 changes: 4 additions & 2 deletions examples/option_orders_unroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
from fast_arrow import Client, OptionOrder


print("----- running {}".format(__file__))


config = configparser.ConfigParser()
config.read('config.debug.ini')

Expand Down Expand Up @@ -34,8 +37,7 @@
#
option_orders_unrolled = OptionOrder.unroll_option_legs(client, option_orders)


#
# let's print out the results
#
print(option_orders_unrolled[1:10])
print(option_orders_unrolled[0].keys())
2 changes: 2 additions & 0 deletions examples/option_positions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
OptionPosition
)

print("----- running {}".format(__file__))

#
# get the authentication configs
#
Expand Down
4 changes: 3 additions & 1 deletion examples/option_positions_humanized.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
OptionMarketdata,
)

print("----- running {}".format(__file__))

#
# get the authentication configs
#
Expand Down Expand Up @@ -73,5 +75,5 @@
# create Pandas DF of option positions
#
df = pd.DataFrame.from_dict(ops)
#
#
print(df)
2 changes: 2 additions & 0 deletions examples/option_positions_max_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
OptionPosition
)

print("----- running {}".format(__file__))

#
# get the authentication configs
#
Expand Down
17 changes: 14 additions & 3 deletions examples/portfolio_historicals.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import configparser
from fast_arrow import Client
from fast_arrow import Portfolio
from fast_arrow import Account


print("----- running {}".format(__file__))


#
# get the authentication configs
Expand All @@ -10,19 +15,25 @@
config.read(config_file)
username = config['account']['username']
password = config['account']['password']
account = config['account']['account']


client = Client(username=username, password=password)
result = client.authenticate()


account = Account.all(client)[0]
account_number = account['account_number']


span="year"
bounds="regular"
portfolio_historicals = Portfolio.historical(client, account, span, bounds)
portfolio_historicals = Portfolio.historical(client, account_number, span, bounds)


ehs = portfolio_historicals["equity_historicals"]
begins_at = ehs[-1]["begins_at"]
ends_at = ehs[0]["begins_at"]

print(ehs[0].keys())

print(ehs[0].keys())
print("Fetched portfolio data between {} and {}".format(begins_at, ends_at))
4 changes: 4 additions & 0 deletions examples/stock_historical_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
StockMarketdata
)


print("----- running {}".format(__file__))


#
# get the authentication configs
#
Expand Down
4 changes: 4 additions & 0 deletions examples/stock_positions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
StockPosition
)


print("----- running {}".format(__file__))


#
# get the authentication configs
#
Expand Down
Loading

0 comments on commit ca4f631

Please sign in to comment.