firstrade 0.0.20__py3-none-any.whl → 0.0.30__py3-none-any.whl

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.
firstrade/urls.py CHANGED
@@ -1,46 +1,76 @@
1
- def get_xml():
2
- return "https://invest.firstrade.com/cgi-bin/getxml"
1
+ def login():
2
+ return "https://api3x.firstrade.com/sess/login"
3
3
 
4
4
 
5
- def login():
6
- return "https://invest.firstrade.com/cgi-bin/login"
5
+ def request_code():
6
+ return "https://api3x.firstrade.com/sess/request_code"
7
+
7
8
 
9
+ def verify_pin():
10
+ return "https://api3x.firstrade.com/sess/verify_pin"
8
11
 
9
- def pin():
10
- return "https://invest.firstrade.com/cgi-bin/enter_pin?destination_page=home"
12
+
13
+ def user_info():
14
+ return "https://api3x.firstrade.com/private/userinfo"
11
15
 
12
16
 
13
17
  def account_list():
14
- return "https://invest.firstrade.com/cgi-bin/getaccountlist"
18
+ return "https://api3x.firstrade.com/private/acct_list"
19
+
20
+
21
+ def account_balances(account):
22
+ return f"https://api3x.firstrade.com/private/balances?account={account}"
23
+
24
+
25
+ def account_positions(account):
26
+ return f"https://api3x.firstrade.com/private/positions?account={account}&per_page=200"
27
+
28
+
29
+ def quote(account, symbol):
30
+ return f"https://api3x.firstrade.com/public/quote?account={account}&q={symbol}"
15
31
 
16
32
 
17
- def quote(symbol):
18
- return f"https://invest.firstrade.com/cgi-bin/getxml?page=quo&quoteSymbol={symbol}"
33
+ def order():
34
+ return "https://api3x.firstrade.com/private/stock_order"
19
35
 
20
36
 
21
- def orderbar():
22
- return "https://invest.firstrade.com/cgi-bin/orderbar"
37
+ def order_list(account):
38
+ return f"https://api3x.firstrade.com/private/order_status?account={account}"
23
39
 
24
40
 
25
- def account_status():
26
- return "https://invest.firstrade.com/cgi-bin/account_status"
41
+ def account_history(account):
42
+ return f"https://api3x.firstrade.com/private/account_history?range=ytd&page=1&account={account}&per_page=200"
27
43
 
28
- def order_list():
29
- return "https://invest.firstrade.com/cgi-bin/orderstatus"
30
44
 
45
+ def cancel_order():
46
+ return "https://api3x.firstrade.com/private/cancel_order"
31
47
 
32
- def status():
33
- return "https://invest.firstrade.com/scripts/profile/margin_v2.php"
48
+
49
+ def option_dates(symbol):
50
+ return f"https://api3x.firstrade.com/public/oc?m=get_exp_dates&root_symbol={symbol}"
51
+
52
+
53
+ def option_quotes(symbol, date):
54
+ return f"https://api3x.firstrade.com/public/oc?m=get_oc&root_symbol={symbol}&exp_date={date}&chains_range=A"
55
+
56
+
57
+ def greek_options():
58
+ return "https://api3x.firstrade.com/private/greekoptions/analytical"
59
+
60
+
61
+ def option_order():
62
+ return "https://api3x.firstrade.com/private/option_order"
34
63
 
35
64
 
36
65
  def session_headers():
37
66
  headers = {
38
- "Accept": "*/*",
39
- "Accept-Encoding": "gzip, deflate, br",
40
- "Accept-Language": "en-US,en;q=0.9",
41
- "Host": "invest.firstrade.com",
42
- "Referer": "https://invest.firstrade.com/cgi-bin/main",
43
- "Connection": "keep-alive",
44
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36 Edg/116.0.1938.81",
67
+ "Accept-Encoding": "gzip",
68
+ "Connection": "Keep-Alive",
69
+ "Host": "api3x.firstrade.com",
70
+ "User-Agent": "okhttp/4.9.2",
45
71
  }
46
72
  return headers
