OpenAPI for Excel

This page documents the functionality of all worksheet functions provided by the OpenAPI for Excel add-in.

Generic Functions

This category includes all functions that perform basic, low-level HTTP interactions with Saxo's OpenAPI.

OpenApiGet()

DescriptionGeneric function for sending a GET request to the OpenAPI.
UseWorksheet cells, VBA.
ArgumentsTypeDescriptionExample

Uri

String

Path to the OpenAPI endpoint including query string parameters.

"/openapi/ref/v1/instruments/details/?AssetTypes=FxSpot&Uics=21"
ParameterListStringList of comma-separated, case-sensitive field names to be returned from the response with full stops identifying nested fields under a specific FieldGroup.
"Description,Exchange.CountryCode,Format.OrderDecimals"

OpenApiPost()

DescriptionGeneric function for sending a POST request to the OpenAPI.
UseWorksheet cells, VBA.
ArgumentsTypeDescriptionExample

Uri

String

Path to the OpenAPI endpoint including query string parameters.

"/openapi/trade/v1/orders"

Body

String

JSON-structured string where double quotes are replaced by single quotes.

"{'AccountKey':'ABCDE12345',
'Amount':100000,
'AssetType':'FxSpot',
'BuySell':'Buy',
'OrderDuration':{'DurationType':'DayOrder'},
'OrderRelation':'Oco',
'OrderType':'Market',
'Uic':21}"

OpenApiPut()

DescriptionGeneric function for sending a PUT request to the OpenAPI.
UseWorksheet cells, VBA.
ArgumentsTypeDescriptionExample

Uri

String

Path to the OpenAPI endpoint including query string parameters.

"/openapi/trade/v1/positions/exercise"

Body

String

JSON-structured string where double quotes are replaced by single quotes.

"{'AccountKey':'ABCDE12345',
'Amount':100,
'AssetType':'StockOption',
'Uic':5455848}"

OpenApiPatch()

DescriptionGeneric function for sending a PATCH request to the OpenAPI.
UseWorksheet cells, VBA.
ArgumentsTypeDescriptionExample

Uri

String

Path to the OpenAPI endpoint including query string parameters.

"/openapi/trade/v1/orders/"

Body

String

JSON-structured string where double quotes are replaced by single quotes.

"{'AccountKey':'ABCDE12345',
'Amount':200.0,
'OrderDuration':{'DurationType':'GoodTillCancel'},
'OrderPrice':1264.0,
'OrderType':'Limit'}"

OpenApiDelete()

DescriptionGeneric function for sending a DELETE request to the OpenAPI.
UseWorksheet cells, VBA.
ArgumentsTypeDescriptionExample

Uri

String

Path to the OpenAPI endpoint including query string parameters.

"/openapi/trade/v1/orders/75646392/?AccountKey=ABCDE12345"

OpenApiGetAsync()

DescriptionGeneric function for sending an asynchronous GET request to the OpenAPI.
UseWorksheet cells only.
ArgumentsTypeDescriptionExample

Uri

String

Path to the OpenAPI endpoint including query string parameters.

"/openapi/ref/v1/instruments/details/?AssetTypes=FxSpot&Uics=21"

ParameterList

String

List of comma-separated, case-sensitive field names to be returned from the response with full stops identifying nested fields under a specific FieldGroup.

"Description,Exchange.CountryCode,Format.OrderDecimals"

OpenApiSubscribe()

DescriptionGeneric function for subscribing to the an OpenAPI endpoint.
UseWorksheet cells only.
ArgumentsTypeDescriptionExample

Uri

String

Path to the OpenAPI endpoint without query string parameters.

"/openapi/trade/v1/infoprices/subscriptions"

Arguments

String

List of comma-separated, case-sensitive field names to be returned from the response with full stops identifying nested fields under a specific FieldGroup.

"AssetType:FxSpot,Uics:21,22,23"

FieldGroups

String

List of comma-separated, case-sensitive FieldGroups to be retrieved from the OpenAPI.

"Quote"

ParameterList

String

List of comma-separated, case-sensitive field names to be returned from the response with full stops identifying nested fields under a specific FieldGroup.

"Description,Exchange.CountryCode,Format.OrderDecimals"

Utility Functions

This category includes all functions that service as shortcuts for standard API calls such as getting account keys and refreshing formulas.

OpenApiGetAccountKey()

DescriptionShortcut function to simply obtaining a account key for a given AccountId. Defaults to the user's primary account.
UseWorksheet cells, VBA.
ArgumentsTypeDescriptionExample

AccountId

String

Optional: AccountId for the requested account.

"101234_USD"

OpenApiGetAccountList()

DescriptionShortcut function to simply obtaining a list of accounts for a given ClientKey. Defaults to the ClientKey of the logged-in user.
UseWorksheet cells only.
ArgumentsTypeDescriptionExample

ClientKey

String

Optional: ClientKey for the requested client.

"X1JAJJAsjsdTMK3mBxzd-D2UA=="

OpenApiGetAutoResize()

DescriptionGET function that resizes the output array in a worksheet automatically depending on the returned size.
UseWorksheet cells only.
ArgumentsTypeDescriptionExample

Uri

String

Path to the OpenAPI endpoint including query string parameters.

