firstrade 0.0.13__tar.gz → 0.0.15__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.
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: firstrade
3
- Version: 0.0.13
3
+ Version: 0.0.15
4
4
  Summary: An unofficial API for Firstrade
5
5
  Home-page: https://github.com/MaxxRK/firstrade-api
6
- Download-URL: https://github.com/MaxxRK/firstrade-api/archive/refs/tags/0013.tar.gz
6
+ Download-URL: https://github.com/MaxxRK/firstrade-api/archive/refs/tags/0015.tar.gz
7
7
  Author: MaxxRK
8
8
  Author-email: maxxrk@pm.me
9
9
  License: MIT
@@ -24,42 +24,48 @@ Requires-Dist: beautifulsoup4
24
24
  Requires-Dist: lxml
25
25
 
26
26
  # firstrade-api
27
- A reverse-engineered python API to interact with the Firstrade Trading platform.
28
27
 
29
- This is not an official api! This api's functionality may change at any time.
28
+ A reverse-engineered python API to interact with the Firstrade Trading platform.
30
29
 
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.
30
+ This is not an official api! This api's functionality may change at any time.
32
31
 
33
- ---
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
+ ---
34
37
 
35
38
  ## Contribution
39
+
36
40
  I am new to coding and new to open-source. I would love any help and suggestions!
37
41
 
38
42
  ## Setup
43
+
39
44
  Install using pypi:
45
+
40
46
  ```
41
47
  pip install firstrade
42
48
  ```
43
49
 
44
50
  ## Quikstart
45
- The code below will:
46
- - Login and print account info.
51
+
52
+ The code below will:
53
+
54
+ - Login and print account info.
47
55
  - Get a quote for 'INTC' and print out the information
48
56
  - Place a market order for 'INTC' on the first account in the `account_numbers` list
49
57
  - Print out the order confirmation
50
58
 
51
59
  ```
52
- from firstrade import account
53
- from firstrade import symbols
54
- from firstrade import order
60
+ from firstrade import account, order, symbols
55
61
 
56
62
  # Create a session
57
- ft_ss = account.FTSession(username='', password='', pin='')
63
+ ft_ss = account.FTSession(username="", password="", pin="")
58
64
 
59
65
  # Get account data
60
66
  ft_accounts = account.FTAccountData(ft_ss)
61
67
  if len(ft_accounts.account_numbers) < 1:
62
- raise Exception('No accounts found or an error occured exiting...')
68
+ raise Exception("No accounts found or an error occured exiting...")
63
69
 
64
70
  # Print ALL account data
65
71
  print(ft_accounts.all_accounts)
@@ -71,7 +77,7 @@ print(ft_accounts.account_numbers[0])
71
77
  print(ft_accounts.account_balances)
72
78
 
73
79
  # Get quote for INTC
74
- quote = symbols.SymbolQuote(ft_ss, 'INTC')
80
+ quote = symbols.SymbolQuote(ft_ss, "INTC")
75
81
  print(f"Symbol: {quote.symbol}")
76
82
  print(f"Exchange: {quote.exchange}")
77
83
  print(f"Bid: {quote.bid}")
@@ -86,50 +92,58 @@ print(f"Company Name: {quote.company_name}")
86
92
  # Get positions and print them out for an account.
87
93
  positions = ft_accounts.get_positions(account=ft_accounts.account_numbers[1])
88
94
  for key in ft_accounts.securities_held:
89
- print(f"Quantity {ft_accounts.securities_held[key]['quantity']} of security {key} held in account {ft_accounts.account_numbers[1]}")
95
+ print(
96
+ f"Quantity {ft_accounts.securities_held[key]['quantity']} of security {key} held in account {ft_accounts.account_numbers[1]}"
97
+ )
90
98
 
91
- # Create an order object.
99
+ # Create an order object.
92
100
  ft_order = order.Order(ft_ss)
93
101
 
94
102
  # Place order and print out order confirmation data.
95
103
  ft_order.place_order(
96
104
  ft_accounts.account_numbers[0],
97
- symbol='INTC',
105
+ symbol="INTC",
98
106
  price_type=order.PriceType.MARKET,
99
107
  order_type=order.OrderType.BUY,
100
- quantity=1,
108
+ quantity=1, # number of shares or amount of dollar, depends on the value of notional
101
109
  duration=order.Duration.DAY,
102
- dry_run=True
110
+ dry_run=True,
111
+ notional=False, # set to True if quantity above is "dollar"
103
112
  )
104
113
 
105
114
  # Print Order data Dict
106
115
  print(ft_order.order_confirmation)
107
116
 
108
117
  # Check if order was successful
109
- if ft_order.order_confirmation['success'] == 'Yes':
110
- print('Order placed successfully.')
118
+ if ft_order.order_confirmation["success"] == "Yes":
119
+ print("Order placed successfully.")
111
120
  # Print Order ID
112
121
  print(f"Order ID: {ft_order.order_confirmation['orderid']}.")
113
122
  else:
114
- print('Failed to place order.')
123
+ print("Failed to place order.")
115
124
  # Print errormessage
116
- print(ft_order.order_confirmation['actiondata'])
125
+ print(ft_order.order_confirmation["actiondata"])
126
+ # Delete cookies
127
+ ft_ss.delete_cookies()
117
128
  ```
