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
typeThe account type to be used or created (stocks or forex).
appIdThe ID of the app.
appKeyThe 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
appIdOAuth flow app ID.
uriOAuth flow redirect URL.
viewControllerOptional 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
appIdOAuth flow app ID.
uriOAuth flow redirect URL.
viewControllerOptional 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
urlThe 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
accessTokenThe 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
authRequestThe authentication request to be sent.
completionThe 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
demoAuthRequestThe demo authentication request to be sent.
completionThe 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
refreshAuthRequestThe refresh authentication request to be sent.
completionThe 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
trialRequestThe request for starting the subscription.
completionThe 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
subscriptionRequestThe request for starting the subscription.
completionThe 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
brokerIdThe id of the broker that the account is at.
userLoginThe login for the account.
completionThe 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
cancelSubscriptionRequestThe request for cancelling the subscription.
completionThe 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
accountThe account for which the two factor authentication response is required.
challengeThe two factor authentication challenge that has been received.
twoFactorAuthResponseThe response for the challenge.
completionThe 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
appIdThe ID of the app to retrieve information for.
completionThe 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
accessTokenThe access token to be used when calling the API.
completionThe 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
accessTokenThe access token to be used when calling the API.
completionThe 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
accountThe account for which the indicators info should be fetched.
completionThe closure to be called when the response comes back, with an optional list of TradableIndicatorInfo objects and an optional TradableError object.
View on GitHub
Tradable Class Reference