Tradable
@objc public class Tradable: NSObject
The Tradable object implementing the singleton pattern.
-
Tradable events delegate for hooking into updates responses.
Declaration
Swift
@objc public weak var eventsDelegate: TradableEventsDelegate?
-
Tradable authentication delegate for hooking into auth responses.
Declaration
Swift
@objc public weak var authDelegate: TradableAuthDelegate?
-
Tradable search delegate for hooking into search results.
Declaration
Swift
@objc public weak var searchDelegate: TradableSearchDelegate?
-
A singleton object used to invoke API methods on.
Declaration
Swift
@objc public static let sharedInstance: Tradable = Tradable()
-
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
@objc 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
@objc 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
@objc public func authenticate(withAppId appId: UInt64, uri: String, viewController: UIViewController? = nil, showLogin: Bool = false)
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
@objc 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
@objc 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
@objc 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 an optional TradableAccessToken object and an optional TradableError object.
-
Creates a demo account of the specified type and returns an authentication granting access to that account.
Declaration
Swift
@objc 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 an optional TradableAccessToken object and an optional TradableError object.
-
Refreshes the authentication that was granted when the refresh token was issued.
Declaration
Swift
@objc 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 an optional TradableAccessToken object and an optional TradableError object.
-
Returns a list of active accounts.
Declaration
Swift
@objc 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
@objc public func getLastSessionAccessTokens() -> [String: TradableAccessToken]?
-
Requests starting a trial period in order to get access to trading with the given broker.
Declaration
Swift
@objc public func startTrial(with trialRequest: TradableStartTrialRequest, completion: ((_ subscriptionResponse: TradableSubscriptionResponse?, _ error: TradableError?) -> Void)!)
Parameters
trialRequest
The request for starting the subscription.
completion
The closure to be called when the response comes back, with an optional TradableSubscriptionResponse object and an optional TradableError object.
-
Subscribes in order to get access to trading with the given broker.
Declaration
Swift
@objc public func subscribe(with subscriptionRequest: TradableSubscriptionRequest, completion: ((_ subscriptionResponse: TradableSubscriptionResponse?, _ error: TradableError?) -> Void)!)
Parameters
subscriptionRequest
The request for starting the subscription.
completion
The closure to be called when the response comes back, with an optional TradableSubscriptionResponse object and an optional TradableError object.
-
Retrieves information on a subscription.
Declaration
Swift
@objc public func getSubscriptionInfo(forBrokerId brokerId: Int, andUserLogin userLogin: String, completion: ((_ subscriptionResponse: TradableSubscriptionResponse?, _ error: TradableError?) -> Void)!)
Parameters
brokerId
The id of the broker that the account is at.
userLogin
The login for the account.
completion
The closure to be called when the response comes back, with an optional TradableSubscriptionResponse object and an optional TradableError object.
-
Cancels the subscription for the given user.
Declaration
Swift
@objc public func cancelSubscription(with cancelSubscriptionRequest: TradableCancelSubscriptionRequest, completion: ((_ subscriptionResponse: TradableSubscriptionResponse?, _ error: TradableError?) -> Void)!)
Parameters
cancelSubscriptionRequest
The request for cancelling the subscription.
completion
The closure to be called when the response comes back, with an optional TradableSubscriptionResponse object and an optional TradableError object.
-
Used to complete two factor authentication.
Declaration
Swift
@objc public func continueTwoFactorAuth(for account: TradableAccount, for challenge: TradableTwoFactorAuthenticationChallenge, with twoFactorAuthResponse: TradableTwoFactorAuthenticationResponse, completion: ((_ accessToken: TradableAccessToken?, _ error: TradableError?) -> Void)!)
Parameters
account
The account for which the two factor authentication response is required.
challenge
The two factor authentication challenge that has been received.
twoFactorAuthResponse
The response for the challenge.
completion
The closure to be called when the response comes back, with an optional TradableAccessToken object and an optional TradableError object.
-
Gets the app information.
Declaration
Swift
@objc 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 an optional TradableApp object and an optional TradableError object.
-
Gets the current user.
Declaration
Swift
@objc 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 an optional TradableOSUser object and an optional TradableError object.
-
Gets available accounts.
Declaration
Swift
@objc 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 an optional TradableAccountList object and an optional TradableError object.
-
Gets the indicators information.
Declaration
Swift
@objc 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 an optional list of TradableIndicatorInfo objects and an optional TradableError object.