Tradable

@objc public class Tradable: NSObject

The Tradable object implementing the singleton pattern.

  • A method used to create and/or activate DEMO accounts. Tries to activate Tradable SDK with the last known tokens; if fails, falls back to creating a demo account. If the current tokens exist and are not expired, the SDK uses the current tokens for the session. Otherwise tries to restore previous session’s tokens and use them for the current session. If those tokens are expired, tries to refresh them and uses the refreshed tokens; if they don’t exist, the method creates a new demo account, with params specified by the user. This is the preferred method to use and should be the first call made to TradableAPI. This method handles token refreshing, if found tokens are refreshable.

    Declaration

    Swift

    public func activateOrCreateDemoAccount(ofType type: TradableDemoAccountType, forAppId appId: UInt64, withAppKey appKey: String)

    Parameters

    type

    The account type to be used or created (stocks or forex).

    appId

    The ID of the app.

    appKey

    The key of the app.

  • A method used to create and/or activate LIVE accounts. Tries to activate Tradable SDK with the last known tokens; if fails, falls back to authentication flow. If the current tokens exist and are not expired, the SDK uses the current tokens for the session. Otherwise tries to restore previous session’s tokens and use them for the current session. If those tokens are expired or don’t exist, the method invokes the authentication flow for Tradable, with params specified by the user. This is the preferred method to use and should be the first call made to TradableAPI. This method handles token refreshing, if found tokens are refreshable.

    Declaration

    Swift

    public func activateOrAuthenticateWith(appId: UInt64, uri: String, viewController: UIViewController? = nil)

    Parameters

    appId

    OAuth flow app ID.

    uri

    OAuth flow redirect URL.

    viewController

    Optional UIViewController conforming to SFSafariViewControllerDelegate component used to transition to SFSafariViewController with login website. If not specified, system browser will be opened.

  • Begins authentication flow for Tradable; if viewController is nil, opens a system browser in order to authorize. Doesn’t restore previous session’s tokens. Consider using activateOrAuthenticateWith(appId: UInt64, uri: String, viewController: UIViewController?) instead.

    Declaration

    Swift

    public func authenticateWith(appId: UInt64, uri: String, viewController: UIViewController? = nil)

    Parameters

    appId

    OAuth flow app ID.

    uri

    OAuth flow redirect URL.

    viewController

    Optional UIViewController conforming to SFSafariViewControllerDelegate component used to transition to SFSafariViewController with login website. If not specified, system browser will be opened.

  • Tells the API to activate with URL containing access token. Should be called when system browser opens the application using TradableAPI. When the access token is successfully created, tradableReady auth delegate method is called. Dismisses an SFSafariViewController with login website if such was presented.

    Declaration

    Swift

    public func activateAfterLaunch(withUrl url: URL)

    Parameters

    url

    The URL containing the information needed in order to create access token.

  • Tells the API to activate with an access token. When the activation is successful, tradableReady auth delegate method is called; if activation fails, tradableAuthenticationError auth delegate method is called.

    Declaration

    Swift

    public func activate(with accessToken: TradableAccessToken)

    Parameters

    accessToken

    The access token to activate the API with.

  • Provides a token granting access to the account(s) associated with the given login.

    Declaration

    Swift

    public func authenticate(with authRequest: TradableAPIAuthenticationRequest, completion: ((_ accessToken: TradableAccessToken?, _ error: TradableError?) -> Void)!)

    Parameters

    authRequest

    The authentication request to be sent.

    completion

    The closure to be called when the response comes back, with optional TradableAccessToken object and optional TradableError object.

  • Creates a demo account of the specified type and returns an authentication granting access to that account.

    Declaration

    Swift

    public func createDemoAccount(with demoAuthRequest: TradableDemoAPIAuthenticationRequest, completion: ((_ accessToken: TradableAccessToken?, _ error: TradableError?) -> Void)!)

    Parameters

    demoAuthRequest

    The demo authentication request to be sent.

    completion

    The closure to be called when the response comes back, with optional TradableAccessToken object and optional TradableError object.

  • Refreshes the authentication that was granted when the refresh token was issued.

    Declaration

    Swift

    public func refreshAuthentication(with refreshAuthRequest: TradableAPIRefreshAuthenticationRequest, completion: ((_ accessToken: TradableAccessToken?, _ error: TradableError?) -> Void)!)

    Parameters

    refreshAuthRequest

    The refresh authentication request to be sent.

    completion

    The closure to be called when the response comes back, with optional TradableAccessToken object and optional TradableError object.

  • Returns a list of active accounts.

    Declaration

    Swift

    public func getActiveAccounts() -> [TradableAccount]
  • Returns an account’s unique ID to token dictionary consisting of the last session’s access tokens, if such were stored; nil otherwise.

    Declaration

    Swift

    public func getLastSessionAccessTokens() -> [String: TradableAccessToken]?
  • Gets the app information.

    Declaration

    Swift

    public func getAppInfo(forAppId appId: UInt64, completion: ((_ app: TradableApp?, _ error: TradableError?) -> Void)!)

    Parameters

    appId

    The ID of the app to retrieve information for.

    completion

    The closure to be called when the response comes back, with optional TradableApp object and optional TradableError object.

  • Gets the current user.

    Declaration

    Swift

    public func getCurrentUser(with accessToken: TradableAccessToken, completion: ((_ user: TradableOSUser?, _ error: TradableError?) -> Void)!)

    Parameters

    accessToken

    The access token to be used when calling the API.

    completion

    The closure to be called when the response comes back, with optional TradableOSUser object and optional TradableError object.

  • Gets available accounts.

    Declaration

    Swift

    public func getAvailableAccounts(with accessToken: TradableAccessToken, completion: ((_ accountList: TradableAccountList?, _ error: TradableError?) -> Void)!)

    Parameters

    accessToken

    The access token to be used when calling the API.

    completion

    The closure to be called when the response comes back, with optional TradableAccountList object and optional TradableError object.

  • Gets the indicators information.

    Declaration

    Swift

    public func getIndicatorsInfo(for account: TradableAccount, completion: ((_ indicatorsInfo: [TradableIndicatorInfo]?, _ error: TradableError?) -> Void)!)

    Parameters

    account

    The account for which the indicators info should be fetched.

    completion

    The closure to be called when the response comes back, with optional list of TradableIndicatorInfo objects and optional TradableError object.