@@ -86,7 +86,6 @@ def place_order(
8686 Order:order_confirmation: Dictionary containing the order confirmation data.
8787 """
8888
89-
9089 if price_type == PriceType .MARKET :
9190 price = ""
9291
@@ -121,7 +120,7 @@ def place_order(
121120 "cond_compare_type0_1" : "2" ,
122121 "cond_compare_value0_1" : "" ,
123122 }
124-
123+
125124 order_data = BeautifulSoup (
126125 self .ft_session .post (
127126 url = urls .orderbar (), headers = urls .session_headers (), data = data
@@ -132,12 +131,12 @@ def place_order(
132131 cdata = order_data .find ("actiondata" ).string
133132 cdata_soup = BeautifulSoup (cdata , "html.parser" )
134133 span = (
135- cdata_soup .find (' div' , class_ = ' msg_bg' )
136- .find (' div' , class_ = ' yellow box' )
137- .find (' div' , class_ = ' error_msg' )
138- .find (' div' , class_ = ' outbox' )
139- .find (' div' , class_ = ' inbox' )
140- .find (' span' )
134+ cdata_soup .find (" div" , class_ = " msg_bg" )
135+ .find (" div" , class_ = " yellow box" )
136+ .find (" div" , class_ = " error_msg" )
137+ .find (" div" , class_ = " outbox" )
138+ .find (" div" , class_ = " inbox" )
139+ .find (" span" )
141140 )
142141 if span :
143142 order_warning = span .text .strip ()
@@ -152,7 +151,7 @@ def place_order(
152151 ).text ,
153152 "xml" ,
154153 )
155-
154+
156155 order_success = order_data .find ("success" ).text .strip ()
157156 order_confirmation ["success" ] = order_success
158157 action_data = order_data .find ("actiondata" ).text .strip ()
@@ -197,48 +196,56 @@ def get_orders(ft_session, account):
197196
198197 # Data dictionary to send with the request
199198 data = {
200- ' accountId' : account ,
199+ " accountId" : account ,
201200 }
202201
203202 # Post request to retrieve the order data
204- response = ft_session .post (url = urls .order_list (), headers = urls .session_headers (), data = data ).text
203+ response = ft_session .post (
204+ url = urls .order_list (), headers = urls .session_headers (), data = data
205+ ).text
205206
206207 # Parse the response using BeautifulSoup
207208 soup = BeautifulSoup (response , "html.parser" )
208209
209210 # Find the table containing orders
210- table = soup .find (' table' , class_ = ' tablesorter' )
211+ table = soup .find (" table" , class_ = " tablesorter" )
211212 if not table :
212213 return []
213214
214- rows = table .find_all ('tr' )[1 :] # skip the header row
215+ rows = table .find_all ("tr" )[1 :] # skip the header row
215216
216217 orders = []
217218 for row in rows :
218219 try :
219- cells = row .find_all ('td' )
220- tooltip_content = row .find ('a' , {'class' : 'info' }).get ('onmouseover' )
221- tooltip_soup = BeautifulSoup (tooltip_content .split ('tooltip.show(' )[1 ].strip ("');" ), 'html.parser' )
222- order_ref = tooltip_soup .find (text = lambda text : 'Order Ref' in text )
223- order_ref_number = order_ref .split ('#: ' )[1 ] if order_ref else None
220+ cells = row .find_all ("td" )
221+ tooltip_content = row .find ("a" , {"class" : "info" }).get ("onmouseover" )
222+ tooltip_soup = BeautifulSoup (
223+ tooltip_content .split ("tooltip.show(" )[1 ].strip ("');" ), "html.parser"
224+ )
225+ order_ref = tooltip_soup .find (text = lambda text : "Order Ref" in text )
226+ order_ref_number = order_ref .split ("#: " )[1 ] if order_ref else None
224227 status = cells [8 ]
225228 # print(status)
226- sub_status = status .find (' strong' )
229+ sub_status = status .find (" strong" )
227230 # print(sub_status)
228231 sub_status = sub_status .get_text (strip = True )
229232 # print(sub_status)
230- status = status .find ('strong' ).get_text (strip = True ) if status .find ('strong' ) else status .get_text (strip = True )
233+ status = (
234+ status .find ("strong" ).get_text (strip = True )
235+ if status .find ("strong" )
236+ else status .get_text (strip = True )
237+ )
231238 order = {
232- ' Date/Time' : cells [0 ].get_text (strip = True ),
233- ' Reference' : order_ref_number ,
234- ' Transaction' : cells [1 ].get_text (strip = True ),
235- ' Quantity' : int (cells [2 ].get_text (strip = True )),
236- ' Symbol' : cells [3 ].get_text (strip = True ),
237- ' Type' : cells [4 ].get_text (strip = True ),
238- ' Price' : float (cells [5 ].get_text (strip = True )),
239- ' Duration' : cells [6 ].get_text (strip = True ),
240- ' Instr.' : cells [7 ].get_text (strip = True ),
241- ' Status' : status ,
239+ " Date/Time" : cells [0 ].get_text (strip = True ),
240+ " Reference" : order_ref_number ,
241+ " Transaction" : cells [1 ].get_text (strip = True ),
242+ " Quantity" : int (cells [2 ].get_text (strip = True )),
243+ " Symbol" : cells [3 ].get_text (strip = True ),
244+ " Type" : cells [4 ].get_text (strip = True ),
245+ " Price" : float (cells [5 ].get_text (strip = True )),
246+ " Duration" : cells [6 ].get_text (strip = True ),
247+ " Instr." : cells [7 ].get_text (strip = True ),
248+ " Status" : status ,
242249 }
243250 orders .append (order )
244251 except Exception as e :
0 commit comments