Skip to content
This repository has been archived by the owner on Apr 16, 2021. It is now read-only.

Commit

Permalink
Merge pull request #75 from westonplatter/17-stock-fetch-by-id
Browse files Browse the repository at this point in the history
feature #17. stocks. symbol(s) and instrument_id(s)
  • Loading branch information
westonplatter committed Apr 13, 2019
2 parents a2bb72c + 3b33d24 commit 9fa6bf5
Show file tree
Hide file tree
Showing 34 changed files with 234 additions and 104 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ coveralls:
.PHONY: lint
lint:
pipenv run tox -e lint


.PHONY: examples
examples:
pipenv run run_all_examples
4 changes: 4 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ yarl = "*"
pandas = ">=0.23.2"
numpy = "*"
datetime = "*"
deprecation = "*"

[dev-packages]
vcrpy = "*"
Expand All @@ -23,3 +24,6 @@ ipdb = "*"

[requires]
python_version = "3.6"

[scripts]
run_all_examples = "sh ./run_all_examples.sh"
30 changes: 26 additions & 4 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions examples/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from fast_arrow import Client
from fast_arrow.resources.user import User

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

#
# get the authentication configs
#
Expand Down
8 changes: 5 additions & 3 deletions examples/auth_mfa.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
from fast_arrow import Client
from fast_arrow.resources.user import User

#
# get the authentication configs
#
print("----- running {}".format(__file__))


get the authentication configs

config_file = "config.debug.ini"
config = configparser.ConfigParser()
config.read(config_file)
Expand Down
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 9fa6bf5

Please sign in to comment.