-
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
See UIAppearance.