🖥️
AutoShares
  • Deploy Apps with AutoShares API
  • User guide
    • Introduction
    • Web Trader
      • Getting Started
      • Platform Layout
      • User Widgets
        • Account Information
        • Account Opening
          • Account Funding
            • ACH Transfers
            • Check Transfers
            • Wire Transfers
        • Chart
        • News
        • Trade Ticket
          • Mutual Funds Trade Ticket
        • Watchlists
        • Orders
        • Positions
        • Market Depth
        • Options
        • Hotkeys
    • Digital Advisor
      • Getting Started
      • Selecting an Investment Model
      • Portfolio Tab
      • Trading Tab
      • Activity Tab
      • Funding Tab
    • WebTrader for iOS
      • Getting Started
      • App Layout
      • Watchlist & Quotes View
        • Trade View
          • Stock Trading
          • Options Trading
      • Positions View
      • Orders View
      • Price Alerts View
      • Account View
      • Apple Watch Extension
    • Web Trader for Android
      • Getting Started
      • App Layout
      • Watchlist & Quote View
        • Trade View
      • Price Alerts
      • Accounts & Settings
    • Knowledge Base
      • Troubleshooting
        • Performance
          • Tips for Enhancing Performance
      • How-To Guides
        • Trading Accounts
          • How to Create a New Trading Account
        • Security
          • How to Enable Two-Factor Authentication
  • REST API
    • Introduction
    • Trading API
      • Overview
      • Authentication
        • Single-Factor Authentication
          • Syntax
        • Two-Factor Authentication
          • Syntax
      • User Registration
        • Get Required Fields
        • Register a User
      • Managing Users
        • Get User's Info
          • Syntax
        • Get User's Trading Settings
        • Get Mobile App Settings
        • Get User's Exchanges
        • Modify User's Settings
        • Update User's Password
      • Trading Accounts
        • Get Account's Balance Info
          • Syntax
        • Get Account's History
          • Syntax
        • List User's Accounts
          • Syntax
      • Password Reset
        • 1. Reset Trader's Password
        • 2. Retrieve the Secret Question
        • 3. Generate a Token For a New Password
        • 4. Update the Password
      • Trading Accounts
        • Open a New Trading Account
      • Account Funding
        • Create an ACH Relationship
        • Get an ACH Relationship
        • Get All ACH Relationships
        • Get the Default ACH Relationship
        • Modify an ACH Relationship
        • Delete an ACH Relationship
        • Approve an ACH Relationship
        • Deposit / Withdraw Funds via ACH
        • Cancel an ACH Transfer
        • Get All Transfers
      • Orders
        • Verify Order Placement
          • Syntax
        • Place Order
          • Syntax
        • Verify Order Replacement
          • Syntax
        • Replace Order
          • Syntax
        • Cancel an Order
          • Syntax
        • Get Order's Info
          • Syntax
        • Get Filtered Orders
          • Syntax
      • Positions
        • Get User's Positions
          • Syntax
        • Get User's Positions in a Security
          • Syntax
        • Get Market Value of all Security Groups
      • Securities
        • Get Equity Info by Internal ID
          • Syntax
        • Get Equity Info by Ticker
          • Syntax
        • Get Equity Info by Mask
          • Syntax
        • Get Filtered Equities
          • Syntax
        • Get Option Info by Internal ID
          • Syntax
        • Get Option Info by Ticker
          • Syntax
        • Get Options Expiration Dates
          • Syntax
        • Get an Option Chain
        • Get Filtered Options
          • Syntax
      • Watchlists
        • Add Security to Watchlist by ID
          • Syntax
        • Add Security to Watchlist by Ticker
          • Syntax
        • Create New Watchlist
          • Syntax
        • Delete Watchlist
          • Syntax
        • Get Specific Watchlist
          • Syntax
        • Get User's Watchlists
          • Syntax
        • Remove Security From Watchlist by ID
          • Syntax
        • Remove Security from Watchlist by Ticker
          • Syntax
        • Rename Watchlist
          • Syntax
      • Price Alerts
        • Create Price Alert
          • Syntax
        • Delete Price Alert
          • Syntax
        • Get Specific Alert
          • Syntax
        • Get User's Price Alerts
          • Syntax
        • Modify Price Alert
          • Syntax
      • Historical Data
        • Get Comparison Chart Data
          • Syntax
        • Get Candles and Indicators for a Security
          • Syntax
        • Get Chart Data in the Excel Format
          • Syntax
      • News
        • Get News for a Security
        • Get Corporate Actions for a Security
      • User Feedback
        • Submit Feedback
          • Syntax
      • Managing Transactions
        • Get Transactions
          • Syntax
      • Streaming Data
        • Quotes
        • Orders
        • Positions
        • Watchlists
        • Account Balances
      • Code Samples
        • Basic Authentication
        • Two-Factor Autentication
        • Placing New Orders
        • Get User Information
        • List User Positions
        • Get Trading Data for Charts
      • Terms and Definitions
        • Part I
        • Part II
        • Part III
