OpenAPI

The Portfolio endpoints have multiple options to retrieve client/account balances and navigate the owner, user, client and account hierarchy. Definitions of these entities can be found here.

Below are some examples of the most common operations.

Balances

To get a snapshot of the current cash balance, portfolio unrealized profit/loss and margin utilization on a given account or client, use the Balances endpoints. These endpoints also return relevant collateral and credit line balances and utilization values.

The calculation currency is determined by the requested entity. If an AccountKey is specified, the calculation will be in the account's currency.

A full description of each field is available in the Portfolio Balances section of Reference Documentation.

Example of Balances data in use 

Example: Get balances for a client

GET https://gateway.saxobank.com/sim/openapi/port/v1/balances/ClientKey=6LvV4vnUsU8782kJtBgnjQ==
 
HTTP/1.1 200 OK
{
  "CalculationReliability": "Ok",
  "CashBalance": 123456.18,
  "ClosedPositionsCount": 0,
  "CollateralCreditValue": {
    "Line": 98900.89,
    "UtilzationPct": 0
  },
  "CostToClosePositions": -15.02,
  "Currency": "USD",
  "CurrencyDecimals": 2,
  "MarginAvailableForTrading": 98915.91,
  "MarginCollateralNotAvailable": -136.28,
  "MarginExposureCoveragePct": 26.25,
  "MarginNetExposure": 394732,
  "MarginUsedByCurrentPositions": -4719.29,
  "MarginUtilizationPct": 4.55,
  "NetEquityForMargin": 103635.2,
  "NetPositionsCount": 3,
  "NonMarginPositionsValue": 605.2,
  "OpenPositionsCount": 5,
  "OptionPremiumsMarketValue": 0,
  "OrdersCount": 0,
  "OtherCollateral": 0,
  "TotalValue": 103771.48,
  "TransactionsNotBooked": 0,
  "UnrealizedMarginClosedProfitLoss": 0,
  "UnrealizedMarginOpenProfitLoss": -20274.88,
  "UnrealizedMarginProfitLoss": -20274.87832,
  "UnrealizedPositionsValue": -19684.69832
}

Alternatively you can use the /me to default to the current logged in user's client:

GET https://gateway.saxobank.com/sim/openapi/port/v1/balances/me

To get balance details for a given account, specify the ClientKey and AccountKey desired:

GET https://gateway.saxobank.com/sim/openapi/port/v1/balances?ClientKey=6LvV4vnUsU8782kJtBgnjQ==&AccountKey=1gm4hJD76DKVkt5XBSYyrw==

Example: Get balances for an underlying client (Partners only)

To get balance details for an underlying client or on a underlying client's account, specify the underlying client's ClientKey and AccountKey.

GET https://gateway.saxobank.com/sim/openapi/port/v1/balances?ClientKey={clientkey}&AccountKey={accountkey}

Margin Utilization breakdown

You can also get an overview of how each net position affects your current overall margin utilization, grouped by class of AssetType.

GET https://gateway.saxobank.com/sim/openapi/port/v1/balances/marginoverview?ClientKey={clientkey}&AccountKey={accountkey}

HTTP/1.1 200 OK
{
  "Groups": [
    {
      "Contributors": [
        {
          "AssetTypes": [
            "FxSpot"
          ],
          "InstrumentDescription": "EURUSD description",
          "InstrumentSpecifier": "EURUSD",
          "Margin": 1235.0,
          "Uic": 21
        }
      ],
      "GroupType": "FX",
      "TotalMargin": 1235.0
    }
  ]
}

This breakdown can also be requested in a streaming subscription including the MarginOverview field group. Please note the update frequency will be 30 seconds, regardless of the subscription's RefreshRate.

POST https://gateway.saxobank.com/sim/openapi/port/v1/balances/subscriptions
{
  "ClientKey": "...",
  "FieldGroups": ["MarginOverview"]
}

Accounts

Get a list of Accounts under a Client

You will need the client key, available from the /clients/me endpoint or from the clients list. Only relevant fields are returned, so some fields may be included or omitted depending on your settings.
A full description of each field is available in the Portfolio Accounts section of Reference Documentation.

GET https://gateway.saxobank.com/sim/openapi/port/v1/accounts?ClientKey={clientkey} 

 Example:

GET https://gateway.saxobank.com/sim/openapi/port/v1/accounts?ClientKey=6LvV4vnUsU8782kJtBgnjQ==
 
