FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Python-TradeStation-API-Code/Get_Tokenv1.0.py at master · qsor27/Python-TradeStation-API-Code · GitHub
qsor27
/
Python-TradeStation-API-Code
Public
forked from
edwarddklee/Python-TradeStation-API-Code
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Python-TradeStation-API-Code
/
Get_Tokenv1.0.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
35 lines (30 loc) · 1.65 KB
Breadcrumbs
Python-TradeStation-API-Code
/
Get_Tokenv1.0.py
Copy path
File metadata and controls
35 lines (30 loc) · 1.65 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import
pandas
as
pd
from
datetime
import
datetime
,
time
import
requests
api_key
=
"api_key_here"
api_secret
=
"api_secret_here"
stream_url
=
"https://api.tradestation.com/v2/stream"
authorize_url
=
"https://api.tradestation.com/v2/authorize/"
v2_url
=
"https://api.tradestation.com/v2/"
redirect_uri
=
"https://www.tradestation.com/"
token_url
=
"https://api.tradestation.com/v2/security/authorize"
client_auth
=
requests
.
auth
.
HTTPBasicAuth
(
api_key
,
api_secret
)
authorization_redirect_url
=
authorize_url
+
"?redirect_uri="
+
redirect_uri
+
"&client_id="
+
api_key
+
"&response_type=code"
print
(
"Please go to url below and log in. Then copy authorization code from url: "
)
print
(
"--- "
+
authorization_redirect_url
+
" ---"
)
authorization_code
=
input
(
"Put authorization code here:"
)
#
client_auth
=
requests
.
auth
.
HTTPBasicAuth
(
api_key
,
api_secret
)
data
=
"grant_type=authorization_code&client_id="
+
api_key
+
"&redirect_uri="
+
redirect_uri
+
"&client_secret="
+
api_secret
+
"&code="
+
authorization_code
+
"&response_type=token"
headers
=
{
"Content-Type"
:
"application/x-www-form-urlencoded"
,
"Content-Length"
:
"630"
}
#response call using requests library
response
=
requests
.
post
(
token_url
,
auth
=
client_auth
,
headers
=
headers
,
data
=
data
)
if
response
.
status_code
!=
200
:
print
(
'Status:'
,
response
.
status_code
,
'Problem with the request. Exiting.'
)
exit
()
#access token: can expire
response_access
=
response
.
json
()[
'access_token'
]
#refresh token: cannot expire
response_token
=
response
.
json
()[
'refresh_token'
]
print
(
"Here is your new refresh token, please update file as necessary and re-run program:
\n
"
)
print
(
response_token
)
Back
|
FazBrowse Home
|
New Git URL