forked from westonplatter/fast_arrow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoption_chain.py
56 lines (42 loc) · 1.05 KB
/
option_chain.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import configparser
import json
from fast_arrow import (
Client,
StockMarketdata,
OptionChain,
Option,
)
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 the stock info for TLT
#
symbol = "TLT"
md = StockMarketdata.quote_by_symbol(client, symbol)
#
# get the TLT option chain info
#
stock_id = md["instrument"].split("/")[-2]
option_chain = OptionChain.fetch(client, stock_id, symbol)
option_chain_id = option_chain["id"]
expiration_dates = option_chain['expiration_dates']
#
# reduce the number of expiration dates we're interested in
#
next_3_expiration_dates = expiration_dates[0:3]
#
# get all options on the TLT option chain
#
ops = Option.in_chain(client, option_chain_id, expiration_dates=next_3_expiration_dates)
#
# merge in market data fro TLT option instruments
#
ops = Option.mergein_marketdata_list(client, ops)