firstrade 0.0.14__tar.gz → 0.0.16__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,81 @@
1
+ Metadata-Version: 2.1
2
+ Name: firstrade
3
+ Version: 0.0.16
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/0016.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
+ The code below will:
53
+
54
+ - Login and print account info.
55
+ - Get a quote for 'INTC' and print out the information
56
+ - Place a market order for 'INTC' on the first account in the `account_numbers` list
57
+ - Print out the order confirmation
58
+
59
+ `Checkout test.py for sample code.`
60
+
61
+ This code is also in test.py
62
+
63
+ ---
64
+
65
+ ## Implemented Features
66
+
67
+ - [x] Login
68
+ - [x] Get Quotes
69
+ - [x] Get Account Data
70
+ - [x] Place Orders and Receive order confirmation
71
+ - [x] Get Currently Held Positions
72
+ - [x] Fractional Trading support (thanks to @jiak94)
73
+ - [x] Check on placed order status. (thanks to @Cfomodz)
74
+
75
+ ## TO DO
76
+
77
+ - [ ] Cancel placed orders
78
+ - [ ] Options
79
+ - [ ] Give me some Ideas!
80
+
81
+ [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/O5O6PTOYG)
@@ -0,0 +1,56 @@
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
+ ## Setup
18
+
19
+ Install using pypi:
20
+
21
+ ```
22
+ pip install firstrade
23
+ ```
24
+
25
+ ## Quikstart
26
+
27
+ The code below will:
28
+
29
+ - Login and print account info.
30
+ - Get a quote for 'INTC' and print out the information
31
+ - Place a market order for 'INTC' on the first account in the `account_numbers` list
32
+ - Print out the order confirmation
33
+
34
+ `Checkout test.py for sample code.`
35
+
36
+ This code is also in test.py
37
+
38
+ ---
39
+
40
+ ## Implemented Features
41
+
42
+ - [x] Login
43
+ - [x] Get Quotes
44
+ - [x] Get Account Data
45
+ - [x] Place Orders and Receive order confirmation
46
+ - [x] Get Currently Held Positions
47
+ - [x] Fractional Trading support (thanks to @jiak94)
48
+ - [x] Check on placed order status. (thanks to @Cfomodz)
49
+
50
+ ## TO DO
51
+
52
+ - [ ] Cancel placed orders
53
+ - [ ] Options
54
+ - [ ] Give me some Ideas!
55
+
56
+ [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/O5O6PTOYG)
@@ -1,13 +1,12 @@
1
1
  from enum import Enum
2
2
 
3
- from firstrade.account import FTSession
4
- from firstrade import urls
5
-
6
3
  from bs4 import BeautifulSoup
7
4
 
5
+ from firstrade import urls
6
+ from firstrade.account import FTSession
8
7
 
9
- class PriceType(str, Enum):
10
8
 
9
+ class PriceType(str, Enum):
11
10
  """
12
11
  This is an :class: 'enum.Enum'
13
12
  that contains the valid price types for an order.
@@ -22,7 +21,6 @@ class PriceType(str, Enum):
22
21
 
23
22
 
24
23
  class Duration(str, Enum):
25
-
26
24
  """
27
25
  This is an :class:'~enum.Enum'
28
26
  that contains the valid durations for an order.
@@ -36,7 +34,6 @@ class Duration(str, Enum):
36
34
 
37
35
 
38
36
  class OrderType(str, Enum):
39
-
40
37
  """
41
38
  This is an :class:'~enum.Enum'
42
39
  that contains the valid order types for an order.
@@ -49,11 +46,11 @@ class OrderType(str, Enum):
49
46
 
50
47
 
51
48
  class Order:
52
-
53
49
  """
54
50
  This class contains information about an order.
55
51
  It also contains a method to place an order.
56
52
  """
53
+
57
54
  def __init__(self, ft_session: FTSession):
58
55
  self.ft_session = ft_session
59
56
  self.order_confirmation = {}
@@ -68,6 +65,7 @@ class Order:
68
65
  duration: Duration,
69
66
  price=0.00,
70
67
  dry_run=True,
68
+ notional=False,
71
69
  ):
72
70
  """
