firstrade 0.0.21__tar.gz → 0.0.30__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,225 @@
1
+ Metadata-Version: 2.1
2
+ Name: firstrade
3
+ Version: 0.0.30
4
+ Summary: An unofficial API for Firstrade
5
+ Home-page: https://github.com/MaxxRK/firstrade-api
6
+ Download-URL: https://github.com/MaxxRK/firstrade-api/archive/refs/tags/0030.tar.gz
7
+ Author: MaxxRK
8
+ Author-email: maxxrk@pm.me
9
+ License: MIT
10
+ Keywords: FIRSTRADE,API
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Topic :: Internet :: WWW/HTTP :: Session
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.8
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: requests
23
+ Requires-Dist: beautifulsoup4
24
+ Requires-Dist: lxml
25
+
26
+ # firstrade-api
27
+
28
+ A reverse-engineered python API to interact with the Firstrade Trading platform.
29
+
30
+ This is not an official api! This api's functionality may change at any time.
31
+
32
+ This api provides a means of buying and selling stocks through Firstrade. It uses the Session class from requests to get authorization cookies. The rest is done with reverse engineered requests to Firstrade's API.
33
+
34
+ In order to use Fractional shares you must accept the agreement on the website before using it in this API.
35
+
36
+ ---
37
+
38
+ ## Contribution
39
+
40
+ I am new to coding and new to open-source. I would love any help and suggestions!
41
+
42
+ ## Disclaimer
43
+ I am not a financial advisor and not affiliated with Firstrade in any way. Use this tool at your own risk. I am not responsible for any losses or damages you may incur by using this project. This tool is provided as-is with no warranty.
44
+
45
+ ## Setup
46
+
47
+ Install using pypi:
48
+
49
+ ```
50
+ pip install firstrade
51
+ ```
52
+
53
+ ## Quikstart
54
+
55
+ The code below will:
56
+ - Login and print account info.
57
+ - Get a quote for 'INTC' and print out the information
58
+ - Place a dry run market order for 'INTC' on the first account in the `account_numbers` list
59
+ - Print out the order confirmation
60
+ - Contains a cancel order example
61
+ - Get an option Dates, Quotes, and Greeks
62
+ - Place a dry run option order
63
+
64
+ ```python
65
+ from firstrade import account, order, symbols
66
+
67
+ # Create a session
68
+ ft_ss = account.FTSession(username="", password="", email = "", profile_path="")
69
+ need_code = ft_ss.login()
70
+ if need_code:
71
+ code = input("Please enter the pin sent to your email/phone: ")
72
+ ft_ss.login_two(code)
73
+
74
+ # Get account data
75
+ ft_accounts = account.FTAccountData(ft_ss)
76
+ if len(ft_accounts.account_numbers) < 1:
77
+ raise Exception("No accounts found or an error occured exiting...")
78
+
79
+ # Print ALL account data
80
+ print(ft_accounts.all_accounts)
81
+
82
+ # Print 1st account number.
83
+ print(ft_accounts.account_numbers[0])
84
+
85
+ # Print ALL accounts market values.
86
+ print(ft_accounts.account_balances)
87
+
88
+ # Get quote for INTC
89
+ quote = symbols.SymbolQuote(ft_ss, ft_accounts.account_numbers[0], "INTC")
90
+ print(f"Symbol: {quote.symbol}")
91
+ print(f"Tick: {quote.tick}")
92
+ print(f"Exchange: {quote.exchange}")
93
+ print(f"Bid: {quote.bid}")
94
+ print(f"Ask: {quote.ask}")
95
+ print(f"Last: {quote.last}")
96
+ print(f"Bid Size: {quote.bid_size}")
97
+ print(f"Ask Size: {quote.ask_size}")
98
+ print(f"Last Size: {quote.last_size}")
99
+ print(f"Bid MMID: {quote.bid_mmid}")
100
+ print(f"Ask MMID: {quote.ask_mmid}")
101
+ print(f"Last MMID: {quote.last_mmid}")
102
+ print(f"Change: {quote.change}")
103
+ print(f"High: {quote.high}")
104
+ print(f"Low: {quote.low}")
105
+ print(f"Change Color: {quote.change_color}")
106
+ print(f"Volume: {quote.volume}")
107
+ print(f"Quote Time: {quote.quote_time}")
108
+ print(f"Last Trade Time: {quote.last_trade_time}")
109
+ print(f"Real Time: {quote.realtime}")
110
+ print(f"Fractional: {quote.is_fractional}")
111
+ print(f"Company Name: {quote.company_name}")
112
+
113
+ # Get positions and print them out for an account.
114
+ positions = ft_accounts.get_positions(account=ft_accounts.account_numbers[1])
115
+ print(positions)
116
+ for item in positions["items"]:
117
+ print(
118
+ f"Quantity {item["quantity"]} of security {item["symbol"]} held in account {ft_accounts.account_numbers[1]}"
119
+ )
120
+
121
+ # Get account history (past 200)
122
+ history = ft_accounts.get_account_history(account=ft_accounts.account_numbers[0])
123
+ for item in history["items"]:
124
+ print(f"Transaction: {item["symbol"]} on {item["report_date"]} for {item["amount"]}.")
125
+
126
+
127
+ # Create an order object.
128
+ ft_order = order.Order(ft_ss)
129
+
130
+ # Place dry run order and print out order confirmation data.
131
+ order_conf = ft_order.place_order(
132
+ ft_accounts.account_numbers[0],
133
+ symbol="INTC",
134
+ price_type=order.PriceType.LIMIT,
135
+ order_type=order.OrderType.BUY,
136
+ duration=order.Duration.DAY,
137
+ quantity=1,
138
+ dry_run=True,
139
+ )
140
+
141
+ print(order_conf)
142
+
143
+ if "order_id" not in order_conf["result"]:
144
+ print("Dry run complete.")
145
+ print(order_conf["result"])
146
+ else:
147
+ print("Order placed successfully.")
148
+ print(f"Order ID: {order_conf["result"]["order_id"]}.")
149
+ print(f"Order State: {order_conf["result"]["state"]}.")
150
+
151
+ # Cancel placed order
152
+ # cancel = ft_accounts.cancel_order(order_conf['result']["order_id"])
153
+ # if cancel["result"]["result"] == "success":
154
+ # print("Order cancelled successfully.")
155
+ # print(cancel)
156
+
157
+ # Check orders
158
+ recent_orders = ft_accounts.get_orders(ft_accounts.account_numbers[0])
159
+ print(recent_orders)
160
+
161
+ #Get option dates
162
+ option_first = symbols.OptionQuote(ft_ss, "INTC")
163
+ for item in option_first.option_dates["items"]:
164
+ print(f"Expiration Date: {item["exp_date"]} Days Left: {item["day_left"]} Expiration Type: {item["exp_type"]}")
165
+
166
+ # Get option quote
167
+ option_quote = option_first.get_option_quote("INTC", option_first.option_dates["items"][0]["exp_date"])
168
+ print(option_quote)
169
+
170
+ # Get option greeks
171
+ option_greeks = option_first.get_greek_options("INTC", option_first.option_dates["items"][0]["exp_date"])
172
+ print(option_greeks)
173
+
174
+ print(f"Placing dry option order for {option_quote["items"][0]["opt_symbol"]} with a price of {option_quote["items"][0]["ask"]}.")
175
+ print("Symbol readable ticker 'INTC'")
176
+
177
+ # Place dry option order
178
+ option_order = ft_order.place_option_order(
179
+ account=ft_accounts.account_numbers[0],
180
+ option_symbol=option_quote["items"][0]["opt_symbol"],
181
+ order_type=order.OrderType.BUY_OPTION,
182
+ price_type=order.PriceType.MARKET,
183
+ duration=order.Duration.DAY,
184
+ contracts=1,
185
+ dry_run=True,
186
+ )
187
+
188
+ print(option_order)
189
+
190
+ # Delete cookies
191
+ ft_ss.delete_cookies()
192
+ ```
193
+
194
+ `You can also find this code in test.py`
195
+
196
+ ---
197
+
198
+ ## Implemented Features
199
+
200
+ - [x] Login (With all 2FA methods now supported!)
201
+ - [x] Get Quotes
202
+ - [x] Get Account Data
203
+ - [x] Place Orders and Receive order confirmation
204
+ - [x] Get Currently Held Positions
205
+ - [x] Fractional Trading support (thanks to @jiak94)
206
+ - [x] Check on placed order status. (thanks to @Cfomodz)
207
+ - [x] Cancel placed orders
208
+ - [x] Options (Orders, Quotes, Greeks)
209
+ - [x] Order History
210
+
211
+ ## TO DO
212
+
213
+ - [ ] Test options fully
214
+ - [ ] Give me some Ideas!
215
+
216
+ ## Options
217
+
218
+ ### I am very new to options trading and have not fully tested this feature.
219
+
220
+ Please:
221
+ - USE THIS FEATURE LIKE IT IS A ALPHA/BETA
222
+ - PUT IN A GITHUB ISSUE IF YOU FIND ANY PROBLEMS
223
+
224
+ ## If you would like to support me, you can do so here:
225
+ [![GitHub Sponsors](https://img.shields.io/github/sponsors/maxxrk?style=social)](https://github.com/sponsors/maxxrk)
@@ -0,0 +1,200 @@
1
+ # firstrade-api
2
+
3
+ A reverse-engineered python API to interact with the Firstrade Trading platform.
4
+
5
+ This is not an official api! This api's functionality may change at any time.
6
+
7
+ This api provides a means of buying and selling stocks through Firstrade. It uses the Session class from requests to get authorization cookies. The rest is done with reverse engineered requests to Firstrade's API.
8
+
9
+ In order to use Fractional shares you must accept the agreement on the website before using it in this API.
10
+
11
+ ---
12
+
13
+ ## Contribution
14
+
15
+ I am new to coding and new to open-source. I would love any help and suggestions!
16
+
17
+ ## Disclaimer
18
+ I am not a financial advisor and not affiliated with Firstrade in any way. Use this tool at your own risk. I am not responsible for any losses or damages you may incur by using this project. This tool is provided as-is with no warranty.
19
+
20
+ ## Setup
21
+
22
+ Install using pypi:
23
+
24
+ ```
25
+ pip install firstrade
26
+ ```
27
+
28
+ ## Quikstart
29
+
30
+ The code below will:
31
+ - Login and print account info.
32
+ - Get a quote for 'INTC' and print out the information
33
+ - Place a dry run market order for 'INTC' on the first account in the `account_numbers` list
34
+ - Print out the order confirmation
35
+ - Contains a cancel order example
36
+ - Get an option Dates, Quotes, and Greeks
37
+ - Place a dry run option order
38
+
39
+ ```python
40
+ from firstrade import account, order, symbols
41
+
42
+ # Create a session
43
+ ft_ss = account.FTSession(username="", password="", email = "", profile_path="")
44
+ need_code = ft_ss.login()
45
+ if need_code:
46
+ code = input("Please enter the pin sent to your email/phone: ")
47
+ ft_ss.login_two(code)
48
+
49
+ # Get account data
50
+ ft_accounts = account.FTAccountData(ft_ss)
51
+ if len(ft_accounts.account_numbers) < 1:
52
+ raise Exception("No accounts found or an error occured exiting...")
53
+
54
+ # Print ALL account data
55
+ print(ft_accounts.all_accounts)
56
+
57
+ # Print 1st account number.
58
+ print(ft_accounts.account_numbers[0])
59
+
60
+ # Print ALL accounts market values.
61
+ print(ft_accounts.account_balances)
62
+
63
+ # Get quote for INTC
64
+ quote = symbols.SymbolQuote(ft_ss, ft_accounts.account_numbers[0], "INTC")
65
+ print(f"Symbol: {quote.symbol}")
66
+ print(f"Tick: {quote.tick}")
67
+ print(f"Exchange: {quote.exchange}")
68
+ print(f"Bid: {quote.bid}")
69
+ print(f"Ask: {quote.ask}")
70
+ print(f"Last: {quote.last}")
71
+ print(f"Bid Size: {quote.bid_size}")
72
+ print(f"Ask Size: {quote.ask_size}")
73
+ print(f"Last Size: {quote.last_size}")
74
+ print(f"Bid MMID: {quote.bid_mmid}")
75
+ print(f"Ask MMID: {quote.ask_mmid}")
76
+ print(f"Last MMID: {quote.last_mmid}")
77
+ print(f"Change: {quote.change}")
78
+ print(f"High: {quote.high}")
79
+ print(f"Low: {quote.low}")
80
+ print(f"Change Color: {quote.change_color}")
81
+ print(f"Volume: {quote.volume}")
82
+ print(f"Quote Time: {quote.quote_time}")
83
+ print(f"Last Trade Time: {quote.last_trade_time}")
84
+ print(f"Real Time: {quote.realtime}")
85
+ print(f"Fractional: {quote.is_fractional}")
86
+ print(f"Company Name: {quote.company_name}")
87
+
88
+ # Get positions and print them out for an account.
89
+ positions = ft_accounts.get_positions(account=ft_accounts.account_numbers[1])
90
+ print(positions)
91
+ for item in positions["items"]:
92
+ print(
93
+ f"Quantity {item["quantity"]} of security {item["symbol"]} held in account {ft_accounts.account_numbers[1]}"
94
+ )
95
+
96
+ # Get account history (past 200)
97
+ history = ft_accounts.get_account_history(account=ft_accounts.account_numbers[0])
98
+ for item in history["items"]:
99
+ print(f"Transaction: {item["symbol"]} on {item["report_date"]} for {item["amount"]}.")
100
+
101
+
102
+ # Create an order object.
103
+ ft_order = order.Order(ft_ss)
104
+
105
+ # Place dry run order and print out order confirmation data.
106
+ order_conf = ft_order.place_order(
107
+ ft_accounts.account_numbers[0],
108
+ symbol="INTC",
109
+ price_type=order.PriceType.LIMIT,
110
+ order_type=order.OrderType.BUY,
111
+ duration=order.Duration.DAY,
112
+ quantity=1,
113
+ dry_run=True,
114
+ )
115
+
116
+ print(order_conf)
117
+
118
+ if "order_id" not in order_conf["result"]:
119
+ print("Dry run complete.")
120
+ print(order_conf["result"])
121
+ else:
122
+ print("Order placed successfully.")
123
+ print(f"Order ID: {order_conf["result"]["order_id"]}.")
124
+ print(f"Order State: {order_conf["result"]["state"]}.")
125
+
126
+ # Cancel placed order
127
+ # cancel = ft_accounts.cancel_order(order_conf['result']["order_id"])
128
+ # if cancel["result"]["result"] == "success":
129
+ # print("Order cancelled successfully.")
130
+ # print(cancel)
131
+
132
+ # Check orders
133
+ recent_orders = ft_accounts.get_orders(ft_accounts.account_numbers[0])
134
+ print(recent_orders)
135
+
136
+ #Get option dates
137
+ option_first = symbols.OptionQuote(ft_ss, "INTC")
138
+ for item in option_first.option_dates["items"]:
139
+ print(f"Expiration Date: {item["exp_date"]} Days Left: {item["day_left"]} Expiration Type: {item["exp_type"]}")
140
+
141
+ # Get option quote
142
+ option_quote = option_first.get_option_quote("INTC", option_first.option_dates["items"][0]["exp_date"])
143
+ print(option_quote)
144
+
145
+ # Get option greeks
146
+ option_greeks = option_first.get_greek_options("INTC", option_first.option_dates["items"][0]["exp_date"])
147
+ print(option_greeks)
148
+
149
+ print(f"Placing dry option order for {option_quote["items"][0]["opt_symbol"]} with a price of {option_quote["items"][0]["ask"]}.")
150
+ print("Symbol readable ticker 'INTC'")
151
+
152
+ # Place dry option order
153
+ option_order = ft_order.place_option_order(
154
+ account=ft_accounts.account_numbers[0],
155
+ option_symbol=option_quote["items"][0]["opt_symbol"],
156
+ order_type=order.OrderType.BUY_OPTION,
157
+ price_type=order.PriceType.MARKET,
158
+ duration=order.Duration.DAY,
159
+ contracts=1,
160
+ dry_run=True,
161
+ )
162
+
163
+ print(option_order)
164
+
165
+ # Delete cookies
166
+ ft_ss.delete_cookies()
167
+ ```
168
+
169
+ `You can also find this code in test.py`
170
+
171
+ ---
172
+
173
+ ## Implemented Features
174
+
175
+ - [x] Login (With all 2FA methods now supported!)
176
+ - [x] Get Quotes
177
+ - [x] Get Account Data
178
+ - [x] Place Orders and Receive order confirmation
179
+ - [x] Get Currently Held Positions
180
+ - [x] Fractional Trading support (thanks to @jiak94)
181
+ - [x] Check on placed order status. (thanks to @Cfomodz)
182
+ - [x] Cancel placed orders
183
+ - [x] Options (Orders, Quotes, Greeks)
184
+ - [x] Order History
185
+
186
+ ## TO DO
187
+
188
+ - [ ] Test options fully
189
+ - [ ] Give me some Ideas!
190
+
191
+ ## Options
192
+
193
+ ### I am very new to options trading and have not fully tested this feature.
194
+
195
+ Please:
196
+ - USE THIS FEATURE LIKE IT IS A ALPHA/BETA
197
+ - PUT IN A GITHUB ISSUE IF YOU FIND ANY PROBLEMS
198
+
199
+ ## If you would like to support me, you can do so here:
200
+ [![GitHub Sponsors](https://img.shields.io/github/sponsors/maxxrk?style=social)](https://github.com/sponsors/maxxrk)