Register
Submit a solution
The challenge is finished.

Challenge Overview

In the previous challenge, we have built the prototype for the SaxoTraderGO iOS app. In this challenge we need to integration the app with REST API.

We'll provide more details about the root url for the API, please register to see details.

Screens

1. Dashboard
Data for dashboard comes from the other screens, check the sections below to see what endpoints you should use to get the data.

2. Account Summary
You should call the port/v1/clients/me endpoint to get account details, then you can use DefaultAccountId from the response for Account Number on the screen. In the response you also get fields like DefaultAccountKey which you need to use in some other api calls.

You should call the port/v1/balances/?AccountKey={DefaultAccountKey}&ClientKey={ClientKey} endpoint to get balances data, and then find the following data:
Cash Available: CashBalance
Account Value: TotalValue
Margin Value: MarginAvailableForTrading
Margin Utilization: MarginUtilizationPct

Asset Allocation will always have FxSpot with 100% for now and the others with a percentage of 0% (show very thin bars in the pie chart for them). The amount to be shown in the center is the TotalValue field from the balances api.

Account Value chart can use mock data as is for now.

3. Positions
To be able to test this you should do the following to create a list of positions first (use the Uics you have in your FxSpot watchlist, see section 4 below on how to get this).

POST trade/v1/orders
{
  "Uic": 16,
  "BuySell": "Buy",
  "AssetType": "FxSpot",
  "Amount": 100000,
  "OrderPrice": 7,
  "OrderType": "Market",
  "OrderRelation": "StandAlone",
  "OrderDuration": {
    "DurationType": "ImmediateOrCancel"
  },
  "AccountKey": "{DefaultAccountKey}"
}

You will get an order id from this call. Then you should change it to Limit order and then back to Market order:
PATCH trade/v1/orders/{orderId}
{
  "Amount": 100000,
  "OrderType": "Limit",
  "OrderDuration": {
    "DurationType": "GoodTillCancel"
  },
  "AccountKey": "{DefaultAccountKey}"
}
PATCH trade/v1/orders/{orderId}
{
  "Amount": 100000,
  "OrderType": "Market",
  "OrderDuration": {
    "DurationType": "ImmediateOrCancel"
  },
  "AccountKey": "{DefaultAccountKey}"
}


Repeat this for a few different Uics (you can find some Uics to use by using the watchlist endpoints described in section 4 below), now you should have data by calling the port/v1/netpositions/?AccountKey={DefaultAccountKey}&ClientKey={ClientKey}&FieldGroups=DisplayAndFormat,NetPositionBase,NetPositionView endpoint. Each element in the response looks like this:
    {
      "DisplayAndFormat": {
        "Currency": "DKK",
        "Decimals": 4,
        "Description": "Euro/Danish Krone",
        "Format": "AllowDecimalPips",
        "Symbol": "EURDKK"
      },
      "NetPositionBase": {
        "AccountId": "8496691",
        "Amount": 200000,
        "AssetType": "FxSpot",
        "CanBeClosed": true,
        "ClientId": "8496691",
        "NumberOfRelatedOrders": 0,
        "PositionsAccount": "8496691",
        "Uic": 16,
        "ValueDate": "2018-04-18T00:00:00.000000Z"
      },
      "NetPositionId": "EURDKK__FxSpot",
      "NetPositionView": {
        "AverageOpenPrice": 7.44714,
        "CalculationReliability": "Ok",
        "CurrentPrice": 7.44705,
        "CurrentPriceDelayMinutes": 0,
        "CurrentPriceType": "Bid",
        "Exposure": 200000,
        "ExposureCurrency": "EUR",
        "ExposureInBaseCurrency": 200000,
        "InstrumentPriceDayPercentChange": 0,
        "PositionCount": 2,
        "PositionsNotClosedCount": 2,
        "ProfitLossOnTrade": -18,
        "ProfitLossOnTradeInBaseCurrency": -2.42,
        "Status": "Open",
        "TradeCostsTotal": 0,
        "TradeCostsTotalInBaseCurrency": 0
      }
    }

Here's how we should map the fields to what we display on the screen:
First line: use the Symbol / Description field
Second line: for the price we use CurrentPrice, drop the text part
Third line: for change of value and change percentage we should make a call to trade/v1/prices/subscriptions (see section 4 below for details) and use NetChange and PercentChange fields respectively, for the last element we use "{Amount} {Status}"

Note: once you set up the subscription on prices, you should use the streaming api (see link in the forum) to get real time updates on prices and show them on this screen.

4. Watchlists
Call ref/v1/watchlists to get a list of watchlists, then use the id of the first watchlist in the response to make a call to ref/v1/watchlists/{WatchListId}, you'll get the data for the full list, note you'll also get the AssetType and Uics of items in the watchlist which you can use in upcoming api calls.



For each of the item in the list, call the following endpoint to get price details:
POST trade/v1/prices/subscriptions
{
  "Arguments": {
    "Uics": 18,
    "AssetType": "FxSpot",
    "RequireTradableQuote":false,
    "FieldGroups":["InstrumentPriceDetails","MarketDepth","PriceInfo","PriceInfoDetails","Quote", "DisplayAndFormat"]
  },
  "RefreshRate":500,
  "ContextId": "random_string",
  "ReferenceId": "random_string"
}

From the response we use Symbol for field 1 (and the title above field 4), use Description for field 4, use Bid for field 2 (which is also used above the chart for TODAY), use PercentChange for field 3 (NetChange and PercentChange are also used above the chart). For the 3 fields below the chart: use High for HIGH, Low for LOW, and Open for OPEN.

For charting data call chart/v1/charts/?AssetType=FxSpot&Horizon=1&Uic=18 and you'll get all the data (use OpenBid field) you need to render that chart. Optionally you can include the Count parameter to limit the number of records to return because the default is 1200 which might be too many for the chart.

Note: once you set up the subscription on prices, you should use the streaming api (see link in the forum) to get real time updates on prices and show them on this screen.

5. Settings
Remove / hide the Margins Value Graph and Account Value Graph options and lock to the other 3 for now, dashboard will always show the 3 sections for this version.

Technology

iOS / Swift
Xcode 9.x

Final Submission Guidelines

  1. Full code that covers the requirements
  2. A detailed readme in markdown format that describes how to configure, run and verify the app

ELIGIBLE EVENTS:

2018 Topcoder(R) Open

Review style

Final Review

Community Review Board

Approval

User Sign-Off

ID: 30064328