HTTP/1.1 200 OK
{
  "Data": 
  [
    {
      "AccountGroupKey": "6LvV4vnUsU8782kJtBgnjQ==",
      "AccountId": "AccountEUR",
      "AccountKey": "1gm4hJD76DKVkt5XBSYyrw==",
      "AccountType": "Normal",
      "Active": true,
      ...
    },
    {      
      "AccountGroupKey": "6LvV4vnUsU8782kJtBgnjQ==",
      "AccountId": "AccountUSD",
      "AccountKey": "2fe4hJD76HSVkt5XXSYwes==",
      "AccountType": "Normal",
      "Active": true,
      ...
    }
  ]
}

Get Details of a Specific Account

You will need the account key, available from the output of the account list. Only relevant fields are returned, so some fields may be included or omitted depending on your settings. A full description of each field is available in the Portfolio Accounts section of Reference Documentation.


GET https://gateway.saxobank.com/sim/openapi/port/v1/accounts/{accountkey} 

 Example:

GET https://gateway.saxobank.com/sim/openapi/port/v1/accounts/1gm4hJD76DKVkt5XBSYyrw==
 
HTTP/1.1 200 OK
{
  "AccountGroupKey": "6LvV4vnUsU8782kJtBgnjQ==",
  "AccountId": "TRIAL_6564075",
  "AccountKey": "1gm4hJD76DKVkt5XBSYyrw==",
  "AccountType": "Normal",
  "Active": true,
  "CfdBorrowingCostsActive": false,
  "ClientId": "6564075",
  "ClientKey": "6LvV4vnUsU8782kJtBgnjQ==",
  "Currency": "USD",
  "CurrencyDecimals": 2,
  "DirectMarketAccess": false,
  "IndividualMargining": false,
  "IsCurrencyConversionAtSettlementTime": false,
  "IsMarginTradingAllowed": true,
  "IsShareable": false,
  "IsTrialAccount": true,
  "LegalAssetTypes": [
    "FxSpot",
    "FxForwards",
    "FxVanillaOption",
    "FxOneTouchOption",
    "FxNoTouchOption",
    "ContractFutures",
    "Stock",
    "Bond",
    "FuturesOption",
    "StockIndexOption",
    "CfdOnStock",
    "CfdOnFutures",
    "CfdOnIndex",
    "StockIndex"
  ],
  "Sharing": [
    "NoSharing"
  ]
}

Reset Simulation Account

When paper trading on simulation, it may be beneficial to reset your account with a new cash balance. This will also remove all orders and positions associated with the account.

Example:

PUT https://gateway.saxobank.com/sim/openapi/port/v1/accounts/1gm4hJD76DKVkt5XBSYyrw==/reset
 
HTTP/1.1 204 NoContent
{   
	"NewBalance": 1000000.00 
}

Get a List of Underlying Accounts (Partners)

To get all accounts under a given owner simply specify the ClientKey of the owner and set IncludeSubAccounts=true.

GET https://gateway.saxobank.com/sim/openapi/port/v1/accounts/?ClientKey={ClientKey}&IncludeSubAccounts=true

Example:

GET https://gateway.saxobank.com/sim/openapi/port/v1/accounts?ClientKey=6LvV4vnUsU8782kJtBgnjQ==&IncludeSubAccounts=true 
 
HTTP/1.1 200 OK{
  "Data": [
    {
      "AccountGroupKey": "b3zXzsomkegikDnFQy8fVg==",
      "AccountId": "TEST_OA_PARTNER1",
      ...
    },
    {
      "AccountGroupKey": "KrksGZpKqo24D1nyXbzpTw==",
      "AccountId": "TEST_OA_SUBCLIEN",
      ...
    }
  ]
}

Clients

Get Details of a Specific Client

You will need the client key, available from the /clients/me endpoint or from the clients list. Only relevant fields are returned, so some fields may be included or omitted depending on your settings. A full description of each field is available in the Portfolio Client section of Reference Documentation.


GET https://gateway.saxobank.com/sim/openapi/port/v1/clients/{clientkey} 

If you just want details for the client belonging to the logged in user, you can use the /me endpoint.

GET https://gateway.saxobank.com/sim/openapi/port/v1/clients/me

 Example:

GET https://gateway.saxobank.com/sim/openapi/port/v1/accounts/1gm4hJD76DKVkt5XBSYyrw==
 
