1+ # Name: ts2OS.py
2+ # Version: 1.0 - 2024/08/05
3+ # Description: Run with python ./buildOS.py, when the prompt comes up, copy and paste the lines from the trade steward bot log for the fill.
4+ # E.g. Leg 1: Sell To Open SPXW 07/18/24 5650P @ $21.13 (21.20/21.50); 49.4 Delta
5+ # Leg 2: Buy To Open SPXW 07/18/24 5620P @ $10.35 (10.40/10.70); 29.3 Delta
6+ # Leg 3: Buy To Open SPXW 07/16/24 5620P @ $2.67 (2.70/2.80); 16.9 Delta
7+ #
8+ # Once input is done, press enter on an empty line. There's no error checking. Quick and dirty...
9+ import re
10+
11+ class Option :
12+ def __init__ (self , stringInput ):
13+ self .expiration = None
14+ self .strike = None
15+ self .type = None
16+ self .quantity = 0
17+ self .ticker = None
18+ self .premium = None
19+ self .processString (stringInput )
20+
21+ def processString (self , stringInput ):
22+ # Parse a string from TradeSteward's bot log
23+ reResult = re .search (r'\w+: (Sell|Buy) To Open (\w+) (\d+[/]\d+[/]\d+) (\d+)(C|P) [@] [$](\d+[.]?\d+)' , stringInput )
24+ if "Sell" in (reResult [1 ]):
25+ self .quantity = - 1
26+ elif "Buy" in reResult [1 ]:
27+ self .quantity = 1
28+
29+ # Ticker
30+ self .ticker = reResult [2 ]
31+
32+ # Date
33+ dateArray = re .search (r'(\d+)[/](\d+)[/](\d+)' , reResult [3 ])
34+ dateString = dateArray [3 ]+ dateArray [1 ]+ dateArray [2 ]
35+ self .expiration = dateString
36+
37+ # Strike
38+ self .strike = reResult [4 ]
39+
40+ # Type
41+ self .type = reResult [5 ]
42+
43+ # Premium
44+ self .premium = reResult [6 ]
45+
46+ def getOSString (self ):
47+ stringOut = ""
48+ if (self .quantity < 0 ):
49+ stringOut = "-"
50+ stringOut = stringOut + "." + self .ticker + self .expiration + self .type + self .strike + "x" + str (abs (self .quantity ))+ "@" + self .premium
51+ return stringOut
52+
53+
54+ if __name__ == "__main__" :
55+ print ("Paste the order information string (Press enter on empty line to end input): " )
56+ options = []
57+ while True :
58+ inString = input ()
59+ if inString == "" :
60+ break
61+ options .append (Option (inString ))
62+
63+
64+ print ("There are" ,str (len (options )), "option legs: " )
65+ # Not the most elegant way to do this... but I need the main ticker... tickers ending in W or Q need to be cleaned
66+ baseTicker = re .search (r'(?:(\w{3,})[WQ]|(\w+))' , options [0 ].ticker )
67+
68+ baseURL = "https://optionstrat.com/build/custom/" + baseTicker [baseTicker .lastindex ] + "/"
69+ fullURL = baseURL
70+ optCount = 0
71+ for opt in options :
72+ if optCount > 0 :
73+ fullURL = fullURL + ","
74+ fullURL = fullURL + opt .getOSString ()
75+ optCount = optCount + 1
76+
77+ print (fullURL )
0 commit comments