"/openapi/ref/v1/instruments/details/?AssetTypes=FxSpot&Uics=21"
ParameterListStringList of comma-separated, case-sensitive field names to be returned from the response with full stops identifying nested fields under a specific FieldGroup.
"Description,Exchange.CountryCode,Format.OrderDecimals"
IncludeHeadersBoolIndicator to instruct the resize formula to include a header row containing the field names of the requested fields.
TRUE

OpenApiGetClientKey()

DescriptionShortcut function to simplify obtaining the ClientKey of the current logged-in user.
UseWorksheet cells, VBA.

OpenApiGetContextId()

DescriptionShortcut function to simplify obtaining the ConextId of the current session.
UseWorksheet cells, VBA.

OpenApiRefreshFormula()

DescriptionFunction that refreshes all OpenAPI and Excel formulas across every sheet in the workbook. Similar to how the Refresh button in the OpenAPI ribbon refreshes all cells.
UseWorksheet cells, VBA.

Trading Functions

This category of functions provides useful wrappers for trading functionality, which is simplified to emulate trade ticket input fields. These functions should not be used outside of VBA (other than for testing), as executing these functions will send requests to the OpenAPI immediately.

OpenApiPlaceOrder()

DescriptionWrapper function which sends a POST request to the OpenAPI containing the order information from the function's arguments.
UseWorksheet cells, VBA (recommended).
ArgumentsTypeDescriptionExample

Accountkey

String

Key of the account of the current logged in user against which the order is placed.

"ABCDE12345"
InstrumentStringSymbol of the instrument that is ordered.
"AAPL:xnas"
AssetTypeStringAssetType of the instrument that is ordered.
"Stock"
AmountIntegerAmount of the order.
200
Buy/SellStringOrder direction.
"Sell"
DurationStringDuration of the order.
"DayOrder"
OrderTypeStringType of the order.
"Market"
OrderPriceFloatPrice of the order.
145.02
RelatedLimitPriceFloatPrice of the related limit order.
155.94
RelatedStopPriceFloatPrice of the related stop order.
136.23
RelatedStopTypeStringType of the related stop order.
"StopLimit"

OpenApiCancelOrder()

DescriptionWrapper function which sends a DELETE request to the OpenAPI.
UseWorksheet cells, VBA (recommended).
ArgumentsTypeDescriptionExample

OrderId

Integer

Order number.

44689512
AccountkeyStringKey of the account of the current logged in user from which the order is deleted.
"ABCDE12345"

OpenApiEditOrder()

DescriptionWrapper function which sends a PATCH request to the OpenAPI to change details of an existing order.
UseWorksheet cells, VBA (recommended).
ArgumentsTypeDescriptionExample
AccountkeyStringKey of the account of the current logged in user which contains the order.
"ABCDE12345"
AmountIntegerAmount of the modified order.
250
DurationStringDuration of the modified order.
"GoodTillCancel"
OrderPriceFloatPrice of the modified order.
130.99
OrderTypeStringType of the modified order.
"Limit"
OrderIdIntegerOrder number of existing order.
44689512

OpenApiAddRelatedOrder()

DescriptionWrapper function which sends a POST request to the OpenAPI to add related order to an existing order.
UseWorksheet cells, VBA (recommended).
ArgumentsTypeDescriptionExample
AccountkeyStringKey of the account of the current logged in user which contains the order.
"ABCDE12345"
AmountIntegerAmount of the related order..
230
Buy/SellStringOrder direction of related order.
"Sell"
DurationStringDuration of the related order.
"GoodTillCancel"
OrderPriceFloatPrice of the related order.
161.42
OrderTypeStringType of the related order.
"Limit"
MainOrderIdIntegerOrder number of existing order.
8466177
OrderRelationStringRelationship between existing and related order.
"Oco"

OpenApiClosePosition()

DescriptionWrapper function which sends a POST request to the OpenAPI to close a position.
UseWorksheet cells, VBA (recommended).
ArgumentsTypeDescriptionExample

Accountkey

String

Key of the account of the current logged in user containing the position.

"ABCDE12345"
InstrumentStringSymbol of the position that is closed.
"AAPL:xnas"
AssetTypeStringAssetType of the position that is closed.
"Stock"
AmountIntegerAmount of the order.
200
Buy/SellStringOrder direction.
"Sell"
DurationStringDuration of the order.
"DayOrder"
OrderTypeStringType of the order.
"Market"
OrderPriceFloatPrice of the order.
145.02
RelatedPositionIdIntegerNumber of the related order that will be cancelled as this position is closed.
55144615

OpenApiPlaceOrderAsync()

DescriptionWrapper function which sends a POST request to the OpenAPI containing the order information from the function's arguments.
UseWorksheet cells (not recommended).
ArgumentsTypeDescriptionExample

Accountkey

String

Key of the account of the current logged in user against which the order is placed.

"ABCDE12345"
InstrumentStringSymbol of the instrument that is ordered.
"AAPL:xnas"
AssetTypeStringAssetType of the instrument that is ordered.
"Stock"
AmountIntegerAmount of the order.
200
Buy/SellStringOrder direction.
"Sell"
DurationStringDuration of the order.
"DayOrder"
OrderTypeStringType of the order.
"Market"
OrderPriceFloatPrice of the order.
145.02