73
71
  Builds and places an order.
@@ -100,6 +98,7 @@ class Order:
100
98
  "submiturl": "/cgi-bin/orderbar",
101
99
  "orderbar_clordid": "",
102
100
  "orderbar_accountid": "",
101
+ "notional": "yes" if notional else "",
103
102
  "stockorderpage": "yes",
104
103
  "submitOrders": "1",
105
104
  "previewOrders": previewOrders,
@@ -162,3 +161,67 @@ class Order:
162
161
  order_confirmation["actiondata"] = action_data
163
162
  order_confirmation["errcode"] = order_data.find("errcode").text.strip()
164
163
  self.order_confirmation = order_confirmation
164
+
165
+
166
+ def get_orders(ft_session, account):
167
+ """
168
+ Retrieves existing order data for a given account.
169
+
170
+ Args:
171
+ ft_session (FTSession): The session object used for making HTTP requests to Firstrade.
172
+ account (str): Account number of the account to retrieve orders for.
173
+
174
+ Returns:
175
+ list: A list of dictionaries, each containing details about an order.
176
+ """
177
+
178
+ # Data dictionary to send with the request
179
+ data = {
180
+ 'accountId': account,
181
+ }
182
+
183
+ # Post request to retrieve the order data
184
+ response = ft_session.post(url=urls.order_list(), headers=urls.session_headers(), data=data).text
185
+
186
+ # Parse the response using BeautifulSoup
187
+ soup = BeautifulSoup(response, "html.parser")
188
+
189
+ # Find the table containing orders
190
+ table = soup.find('table', class_='tablesorter')
191
+ if not table:
192
+ return []
193
+
194
+ rows = table.find_all('tr')[1:] # skip the header row
195
+
196
+ orders = []
197
+ for row in rows:
198
+ try:
199
+ cells = row.find_all('td')
200
+ tooltip_content = row.find('a', {'class': 'info'}).get('onmouseover')
201
+ tooltip_soup = BeautifulSoup(tooltip_content.split('tooltip.show(')[1].strip("');"), 'html.parser')
202
+ order_ref = tooltip_soup.find(text=lambda text: 'Order Ref' in text)
203
+ order_ref_number = order_ref.split('#: ')[1] if order_ref else None
204
+ status = cells[8]
205
+ # print(status)
206
+ sub_status = status.find('strong')
207
+ # print(sub_status)
208
+ sub_status = sub_status.get_text(strip=True)
209
+ # print(sub_status)
210
+ status = status.find('strong').get_text(strip=True) if status.find('strong') else status.get_text(strip=True)
211
+ order = {
212
+ 'Date/Time': cells[0].get_text(strip=True),
213
+ 'Reference': order_ref_number,
214
+ 'Transaction': cells[1].get_text(strip=True),
215
+ 'Quantity': int(cells[2].get_text(strip=True)),
216
+ 'Symbol': cells[3].get_text(strip=True),
217
+ 'Type': cells[4].get_text(strip=True),
218
+ 'Price': float(cells[5].get_text(strip=True)),
219
+ 'Duration': cells[6].get_text(strip=True),
220
+ 'Instr.': cells[7].get_text(strip=True),
221
+ 'Status': status,
222
+ }
223
+ orders.append(order)
224
+ except Exception as e:
225
+ print(f"Error parsing order: {e}")
226
+
227
+ return orders
@@ -21,6 +21,8 @@ class SymbolQuote:
21
21
  low (float): The lowest price for the symbol during the trading day.
22
22
  volume (str): The volume of shares traded for the symbol.
23
23
  company_name (str): The name of the company associated with the symbol.