73
+
74
+
75
+ def access_token():
76
+ return "833w3XuIFycv18ybi"
@@ -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,11 @@
1
+ firstrade/__init__.py,sha256=fNiWYgSTjElY1MNv0Ug-sVLMTR2z_Ngri_FY7Pekdrw,95
2
+ firstrade/account.py,sha256=U9U-LXmOS3pQK7WjQ3oXqlKvl3r-2kphBPvWGsD3q9Y,13287
3
+ firstrade/exceptions.py,sha256=tL9hXGTZM1Ds0yWNCLSqD7hdcL_157CHLJT0e7AjxOg,1893
4
+ firstrade/order.py,sha256=_IwKsJ58A8KxiiaFFNbGBE7sak4G23s4_uFaCSovx00,8789
5
+ firstrade/symbols.py,sha256=9HKvg-rqX3GNCUKHtIOw81_MNkboamihmAaj6MpheW0,7930
6
+ firstrade/urls.py,sha256=7jeIaRERP8yDbZrnw2QcWn2J0z2MYKSNFJhJvef8I2Q,1859
7
+ firstrade-0.0.30.dist-info/LICENSE,sha256=wPEQjDqm5zMBmEcZp219Labmq_YIjhudpZiUzyVKaFA,1057
8
+ firstrade-0.0.30.dist-info/METADATA,sha256=jNfpF431f4pEIsEBTc3dI8IUlIxhI4TZJcoXp0API8U,7186
9
+ firstrade-0.0.30.dist-info/WHEEL,sha256=HiCZjzuy6Dw0hdX5R3LCFPDmFS4BWl8H-8W39XfmgX4,91
10
+ firstrade-0.0.30.dist-info/top_level.txt,sha256=tdA8v-KDxU1u4VV6soiNWGBlni4ojv_t_j2wFn5nZcs,10
11
+ firstrade-0.0.30.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (70.3.0)
2
+ Generator: setuptools (72.2.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,81 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: firstrade
3
- Version: 0.0.20
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/0020.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
- ## Setup
43
-
44
- Install using pypi:
45
-
46
- ```
47
- pip install firstrade
48
- ```
49
-
50
- ## Quikstart
51
-
52
- `Checkout test.py for sample code.`
53
-
54
- This code will:
55
- - Login and print account info.
56
- - Get a quote for 'INTC' and print out the information
57
- - Place a market order for 'INTC' on the first account in the `account_numbers` list
58
- - Print out the order confirmation
59
-
60
- `Checkout test.py for sample code.`
61
-
62
- ---
63
-
64
- ## Implemented Features
65
-
66
- - [x] Login
67
- - [x] Get Quotes
68
- - [x] Get Account Data
69
- - [x] Place Orders and Receive order confirmation
70
- - [x] Get Currently Held Positions
71
- - [x] Fractional Trading support (thanks to @jiak94)
72
- - [x] Check on placed order status. (thanks to @Cfomodz)
73
-
74
- ## TO DO
75
-
76
- - [ ] Cancel placed orders
77
- - [ ] Options
78
- - [ ] Give me some Ideas!
79
-
80
- ## If you would like to support me, you can do so here:
81
- [![GitHub Sponsors](https://img.shields.io/github/sponsors/maxxrk?style=social)](https://github.com/sponsors/maxxrk)
@@ -1,10 +0,0 @@
1
- firstrade/__init__.py,sha256=fNiWYgSTjElY1MNv0Ug-sVLMTR2z_Ngri_FY7Pekdrw,95
2
- firstrade/account.py,sha256=xDgTMXDy2UWUNi4kboXAKKBrbmZGpXLJ11MCHlMvzB0,9218
3
- firstrade/order.py,sha256=chDqutqA3H7_5NMnleGoqD3OdHms4iTCRZ34lKZ1_FU,8507
4
- firstrade/symbols.py,sha256=tZD7jexvyvh1rTaOdAKv_vyZWzpjffvl_nPwBe1QaiA,3633
5
- firstrade/urls.py,sha256=OrfXGDsNpA2rTm4o55KAQzpeigG_pxufWyTDBlbhJYQ,1248
6
- firstrade-0.0.20.dist-info/LICENSE,sha256=wPEQjDqm5zMBmEcZp219Labmq_YIjhudpZiUzyVKaFA,1057
7
- firstrade-0.0.20.dist-info/METADATA,sha256=9Uhmo3S2cvYc5fyTpyACPxHTpCIS5p1GgBOqb2csZ-A,2399
8
- firstrade-0.0.20.dist-info/WHEEL,sha256=Z4pYXqR_rTB7OWNDYFOm1qRk0RX6GFP2o8LgvP453Hk,91
9
- firstrade-0.0.20.dist-info/top_level.txt,sha256=tdA8v-KDxU1u4VV6soiNWGBlni4ojv_t_j2wFn5nZcs,10
10
- firstrade-0.0.20.dist-info/RECORD,,