129
+
118
130
  This code is also in test.py
119
131
 
120
132
  ---
121
133
 
122
- ## Implemented Features
123
- - [x] Login
124
- - [x] Get Quotes
125
- - [x] Get Account Data
126
- - [x] Place Orders and Receive order confirmation
127
- - [x] Get Currently Held Positions
134
+ ## Implemented Features
135
+
136
+ - [x] Login
137
+ - [x] Get Quotes
138
+ - [x] Get Account Data
139
+ - [x] Place Orders and Receive order confirmation
140
+ - [x] Get Currently Held Positions
128
141
 
129
142
  ## TO DO
130
- - [ ] Check on placed order status.
131
- - [ ] Cancel placed orders
132
- - [ ] Options
133
- - [ ] Give me some Ideas!
134
143
 
135
- [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/O5O6PTOYG)
144
+ - [ ] Check on placed order status.
145
+ - [ ] Cancel placed orders
146
+ - [ ] Options
147
+ - [ ] Give me some Ideas!
148
+
149
+ [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/O5O6PTOYG)
@@ -1,40 +1,46 @@
1
1
  # firstrade-api
2
- A reverse-engineered python API to interact with the Firstrade Trading platform.
3
2
 
4
- This is not an official api! This api's functionality may change at any time.
3
+ A reverse-engineered python API to interact with the Firstrade Trading platform.
5
4
 
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.
5
+ This is not an official api! This api's functionality may change at any time.
7
6
 
8
- ---
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
+ ---
9
12
 
10
13
  ## Contribution
14
+
11
15
  I am new to coding and new to open-source. I would love any help and suggestions!
12
16
 
13
17
  ## Setup
18
+
14
19
  Install using pypi:
20
+
15
21
  ```
16
22
  pip install firstrade
17
23
  ```
18
24
 
19
25
  ## Quikstart
20
- The code below will:
21
- - Login and print account info.
26
+
27
+ The code below will:
28
+
29
+ - Login and print account info.
22
30
  - Get a quote for 'INTC' and print out the information
23
31
  - Place a market order for 'INTC' on the first account in the `account_numbers` list
24
32
  - Print out the order confirmation
25
33
 
