-
Notifications
You must be signed in to change notification settings - Fork 25
Launching TradeIt screens
Almost all TradeIt functionality can be quickly and easily integrated just by launching the pre-built TradeIt screens from the SDK.
If the user has no previously linked brokers, launching any of the pre-built TradeIt screens will result in the user first being prompted to link a broker. Otherwise the broker linking UI flow can be manually launched like this:
TradeItSDK.launcher.launchBrokerLinking(fromViewController: self)
When the user has successfully authorized the linking, the SDK will deep link back into your app using the OAuth callback URL specified when you initialized the TradeItSDK
. Your app should intercept the deep link and pass the callback URL and the top most currently presented view controller to TradeItSDK.launcher.handleOAuthCallback
to complete the OAuth flow like this:
// In AppDelegate
func application(_ application: UIApplication,
open url: URL,
sourceApplication: String?,
annotation: Any) -> Bool {
// Make sure to verify the deep link URL is the one you specified for the TradeItSDK before proceeding with launching handleOAuthCallback
// Get the top view controller to pass to the launcher. The below example works in the general case, but your app may need to implement custom logic to get the top-most presented view controller.
if var topViewController = UIApplication.shared.keyWindow?.rootViewController {
while let presentedViewController = topViewController.presentedViewController {
topViewController = presentedViewController
}
if let navController = topViewController as? UINavigationController,
let navTopViewController = navController.topViewController {
topViewController = navTopViewController
}
TradeItSDK.launcher.handleOAuthCallback(onTopmostViewController: topViewController, oAuthCallbackUrl: url)
}
return true
}
By default the first valid account is preselected.
TradeItSDK.launcher.launchPortfolio(fromViewController: self)
let linkedBroker = TradeItSDK.linkedBrokerManager.linkedBrokers.first
let account = linkedBroker.accounts.first
TradeItSDK.launcher.launchPortfolio(fromViewController: self, forLinkedBrokerAccount: account)
TradeItSDK.launcher.launchTrading(fromViewController: self)
If a TradeItOrder
is passed when launching trading, the trading ticket screen inputs will be prepopulated from the provided order.
let order = TradeItOrder()
order.symbol = "SYMB"
order.quantity = 100
order.action = .buyToCover
order.expiration = .goodForDay
TradeItSDK.launcher.launchTrading(fromViewController: self, withOrder: order)
TradeItSDK.launcher.launchAccountManagement(fromViewController: self)
TradeItSDK.launcher.launchBrokerLinking(fromViewController: self, onLinked: { linkedBroker in
print("Newly linked broker: \(linkedBroker)")
}, onFlowAborted: {
print("User aborted linking")
})
To configure whether the Portfolio screen is accessible from the Trading flow use:
TradeItSDK.isPortfolioEnabled = false
In order to visually integrate the TradeIt screens in to your app, you can create a TradeItTheme
object.
The SDK includes a light and dark theme which you can modify as needed.
// Set light theme
TradeItSDK.theme = TradeItTheme.light()
// Set dark theme
TradeItSDK.theme = TradeItTheme.dark()
The TradeItTheme
object has the following properties to let you customise further.
let theme = TradeItTheme()
theme.textColor // standard text color
theme.warningTextColor // warning text color
theme.backgroundColor // background color used on most screens including trading and linking screens
theme.alternativeBackgroundColor // background color used on the portfolio screen
theme.tableHeaderBackgroundColor // table header background color
theme.tableHeaderTextColor // table header text color
theme.interactivePrimaryColor // standard background color for buttons
theme.interactiveSecondaryColor // standard text color for buttons
theme.warningPrimaryColor // warning background color for buttons
theme.warningSecondaryColor // warning text color for buttons
theme.inputFrameColor // color used to frame input elements like UITextField
TradeItSDK.theme = theme