HTTP/1.1 200 OK
{
  "AccountGroupKey": "6LvV4vnUsU8782kJtBgnjQ==",
  "AccountId": "TRIAL_6564075",
  "AccountKey": "1gm4hJD76DKVkt5XBSYyrw==",
  "AccountType": "Normal",
  "Active": true,
  "CfdBorrowingCostsActive": false,
  "ClientId": "6564075",
  "ClientKey": "6LvV4vnUsU8782kJtBgnjQ==",
  "Currency": "USD",
  "CurrencyDecimals": 2,
  "DirectMarketAccess": false,
  "IndividualMargining": false,
  "IsCurrencyConversionAtSettlementTime": false,
  "IsMarginTradingAllowed": true,
  "IsShareable": false,
  "IsTrialAccount": true,
  "LegalAssetTypes": [
    "FxSpot",
    "FxForwards",
    "FxVanillaOption",
    "FxOneTouchOption",
    "FxNoTouchOption",
    "ContractFutures",
    "Stock",
    "Bond",
    "FuturesOption",
    "StockIndexOption",
    "CfdOnStock",
    "CfdOnFutures",
    "CfdOnIndex",
    "StockIndex"
  ],
  "Sharing": [
    "NoSharing"
  ]
}

Switch a Client's Position Netting Mode

For some clients two netting modes are available,  End of day and Intraday. Click here for a full description. This endpoint allows qualified clients to switch the netting mode.

Example:

PATCH https://gateway.saxobank.com/sim/openapi/port/v1/clients/me
 
HTTP/1.1 204 OK
{
   "NewPositionNettingMode": "Intraday" 
}

All orders related to positions must be removed before real-time netting can be enabled.

Get a list of Underlying Clients (Partners)

To get all clients under a given owner simply specify the OwnerKey. An OwnerKey is simply the ClientKey of the partner with underlying clients.

GET https://gateway.saxobank.com/sim/openapi/port/v1/clients/?OwnerKey={OwnerKey}

Example:

GET https://gateway.saxobank.com/sim/openapi/port/v1/clients?OwnerKey=6LvV4vnUsU8782kJtBgnjQ==
 
HTTP/1.1 200 OK
{
  "Data": [
    {
      "ClientId": "2147308358",
      "ClientKey": "b3zXzsomkegikDnFQy8fVg==",
      "CurrencyDecimals": 2,
      "DefaultAccountId": "TEST_OA_PARTNER1",
      "DefaultCurrency": "EUR",
      "IsMarginTradingAllowed": true,
      "IsVariationMarginEligible": false,
      "LegalAssetTypes": [        ...      ],
      "Name": "OpenApi AutoTest Partner",
      "PositionNettingMode": "Intraday"
    },
    {
      "ClientId": "2147308359",
      "ClientKey": "KrksGZpKqo24D1nyXbzpTw==",
      "CurrencyDecimals": 2,
      "DefaultAccountId": "TEST_OA_SUBCLIEN",
      "DefaultCurrency": "USD",
      "IsMarginTradingAllowed": true,
      "IsVariationMarginEligible": false,
      "LegalAssetTypes": [ ... ],
      "Name": "OpenApi Auto Test SubClient",
      "PositionNettingMode": "Intraday"
    }
  ]
}


Users

Get Details of a Specific user

You will need the user key, available from the /users/me endpoint or from the users list. In many instances there will exist a UserKey that is the same as the ClientKey. Only relevant fields are returned, so some fields may be included or omitted depending on your settings. A full description of each field is available in the Portfolio Users section of Reference Documentation.


GET https://gateway.saxobank.com/sim/openapi/port/v1/users/{userkey} 

If you just want details for the logged in user, you can use the /me endpoint.

GET https://gateway.saxobank.com/sim/openapi/port/v1/users/me

 Example:

GET https://gateway.saxobank.com/sim/openapi/port/v1/users/6LvV4vnUsU8782kJtBgnjQ==
 
HTTP/1.1 200 OK
{
  "ClientKey": "6LvV4vnUsU8782kJtBgnjQ==",
  "Culture": "en-GB",
  "Language": "en",
  "LastLoginStatus": "Successful",
  "LastLoginTime": "2017-02-23T14:16:43.197000Z",
  "LegalAssetTypes": [
    "FxSpot",
    "FxForwards",
    "FxVanillaOption",
    "FxKnockInOption",
    "FxKnockOutOption",
    "FxOneTouchOption",
    "FxNoTouchOption",
    "ContractFutures",
    "Stock",
    "Bond",
    "FuturesOption",
    "StockIndexOption",
    "StockOption",
    "CfdOnStock",
    "CfdOnIndex",
    "CfdOnFutures",
    "StockIndex"
  ],
  "Name": "Nick Wilder",
  "TimeZoneId": 27,
  "UserId": "6564075",
  "UserKey": "6LvV4vnUsU8782kJtBgnjQ=="
}