26
34
  ```
27
- from firstrade import account
28
- from firstrade import symbols
29
- from firstrade import order
35
+ from firstrade import account, order, symbols
30
36
 
31
37
  # Create a session
32
- ft_ss = account.FTSession(username='', password='', pin='')
38
+ ft_ss = account.FTSession(username="", password="", pin="")
33
39
 
34
40
  # Get account data
35
41
  ft_accounts = account.FTAccountData(ft_ss)
36
42
  if len(ft_accounts.account_numbers) < 1:
37
- raise Exception('No accounts found or an error occured exiting...')
43
+ raise Exception("No accounts found or an error occured exiting...")
38
44
 
39
45
  # Print ALL account data
40
46
  print(ft_accounts.all_accounts)
@@ -46,7 +52,7 @@ print(ft_accounts.account_numbers[0])
46
52
  print(ft_accounts.account_balances)
47
53
 
48
54
  # Get quote for INTC
49
- quote = symbols.SymbolQuote(ft_ss, 'INTC')
55
+ quote = symbols.SymbolQuote(ft_ss, "INTC")
50
56
  print(f"Symbol: {quote.symbol}")
51
57
  print(f"Exchange: {quote.exchange}")
52
58
  print(f"Bid: {quote.bid}")
@@ -61,50 +67,58 @@ print(f"Company Name: {quote.company_name}")
61
67
  # Get positions and print them out for an account.
62
68
  positions = ft_accounts.get_positions(account=ft_accounts.account_numbers[1])
63
69
  for key in ft_accounts.securities_held:
64
- print(f"Quantity {ft_accounts.securities_held[key]['quantity']} of security {key} held in account {ft_accounts.account_numbers[1]}")
70
+ print(
71
+ f"Quantity {ft_accounts.securities_held[key]['quantity']} of security {key} held in account {ft_accounts.account_numbers[1]}"
72
+ )
65
73
 
66
- # Create an order object.
74
+ # Create an order object.
67
75
  ft_order = order.Order(ft_ss)
68
76
 
69
77
  # Place order and print out order confirmation data.
70
78
  ft_order.place_order(
71
79
  ft_accounts.account_numbers[0],
72
- symbol='INTC',
80
+ symbol="INTC",
73
81
  price_type=order.PriceType.MARKET,
74
82
  order_type=order.OrderType.BUY,
75
- quantity=1,
83
+ quantity=1, # number of shares or amount of dollar, depends on the value of notional
76
84
  duration=order.Duration.DAY,
77
- dry_run=True
85
+ dry_run=True,
86
+ notional=False, # set to True if quantity above is "dollar"
78
87
  )
79
88
 
80
89
  # Print Order data Dict
81
90
  print(ft_order.order_confirmation)
82
91
 
83
92
  # Check if order was successful
84
- if ft_order.order_confirmation['success'] == 'Yes':
85
- print('Order placed successfully.')
93
+ if ft_order.order_confirmation["success"] == "Yes":
94
+ print("Order placed successfully.")
86
95
  # Print Order ID
87
96
  print(f"Order ID: {ft_order.order_confirmation['orderid']}.")
88
97
  else:
89
- print('Failed to place order.')
98
+ print("Failed to place order.")
90
99
  # Print errormessage
91
- print(ft_order.order_confirmation['actiondata'])
100
+ print(ft_order.order_confirmation["actiondata"])
101
+ # Delete cookies
102
+ ft_ss.delete_cookies()
92
103
  ```
104
+
93
105
  This code is also in test.py
94
106
 
95
107
  ---
96
108
 
97
- ## Implemented Features
98
- - [x] Login
99
- - [x] Get Quotes
100
- - [x] Get Account Data
101
- - [x] Place Orders and Receive order confirmation
102
- - [x] Get Currently Held Positions
109
+ ## Implemented Features
110
+
111
+ - [x] Login
112
+ - [x] Get Quotes
113
+ - [x] Get Account Data
114
+ - [x] Place Orders and Receive order confirmation
115
+ - [x] Get Currently Held Positions
103
116
 
104
117
  ## TO DO
105
- - [ ] Check on placed order status.
106
- - [ ] Cancel placed orders
107
- - [ ] Options
108
- - [ ] Give me some Ideas!
109
118
 
110
- [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/O5O6PTOYG)
119
+ - [ ] Check on placed order status.
120
+ - [ ] Cancel placed orders
121
+ - [ ] Options
122
+ - [ ] Give me some Ideas!
123
+
124
+ [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/O5O6PTOYG)
@@ -70,8 +70,7 @@ class FTSession:
70
70
  self.session.post(
71
71
  url=urls.pin(), headers=headers, cookies=self.session.cookies, data=data
72
72
  )