24
+ real_time (bool): If the quote is real-time or not
25
+ fractional (bool): If the stock can be traded fractionally, or not
24
26
  """
25
27
 
26
28
  def __init__(self, ft_session: FTSession, symbol: str):
@@ -41,17 +43,19 @@ class SymbolQuote:
41
43
  quote = soup.find("quote")
42
44
  self.symbol = quote.find("symbol").text
43
45
  self.exchange = quote.find("exchange").text
44
- self.bid = float(quote.find("bid").text)
45
- self.ask = float(quote.find("ask").text)
46
- self.last = float(quote.find("last").text)
47
- self.change = float(quote.find("change").text)
46
+ self.bid = float(quote.find("bid").text.replace(",", ""))
47
+ self.ask = float(quote.find("ask").text.replace(",", ""))
48
+ self.last = float(quote.find("last").text.replace(",", ""))
49
+ self.change = float(quote.find("change").text.replace(",", ""))
48
50
  if quote.find("high").text == "N/A":
49
51
  self.high = None
50
52
  else:
51
- self.high = float(quote.find("high").text)
53
+ self.high = float(quote.find("high").text.replace(",", ""))
52
54
  if quote.find("low").text == "N/A":
53
55
  self.low = "None"
54
56
  else:
55
- self.low = float(quote.find("low").text)
57
+ self.low = float(quote.find("low").text.replace(",", ""))
56
58
  self.volume = quote.find("vol").text
57
59
  self.company_name = quote.find("companyname").text
60
+ self.real_time = quote.find("realtime").text == "T"
61
+ self.fractional = quote.find("fractional").text == "T"
@@ -25,6 +25,9 @@ def orderbar():
25
25
  def account_status():
26
26
  return "https://invest.firstrade.com/cgi-bin/account_status"
27
27
 
28
+ def order_list():
29
+ return "https://invest.firstrade.com/cgi-bin/orderstatus"
30
+
28
31
 
29
32
  def status():
30
33
  return "https://invest.firstrade.com/scripts/profile/margin_v2.php"
@@ -0,0 +1,81 @@
1
+ Metadata-Version: 2.1
2
+ Name: firstrade
3
+ Version: 0.0.16
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/0016.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
+ The code below will:
53
+
54
+ - Login and print account info.
55
+ - Get a quote for 'INTC' and print out the information
56
+ - Place a market order for 'INTC' on the first account in the `account_numbers` list
57
+ - Print out the order confirmation
58
+
59
+ `Checkout test.py for sample code.`
60
+
61
+ This code is also in test.py
62
+
63
+ ---
64
+
65
+ ## Implemented Features
66
+
67
+ - [x] Login
68
+ - [x] Get Quotes
69
+ - [x] Get Account Data
70
+ - [x] Place Orders and Receive order confirmation
71
+ - [x] Get Currently Held Positions
72
+ - [x] Fractional Trading support (thanks to @jiak94)
73
+ - [x] Check on placed order status. (thanks to @Cfomodz)
74
+
75
+ ## TO DO
76
+
77
+ - [ ] Cancel placed orders
78
+ - [ ] Options
79
+ - [ ] Give me some Ideas!
80
+
81
+ [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/O5O6PTOYG)
@@ -5,7 +5,7 @@ with open("README.md", "r") as f:
5
5
 
6
6
  setuptools.setup(
7
7
  name="firstrade",
8
- version="0.0.14",
8
+ version="0.0.16",
9
9
  author="MaxxRK",
10
10
  author_email="maxxrk@pm.me",
11
11
  description="An unofficial API for Firstrade",
@@ -13,7 +13,7 @@ setuptools.setup(
13
13
  long_description_content_type="text/markdown",
14
14
  license="MIT",
15
15
  url="https://github.com/MaxxRK/firstrade-api",
16
- download_url="https://github.com/MaxxRK/firstrade-api/archive/refs/tags/0014.tar.gz",
16
+ download_url="https://github.com/MaxxRK/firstrade-api/archive/refs/tags/0016.tar.gz",
17
17
  keywords=["FIRSTRADE", "API"],
18
18
  install_requires=["requests", "beautifulsoup4", "lxml"],
19
19
  packages=["firstrade"],
firstrade-0.0.14/PKG-INFO DELETED
@@ -1,137 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: firstrade
3
- Version: 0.0.14
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/0014.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
- A reverse-engineered python API to interact with the Firstrade Trading platform.
28
-
29
- This is not an official api! This api's functionality may change at any time.
30
-
31
- 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.
32
-
33
- ---
34
-
35
- ## Contribution
36
- I am new to coding and new to open-source. I would love any help and suggestions!
37
-
38
- ## Setup
39
- Install using pypi:
40
- ```
41
- pip install firstrade
42
- ```
43
-
44
- ## Quikstart
45
- The code below will:
46
- - Login and print account info.
47
- - Get a quote for 'INTC' and print out the information
48
- - Place a market order for 'INTC' on the first account in the `account_numbers` list
49
- - Print out the order confirmation
50
-
51
- ```
52
- from firstrade import account, order, symbols
53
-
54
- # Create a session
55
- ft_ss = account.FTSession(username="", password="", pin="")
56
-
57
- # Get account data
58
- ft_accounts = account.FTAccountData(ft_ss)
59
- if len(ft_accounts.account_numbers) < 1:
60
- raise Exception("No accounts found or an error occured exiting...")
61
-
62
- # Print ALL account data
63
- print(ft_accounts.all_accounts)
64
-
65
- # Print 1st account number.
66
- print(ft_accounts.account_numbers[0])
67
-
68
- # Print ALL accounts market values.
69
- print(ft_accounts.account_balances)
70
-
71
- # Get quote for INTC
72
- quote = symbols.SymbolQuote(ft_ss, "INTC")
73
- print(f"Symbol: {quote.symbol}")
74
- print(f"Exchange: {quote.exchange}")
75
- print(f"Bid: {quote.bid}")
76
- print(f"Ask: {quote.ask}")
77
- print(f"Last: {quote.last}")
78
- print(f"Change: {quote.change}")
79
- print(f"High: {quote.high}")
80
- print(f"Low: {quote.low}")
81
- print(f"Volume: {quote.volume}")
82
- print(f"Company Name: {quote.company_name}")
83
-
84
- # Get positions and print them out for an account.
85
- positions = ft_accounts.get_positions(account=ft_accounts.account_numbers[1])
86
- for key in ft_accounts.securities_held:
87
- print(
88
- f"Quantity {ft_accounts.securities_held[key]['quantity']} of security {key} held in account {ft_accounts.account_numbers[1]}"
89
- )
90
-
91
- # Create an order object.
92
- ft_order = order.Order(ft_ss)
93
-
94
- # Place order and print out order confirmation data.
95
- ft_order.place_order(
96
- ft_accounts.account_numbers[0],
97
- symbol="INTC",
98
- price_type=order.PriceType.MARKET,
99
- order_type=order.OrderType.BUY,
100
- quantity=1,
101
- duration=order.Duration.DAY,
102
- dry_run=True,
103
- )
104
-
105
- # Print Order data Dict
106
- print(ft_order.order_confirmation)
107
-
108
- # Check if order was successful
109
- if ft_order.order_confirmation["success"] == "Yes":
110
- print("Order placed successfully.")
111
- # Print Order ID
112
- print(f"Order ID: {ft_order.order_confirmation['orderid']}.")
113
- else:
114
- print("Failed to place order.")
115
- # Print errormessage
116
- print(ft_order.order_confirmation["actiondata"])
117
- # Delete cookies
118
- ft_ss.delete_cookies()
119
- ```
120
- This code is also in test.py
121
-
122
- ---
123
-
124
- ## Implemented Features
125
- - [x] Login
126
- - [x] Get Quotes
127
- - [x] Get Account Data
128
- - [x] Place Orders and Receive order confirmation
129
- - [x] Get Currently Held Positions
130
-
131
- ## TO DO
132
- - [ ] Check on placed order status.
133
- - [ ] Cancel placed orders
134
- - [ ] Options
135
- - [ ] Give me some Ideas!
136
-
137
- [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/O5O6PTOYG)
@@ -1,112 +0,0 @@
1
- # firstrade-api
2
- A reverse-engineered python API to interact with the Firstrade Trading platform.
3
-
4
- This is not an official api! This api's functionality may change at any time.
5
-
6
- 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.
7
-
8
- ---
9
-
10
- ## Contribution
11
- I am new to coding and new to open-source. I would love any help and suggestions!
12
-
13
- ## Setup
14
- Install using pypi:
15
- ```
16
- pip install firstrade
17
- ```
18
-
19
- ## Quikstart
20
- The code below will:
21
- - Login and print account info.
22
- - Get a quote for 'INTC' and print out the information
23
- - Place a market order for 'INTC' on the first account in the `account_numbers` list
24
- - Print out the order confirmation
25
-
26
- ```
27
- from firstrade import account, order, symbols
28
-
29
- # Create a session
30
- ft_ss = account.FTSession(username="", password="", pin="")
31
-
32
- # Get account data
33
- ft_accounts = account.FTAccountData(ft_ss)
34
- if len(ft_accounts.account_numbers) < 1:
35
- raise Exception("No accounts found or an error occured exiting...")
36
-
37
- # Print ALL account data
38
- print(ft_accounts.all_accounts)
39
-
40
- # Print 1st account number.
41
- print(ft_accounts.account_numbers[0])
42
-
43
- # Print ALL accounts market values.
44
- print(ft_accounts.account_balances)
45
-
46
- # Get quote for INTC
47
- quote = symbols.SymbolQuote(ft_ss, "INTC")
48
- print(f"Symbol: {quote.symbol}")
49
- print(f"Exchange: {quote.exchange}")
50
- print(f"Bid: {quote.bid}")
51
- print(f"Ask: {quote.ask}")
52
- print(f"Last: {quote.last}")
53
- print(f"Change: {quote.change}")
54
- print(f"High: {quote.high}")
55
- print(f"Low: {quote.low}")
56
- print(f"Volume: {quote.volume}")
57
- print(f"Company Name: {quote.company_name}")
58
-
59
- # Get positions and print them out for an account.
60
- positions = ft_accounts.get_positions(account=ft_accounts.account_numbers[1])
61
- for key in ft_accounts.securities_held:
62
- print(
63
- f"Quantity {ft_accounts.securities_held[key]['quantity']} of security {key} held in account {ft_accounts.account_numbers[1]}"
64
- )
65
-
66
- # Create an order object.
67
- ft_order = order.Order(ft_ss)
68
-
69
- # Place order and print out order confirmation data.
70
- ft_order.place_order(
71
- ft_accounts.account_numbers[0],
72
- symbol="INTC",
73
- price_type=order.PriceType.MARKET,
74
- order_type=order.OrderType.BUY,
75
- quantity=1,
76
- duration=order.Duration.DAY,
77
- dry_run=True,
78
- )
79
-
80
- # Print Order data Dict
81
- print(ft_order.order_confirmation)
82
-
83
- # Check if order was successful
84
- if ft_order.order_confirmation["success"] == "Yes":
85
- print("Order placed successfully.")
86
- # Print Order ID
87
- print(f"Order ID: {ft_order.order_confirmation['orderid']}.")
88
- else:
89
- print("Failed to place order.")
90
- # Print errormessage
91
- print(ft_order.order_confirmation["actiondata"])
92
- # Delete cookies
93
- ft_ss.delete_cookies()
94
- ```
95
- This code is also in test.py
96
-
97
- ---
98
-
99
- ## Implemented Features
100
- - [x] Login
101
- - [x] Get Quotes
102
- - [x] Get Account Data
103
- - [x] Place Orders and Receive order confirmation
104
- - [x] Get Currently Held Positions
105
-
106
- ## TO DO
107
- - [ ] Check on placed order status.
108
- - [ ] Cancel placed orders
109
- - [ ] Options
110
- - [ ] Give me some Ideas!
111
-
112
- [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/O5O6PTOYG)
@@ -1,137 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: firstrade
3
- Version: 0.0.14
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/0014.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
- A reverse-engineered python API to interact with the Firstrade Trading platform.
28
-
29
- This is not an official api! This api's functionality may change at any time.
30
-
31
- 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.
32
-
33
- ---
34
-
35
- ## Contribution
36
- I am new to coding and new to open-source. I would love any help and suggestions!
37
-
38
- ## Setup
39
- Install using pypi:
40
- ```
41
- pip install firstrade
42
- ```
43
-
44
- ## Quikstart
45
- The code below will:
46
- - Login and print account info.
47
- - Get a quote for 'INTC' and print out the information
48
- - Place a market order for 'INTC' on the first account in the `account_numbers` list
49
- - Print out the order confirmation
50
-
51
- ```
52
- from firstrade import account, order, symbols
53
-
54
- # Create a session
55
- ft_ss = account.FTSession(username="", password="", pin="")
56
-
57
- # Get account data
58
- ft_accounts = account.FTAccountData(ft_ss)
59
- if len(ft_accounts.account_numbers) < 1:
60
- raise Exception("No accounts found or an error occured exiting...")
61
-
62
- # Print ALL account data
63
- print(ft_accounts.all_accounts)
64
-
65
- # Print 1st account number.
66
- print(ft_accounts.account_numbers[0])
67
-
68
- # Print ALL accounts market values.
69
- print(ft_accounts.account_balances)
70
-
71
- # Get quote for INTC
72
- quote = symbols.SymbolQuote(ft_ss, "INTC")
73
- print(f"Symbol: {quote.symbol}")
74
- print(f"Exchange: {quote.exchange}")
75
- print(f"Bid: {quote.bid}")
76
- print(f"Ask: {quote.ask}")
77
- print(f"Last: {quote.last}")
78
- print(f"Change: {quote.change}")
79
- print(f"High: {quote.high}")
80
- print(f"Low: {quote.low}")
81
- print(f"Volume: {quote.volume}")
82
- print(f"Company Name: {quote.company_name}")
83
-
84
- # Get positions and print them out for an account.
85
- positions = ft_accounts.get_positions(account=ft_accounts.account_numbers[1])
86
- for key in ft_accounts.securities_held:
87
- print(
88
- f"Quantity {ft_accounts.securities_held[key]['quantity']} of security {key} held in account {ft_accounts.account_numbers[1]}"
89
- )
90
-
91
- # Create an order object.
92
- ft_order = order.Order(ft_ss)
93
-
94
- # Place order and print out order confirmation data.
95
- ft_order.place_order(
96
- ft_accounts.account_numbers[0],
97
- symbol="INTC",
98
- price_type=order.PriceType.MARKET,
99
- order_type=order.OrderType.BUY,
100
- quantity=1,
101
- duration=order.Duration.DAY,
102
- dry_run=True,
103
- )
104
-
105
- # Print Order data Dict
106
- print(ft_order.order_confirmation)
107
-
108
- # Check if order was successful
109
- if ft_order.order_confirmation["success"] == "Yes":
110
- print("Order placed successfully.")
111
- # Print Order ID
112
- print(f"Order ID: {ft_order.order_confirmation['orderid']}.")
113
- else:
114
- print("Failed to place order.")
115
- # Print errormessage
116
- print(ft_order.order_confirmation["actiondata"])
117
- # Delete cookies
118
- ft_ss.delete_cookies()
119
- ```
120
- This code is also in test.py
121
-
122
- ---
123
-
124
- ## Implemented Features
125
- - [x] Login
126
- - [x] Get Quotes
127
- - [x] Get Account Data
128
- - [x] Place Orders and Receive order confirmation
129
- - [x] Get Currently Held Positions
130
-
131
- ## TO DO
132
- - [ ] Check on placed order status.
133
- - [ ] Cancel placed orders
134
- - [ ] Options
135
- - [ ] Give me some Ideas!
136
-
137
- [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/O5O6PTOYG)
File without changes
File without changes