Powered by GitBook
On this page
  • Single-Factor Authentication
  • CURL
  1. REST API
  2. Trading API
  3. Code Samples

Basic Authentication

PreviousCode SamplesNextTwo-Factor Autentication

Last updated 4 years ago

Single-Factor Authentication

Initial Authentication
import requests

class AutosharesAPIRequest:

    baseURL = "https://pub-api-et-demo-prod.etnasoft.us/api/"
    EtAppKey = "your EtAppKey from the BO Companies widget"

    token = 'uninitialized'

    username = "your username in Autoshares Trader"
    password = "your password in Autoshares Trader"

    def initialAuth(self):
        #Creating a POST request
        authenticationRequest = requests.post(self.baseURL + 'token', 
                                              headers = {"Accept" : "application/json", "Et-App-Key" : self.EtAppKey, "Username":self.username, "Password":self.password})

        print('Authorization status code: ' + str(authenticationRequest.status_code) + '\n')

        try:
            responseJSON = authenticationRequest.json()
            print(responseJSON)
            self.token = "Bearer " + responseJSON["Token"]
            return responseJSON
        except:
            return "No response"

#Performing initial Authentication
sampleRequest = AutosharesAPIRequest()
sampleRequest.initialAuth()

In this example, there's a class called AutosharesAPIRequest that has five properties:

  • baseURL — this is the URL that hosts your API. Each solution has its own base URL for both the Trader and the Developer API.

  • EtAppKey — this is the unique key of your solution that can be retrieved from the BO companies widget in Autoshares Trader.

  • Token — this is the authentication token that must be provided in all API requests except for the first one (authentication).

  • Username and password — these are the credentials of a user on whose behalf all API requests will be made.

The first method — initialAuth — creates a POST request to the base URL appended by token (each endpoint has its own unique address). As for headers, the authentication endpoint requires you to provide the following parameters:

  • "Accept" : "application/json"— use this parameter to accept the authorization token that will be returned in response to this request.

  • EtAppKey — use this parameter to identify your app in all requests.

  • Username and password — these are the credentials of the user on whose behalf all subsequent requests will be made.

In response to this request, you'll receive a JSON file that contains the token (provided that all the parameters were correctly specified):

{'State': 'Succeeded', 'Token': 'Fake/Cl++ZKkDecvgAAAAAOgAAAAAIAACAAAAB8WguNLQWKAUhh7QbSvsHZMGhO6xlNiSFPptfJRlnD0hABAADlr/R6NVs3V+nl2HJlzM8qOLy3MvGU313ecOIsR9GBF14QsRVohtUPRyoiNpdZ9BRql9EdGstABoDNlYF4TLNJeEyF8WEaKL+gEHP4OXmbQTnpD6swG7+2Y3MWe6atpglyzFsJiDoMRuHMMOLbM3h3zy4+E3wgewghduRvBzgRa9pmp7iuCSF9RixJAO+pW+VzNXdfalulcBMdbVBaomN08TATGvrLjsDRKbzMy3j02w1qPc2dE7xo4svIxwWfMj+wpPDUDg4Low4Solyfk3qdK0W9/gYBvGGCB/Ppg6GRJYuFZf5+KHpbb43k/M8QFaXzpmlEL4HTYfC6cjDRsngmOzAwTK0WqT/7NpE+o1X610AAAAC3eKWYjv0Il+s4H0hr+Tkqc6L3+2IcT97KcTCMP7/Xrb7Pa/ybDPoZ3ZVHiU7JBUFaS4MEaZ44u7Zrsu/gbOxG'}

You can then extract the returned token and assign it to the token property.

CURL

The following is a sample CURL for performing single-factor authentication:

curl -X POST "https://pub-api-et-demo-prod.etnasoft.us/api/token" \
    -H "Username: yourUsername" \
    -H "Password: yourPassword" \
    -H "Et-App-Key: yourEttAppKey" \
    -H "Content-Length: 0"
Authentication