73
- if self.profile_path is not None:
74
- self.save_cookies()
73
+ self.save_cookies()
75
74
  if (
76
75
  "/cgi-bin/sessionfailed?reason=6"
77
76
  in self.session.get(
@@ -88,15 +87,16 @@ class FTSession:
88
87
  Dict: Dictionary of cookies. Nom Nom
89
88
  """
90
89
  cookies = {}
91
- if self.profile_path is not None:
92
- directory = os.path.abspath(self.profile_path)
93
- if not os.path.exists(directory):
94
- os.makedirs(directory)
95
- for filename in os.listdir(directory):
96
- if filename.endswith(f"{self.username}.pkl"):
97
- filepath = os.path.join(directory, filename)
98
- with open(filepath, "rb") as f:
99
- cookies = pickle.load(f)
90
+ directory = os.path.abspath(self.profile_path) if self.profile_path is not None else "."
91
+
92
+ if not os.path.exists(directory):
93
+ os.makedirs(directory)
94
+
95
+ for filename in os.listdir(directory):
96
+ if filename.endswith(f"{self.username}.pkl"):
97
+ filepath = os.path.join(directory, filename)
98
+ with open(filepath, "rb") as f:
99
+ cookies = pickle.load(f)
100
100
  return cookies
101
101
 
102
102
  def save_cookies(self):
@@ -110,6 +110,14 @@ class FTSession:
110
110
  path = f"ft_cookies{self.username}.pkl"
111
111
  with open(path, "wb") as f:
112
112
  pickle.dump(self.session.cookies.get_dict(), f)
113
+
114
+ def delete_cookies(self):
115
+ """Deletes the session cookies."""
116
+ if self.profile_path is not None:
117
+ path = os.path.join(self.profile_path, f"ft_cookies{self.username}.pkl")
118
+ else:
119
+ path = f"ft_cookies{self.username}.pkl"
120
+ os.remove(path)
113
121
 
114
122
  def __getattr__(self, name):
115
123
  """
@@ -68,6 +68,7 @@ class Order:
68
68
  duration: Duration,
69
69
  price=0.00,
70
70
  dry_run=True,
71
+ notional=False,
71
72
  ):
72
73
  """
73
74
  Builds and places an order.
@@ -100,6 +101,7 @@ class Order:
100
101
  "submiturl": "/cgi-bin/orderbar",
101
102
  "orderbar_clordid": "",
102
103
  "orderbar_accountid": "",
104
+ "notional": "yes" if notional else "",
103
105
  "stockorderpage": "yes",
104
106
  "submitOrders": "1",
105
107
  "previewOrders": previewOrders,
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: firstrade
3
- Version: 0.0.13
3
+ Version: 0.0.15
4
4
  Summary: An unofficial API for Firstrade
5
5
  Home-page: https://github.com/MaxxRK/firstrade-api
6
- Download-URL: https://github.com/MaxxRK/firstrade-api/archive/refs/tags/0013.tar.gz
6
+ Download-URL: https://github.com/MaxxRK/firstrade-api/archive/refs/tags/0015.tar.gz
7
7
  Author: MaxxRK
8
8
  Author-email: maxxrk@pm.me
9
9
  License: MIT
@@ -24,42 +24,48 @@ Requires-Dist: beautifulsoup4
24
24
  Requires-Dist: lxml
25
25
 
26
26
  # firstrade-api
27
- A reverse-engineered python API to interact with the Firstrade Trading platform.
28
27
 
29
- This is not an official api! This api's functionality may change at any time.
28
+ A reverse-engineered python API to interact with the Firstrade Trading platform.
30
29
 
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.
30
+ This is not an official api! This api's functionality may change at any time.
32
31
 
33
- ---
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
+ ---
34
37
 
35
38
  ## Contribution
39
+
36
40
  I am new to coding and new to open-source. I would love any help and suggestions!
37
41
 
38
42
  ## Setup
43
+
39
44
  Install using pypi:
45
+
40
46
  ```
41
47
  pip install firstrade
42
48
  ```
43
49
 
44
50
  ## Quikstart
45
- The code below will:
46
- - Login and print account info.
51
+
52
+ The code below will:
53
+
54
+ - Login and print account info.
47
55
  - Get a quote for 'INTC' and print out the information
48
56
  - Place a market order for 'INTC' on the first account in the `account_numbers` list
49
57
  - Print out the order confirmation
50
58
 
51
59
  ```
52
- from firstrade import account
53
- from firstrade import symbols
54
- from firstrade import order
60
+ from firstrade import account, order, symbols
55
61
 
56
62
  # Create a session
57
- ft_ss = account.FTSession(username='', password='', pin='')
63
+ ft_ss = account.FTSession(username="", password="", pin="")
58
64
 
59
65
  # Get account data
60
66
  ft_accounts = account.FTAccountData(ft_ss)
61
67
  if len(ft_accounts.account_numbers) < 1:
62
- raise Exception('No accounts found or an error occured exiting...')
68
+ raise Exception("No accounts found or an error occured exiting...")
63
69
 
64
70
  # Print ALL account data
65
71
  print(ft_accounts.all_accounts)
@@ -71,7 +77,7 @@ print(ft_accounts.account_numbers[0])
71
77
  print(ft_accounts.account_balances)
72
78
 
73
79
  # Get quote for INTC
74
- quote = symbols.SymbolQuote(ft_ss, 'INTC')
80
+ quote = symbols.SymbolQuote(ft_ss, "INTC")
75
81
  print(f"Symbol: {quote.symbol}")
76
82
  print(f"Exchange: {quote.exchange}")
77
83
  print(f"Bid: {quote.bid}")
@@ -86,50 +92,58 @@ print(f"Company Name: {quote.company_name}")
86
92
  # Get positions and print them out for an account.
87
93
  positions = ft_accounts.get_positions(account=ft_accounts.account_numbers[1])
88
94
  for key in ft_accounts.securities_held:
89
- print(f"Quantity {ft_accounts.securities_held[key]['quantity']} of security {key} held in account {ft_accounts.account_numbers[1]}")
95
+ print(
96
+ f"Quantity {ft_accounts.securities_held[key]['quantity']} of security {key} held in account {ft_accounts.account_numbers[1]}"
97
+ )
90
98
 
91
- # Create an order object.
99
+ # Create an order object.
92
100
  ft_order = order.Order(ft_ss)
93
101
 
94
102
  # Place order and print out order confirmation data.
95
103
  ft_order.place_order(
96
104
  ft_accounts.account_numbers[0],
97
- symbol='INTC',
105
+ symbol="INTC",
98
106
  price_type=order.PriceType.MARKET,
99
107
  order_type=order.OrderType.BUY,
100
- quantity=1,
108
+ quantity=1, # number of shares or amount of dollar, depends on the value of notional
101
109
  duration=order.Duration.DAY,
102
- dry_run=True
110
+ dry_run=True,
111
+ notional=False, # set to True if quantity above is "dollar"
103
112
  )
104
113
 
105
114
  # Print Order data Dict
106
115
  print(ft_order.order_confirmation)
107
116
 
108
117
  # Check if order was successful
109
- if ft_order.order_confirmation['success'] == 'Yes':
110
- print('Order placed successfully.')
118
+ if ft_order.order_confirmation["success"] == "Yes":
119
+ print("Order placed successfully.")
111
120
  # Print Order ID
112
121
  print(f"Order ID: {ft_order.order_confirmation['orderid']}.")
113
122
  else:
114
- print('Failed to place order.')
123
+ print("Failed to place order.")
115
124
  # Print errormessage
116
- print(ft_order.order_confirmation['actiondata'])
125
+ print(ft_order.order_confirmation["actiondata"])
126
+ # Delete cookies
127
+ ft_ss.delete_cookies()
117
128
  ```
129
+
118
130
  This code is also in test.py
119
131
 
120
132
  ---
121
133
 
122
- ## Implemented Features
123
- - [x] Login
124
- - [x] Get Quotes
125
- - [x] Get Account Data
126
- - [x] Place Orders and Receive order confirmation
127
- - [x] Get Currently Held Positions
134
+ ## Implemented Features
135
+
136
+ - [x] Login
137
+ - [x] Get Quotes
138
+ - [x] Get Account Data
139
+ - [x] Place Orders and Receive order confirmation
140
+ - [x] Get Currently Held Positions
128
141
 
129
142
  ## TO DO
130
- - [ ] Check on placed order status.
131
- - [ ] Cancel placed orders
132
- - [ ] Options
133
- - [ ] Give me some Ideas!
134
143
 
135
- [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/O5O6PTOYG)
144
+ - [ ] Check on placed order status.
145
+ - [ ] Cancel placed orders
146
+ - [ ] Options
147
+ - [ ] Give me some Ideas!
148
+
149
+ [![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.13",
8
+ version="0.0.15",
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/0013.tar.gz",
16
+ download_url="https://github.com/MaxxRK/firstrade-api/archive/refs/tags/0015.tar.gz",
17
17
  keywords=["FIRSTRADE", "API"],
18
18
  install_requires=["requests", "beautifulsoup4", "lxml"],
19
19
  packages=["firstrade"],
File without changes
File without changes
File without changes