### Instantiate and send a Get request Source: https://saxo-openapi.readthedocs.io/en/latest/endpoints/rootservices/diagnostics/Get.html Shows how to create a Get request object and send it using the API client. The example imports the necessary modules, creates an API client with an access token, instantiates the Get request, sends it, and asserts the response status code matches the expected status. ```python >>> import saxo_openapi >>> import saxo_openapi.endpoints.rootservices as rs >>> import json >>> client = saxo_openapi.API(access_token=...) >>> r = rs.diagnostics.Get() >>> rv = client.request(r) >>> assert r.status_code == r.expected_status ``` -------------------------------- ### UpdatePosition request setup and execution Source: https://saxo-openapi.readthedocs.io/en/latest/endpoints/trading/positions/UpdatePosition.html Shows how to import the library, create a client, define the data payload with AccountKey and ExerciseMethod, and execute the UpdatePosition request. The example includes the response with a PositionId. ```python >>> import saxo_openapi >>> import saxo_openapi.endpoints.trading as tr >>> import json >>> client = saxo_openapi.API(access_token=...) >>> data = { "AccountKey": "LZTc7DdejXODf-WSl2aCyQ==", "ExerciseMethod": "Spot" } ``` ```python >>> PositionId = 1019942425 >>> r = tr.positions.UpdatePosition(PositionId, data=data) >>> rv = client.request(r) >>> print(json.dumps(rv, indent=2)) ``` ```json { "PositionId": "1019942426" } ``` -------------------------------- ### PrecheckOrder usage example Source: https://saxo-openapi.readthedocs.io/en/latest/endpoints/trading/orders/PrecheckOrder.html Python example showing how to instantiate the PrecheckOrder endpoint, send the request, and print the response. ```python >>> import saxo_openapi >>> import saxo_openapi.endpoints.trading as tr >>> import json >>> client = saxo_openapi.API(access_token=...) >>> data = ... >>> r = tr.orders.PrecheckOrder(data=data) >>> client.request(r) >>> print(json.dumps(r.response, indent=4)) ``` -------------------------------- ### Import and setup for PriceSubscriptionRemoveByTag Source: https://saxo-openapi.readthedocs.io/en/latest/endpoints/trading/prices/PriceSubscriptionRemoveByTag.html Imports the required modules and initializes the API client with an access token. The params dictionary is left empty in this example. ```python >>> import saxo_openapi >>> import saxo_openapi.endpoints.trading as tr >>> import json >>> client = saxo_openapi.API(access_token=...) >>> params = {} ``` -------------------------------- ### Import and setup for ChartDataRemoveSubscriptions Source: https://saxo-openapi.readthedocs.io/en/latest/endpoints/chart/charts/ChartDataRemoveSubscriptions.html Imports the required modules and creates an API client. The params dictionary is left empty in this example. ```python >>> import saxo_openapi >>> import saxo_openapi.endpoints.chart as ch >>> import json >>> client = saxo_openapi.API(access_token=...) >>> params = {} ``` -------------------------------- ### CurrencyExposureMe usage example Source: https://saxo-openapi.readthedocs.io/en/latest/endpoints/portfolio/exposure/CurrencyExposureMe.html Shows how to instantiate the CurrencyExposureMe request, send it with the client, and print the response. The expected status is 200 and the method is GET. ```python >>> import saxo_openapi >>> import saxo_openapi.endpoints.portfolio as pf >>> import json >>> client = saxo_openapi.API(access_token=...) >>> r = pf.exposure.CurrencyExposureMe() >>> client.request(r) >>> print(json.dumps(r.response, indent=2)) ``` ```json [ { "Amount": 1057573.99, "Currency": "EUR" }, { "Amount": -67842.6, "Currency": "USD" }, { "Amount": -50000, "Currency": "GBP" }, { "Amount": 434195, "Currency": "DKK" } ] ``` -------------------------------- ### PrecheckOrder output example Source: https://saxo-openapi.readthedocs.io/en/latest/endpoints/trading/orders/PrecheckOrder.html Example response output from the PrecheckOrder request, showing estimated cash required and precheck result. ```json { "EstimatedCashRequired": 296.275, "EstimatedCashRequiredCurrency": "EUR", "InstrumentToAccountConversionRate": 0.88239, "PreCheckResult": "Ok" } ``` -------------------------------- ### CreatePriceSubscription: Example response Source: https://saxo-openapi.readthedocs.io/en/latest/endpoints/trading/prices/CreatePriceSubscription.html Example JSON response from a successful price subscription creation, showing the subscription state, snapshot, and quote details. ```json { "ContextId": "explorer_1552305379377", "Format": "application/json", "InactivityTimeout": 30, "ReferenceId": "N_935", "RefreshRate": 1000, "Snapshot": { "AssetType": "FxSpot", "LastUpdated": "2019-03-11T21:14:00.578000Z", "PriceSource": "SBFX", "Quote": { "Amount": 100000, "Ask": 1.35827, "Bid": 1.35754, "DelayedByMinutes": 0, "ErrorCode": "None", "Mid": 1.357905, "PriceTypeAsk": "Tradable", "PriceTypeBid": "Tradable", "RFQState": "None" }, "Uic": 45 }, "State": "Active" } ``` -------------------------------- ### Instantiate InfoPrices request with parameters Source: https://saxo-openapi.readthedocs.io/en/latest/endpoints/trading/infoprices/InfoPrices.html Shows how to import the library, create an API client, and define the parameters dictionary for the InfoPrices request. The parameters include Uics and AccountKey, with a placeholder for other parameters. ```python >>> import saxo_openapi >>> import saxo_openapi.endpoints.trading as tr >>> import json >>> client = saxo_openapi.API(access_token=...) >>> params = { "Uics": "22,23", "AccountKey": "1a463418-88d4-4555-92e3-e6004d675245", "": "..." } ``` -------------------------------- ### Import and instantiate client with params Source: https://saxo-openapi.readthedocs.io/en/latest/endpoints/valueadd/pricealerts/GetAllAlerts.html Shows the required imports and client setup, then defines the query parameters for the GetAllAlerts request, including $top, $skip, $inlinecount, and State. ```python >>> import saxo_openapi >>> import saxo_openapi.endpoints.valueadd as va >>> import json >>> client = saxo_openapi.API(access_token=...) >>> params = { "$top": 12015, "$skip": 27782, "$inlinecount": "None", "State": "Enabled" } ``` -------------------------------- ### Instantiate InfoPrice request with parameters Source: https://saxo-openapi.readthedocs.io/en/latest/endpoints/trading/infoprices/InfoPrice.html Shows how to import the library and create an InfoPrice request with a params dictionary containing Uic, AccountKey, AssetType, and other parameters. ```python >>> import saxo_openapi >>> import saxo_openapi.endpoints.trading as tr >>> import json >>> client = saxo_openapi.API(access_token=...) >>> params = { "Uic": 22, "AccountKey": "81ef1924-c25f-43fe-90ff-028e3fe249f2", "AssetType": "...", "": "..." } ``` -------------------------------- ### Create a subscription with SubscriptionCreate and print response Source: https://saxo-openapi.readthedocs.io/en/latest/endpoints/portfolio/accounts/SubscriptionCreate.html Shows the full workflow for creating a subscription: import the required modules, construct the request body with the required Arguments, ContextId, and ReferenceId, then instantiate SubscriptionCreate, send the request, and print the response. The output shows the expected 201 response with a snapshot of account data and subscription settings such as InactivityTimeout and RefreshRate. ```python >>> import saxo_openapi >>> import saxo_openapi.endpoints.portfolio as pf >>> import json >>> client = saxo_openapi.API(access_token=...) >>> data = { "Arguments": { "ClientKey": "Cf4xZWiYL6W1nMKpygBLLA==" }, "ContextId": "explorer_1551455553043", "ReferenceId": "I_213" } ``` ```python >>> r = pf.accounts.SubscriptionCreate(data=data) >>> client.request(r) >>> print(json.dumps(r.response, indent=2)) ``` ```json { "ContextId": "explorer_1551455553043", "Format": "application/json", "InactivityTimeout": 30, "ReferenceId": "I_213", "RefreshRate": 5000, "Snapshot": { "Data": [ { "AccountGroupKey": "Cf4xZWiYL6W1nMKpygBLLA==", "AccountId": "9226397", "AccountKey": "Cf4xZWiYL6W1nMKpygBLLA==", "AccountType": "Normal", "Active": true, "CanUseCashPositionsAsMarginCollateral": true, "ClientId": "9226397", "ClientKey": "Cf4xZWiYL6W1nMKpygBLLA==", "CreationDate": "2019-02-02T10:47:42.313000Z", "Currency": "EUR", "CurrencyDecimals": 2, "DirectMarketAccess": false, "DisplayName": "bram", "IndividualMargining": false, "IsCurrencyConversionAtSettlementTime": true, "IsMarginTradingAllowed": true, "IsShareable": false, "IsTrialAccount": true, "LegalAssetTypes": [ "FxSpot", "FxForwards", "FxVanillaOption", "FxKnockInOption", "FxKnockOutOption", "FxOneTouchOption", "FxNoTouchOption" ], "Sharing": [ "NoSharing" ], "SupportsAccountValueProtectionLimit": false, "UseCashPositionsAsMarginCollateral": true } ] }, "State": "Active" } ``` -------------------------------- ### GET openapi/port/v1/orders/ Source: https://saxo-openapi.readthedocs.io/en/latest/endpoints/portfolio/orders/GetAllOpenOrders.html This code snippet documents the GetAllOpenOrders endpoint, which retrieves all open orders for a given client. It includes the endpoint path, method, parameters, and a response example. ```APIDOC ## [GET] openapi/port/v1/orders/ ### Description Retrieves all open orders on an account or a client. ### Method GET ### Endpoint openapi/port/v1/orders/ ### Parameters #### Query Parameters - **ClientKey** (string) - Required - The client key to retrieve open orders for. ### Request Example ```python >>> import saxo_openapi >>> import saxo_openapi.endpoints.portfolio as pf >>> import json >>> client = saxo_openapi.API(access_token=...) >>> params = { ... "ClientKey": "Cf4xZWiYL6W1nMKpygBLLA==" ... } >>> r = pf.orders.GetAllOpenOrders(params=params) >>> client.request(r) >>> print(json.dumps(r.response, indent=2)) ``` ### Response #### Success Response (200) - **__count** (integer) - The number of open orders returned. - **Data** (array) - List of open orders. - **AccountId** (string) - The account ID. - **AccountKey** (string) - The account key. - **Amount** (number) - The order amount. - **AssetType** (string) - The asset type. - **BuySell** (string) - Buy or Sell. - **CalculationReliability** (string) - Reliability of the calculation. - **ClientKey** (string) - The client key. - **CorrelationKey** (string) - Correlation key. - **CurrentPrice** (number) - Current price. - **CurrentPriceDelayMinutes** (integer) - Delay in minutes for current price. - **CurrentPriceType** (string) - Type of current price. - **DistanceToMarket** (number) - Distance to market. - **Duration** (object) - Duration details. - **DurationType** (string) - Duration type. - **IsMarketOpen** (boolean) - Whether the market is open. - **MarketPrice** (number) - Market price. - **OpenOrderType** (string) - Type of open order. - **OrderAmountType** (string) - Order amount type. - **OrderId** (string) - Order ID. - **OrderRelation** (string) - Order relation. - **OrderTime** (string) - Order time. - **Price** (number) - Order price. - **RelatedOpenOrders** (array) - Related open orders. - **Status** (string) - Order status. - **Uic** (integer) - Uic. #### Response Example ```json { "__count": 3, "Data": [ { "AccountId": "9226397", "AccountKey": "Cf4xZWiYL6W1nMKpygBLLA==", "Amount": 100000, "AssetType": "FxSpot", "BuySell": "Buy", "CalculationReliability": "Ok", "ClientKey": "Cf4xZWiYL6W1nMKpygBLLA==", "CorrelationKey": "925ab7aa-998b-4f4b-af26-7c1b3f4eee27", "CurrentPrice": 7.46175, "CurrentPriceDelayMinutes": 0, "CurrentPriceType": "Ask", "DistanceToMarket": 0.46175, "Duration": { "DurationType": "GoodTillCancel" }, "IsMarketOpen": false, "MarketPrice": 7.46175, "OpenOrderType": "Limit", "OrderAmountType": "Quantity", "OrderId": "76332324", "OrderRelation": "StandAlone", "OrderTime": "2019-03-07T14:54:17.423333Z", "Price": 7, "RelatedOpenOrders": [], "Status": "Working", "Uic": 16 } ] } ``` ``` -------------------------------- ### GET openapi/port/v1/netpositions/{NetPositionId}/details Source: https://saxo-openapi.readthedocs.io/en/latest/endpoints/portfolio/netpositions/SingleNetPositionDetails.html This snippet documents the SingleNetPositionDetails endpoint, which retrieves details for a single net position. It includes the endpoint path, required parameters, and an example request and response. ```APIDOC ## [GET] openapi/port/v1/netpositions/{NetPositionId}/details ### Description Get a single net position details. ### Method GET ### Endpoint openapi/port/v1/netpositions/{NetPositionId}/details ### Parameters #### Path Parameters - **NetPositionId** (string) - Required - The NetPositionId #### Query Parameters - **params** (dict) - Required - dict representing the querystring parameters ### Request Example ``` >>> import saxo_openapi >>> import saxo_openapi.endpoints.portfolio as pf >>> import json >>> client = saxo_openapi.API(access_token=...) >>> params = { "ClientKey": "Cf4xZWiYL6W1nMKpygBLLA==" } >>> NetPositionId = "GBPCAD__FxSpot" >>> r = pf.positions.SingleNetPositionDetails( ... NetPositionId=NetPositionId, ... params=params) >>> client.request(r) >>> print(json.dumps(r.response, indent=4)) ``` ### Response #### Success Response (200) - **NetPositionBase** (object) - Contains base net position details. - **NetPositionDetails** (object) - Contains detailed net position information. - **NetPositionId** (string) - The net position identifier. - **NetPositionView** (object) - Contains view-specific net position data. #### Response Example ``` { "NetPositionBase": { "AccountId": "9226397", "Amount": 100000, "AssetType": "FxSpot", "CanBeClosed": true, "ClientId": "9226397", "IsMarketOpen": true, "NumberOfRelatedOrders": 0, "PositionsAccount": "9226397", "SinglePositionId": "212550210", "SinglePositionStatus": "Open", "Uic": 23, "ValueDate": "2019-03-06T00:00:00.000000Z" }, "NetPositionDetails": { "CloseCost": { "Commission": 8.77 }, "CloseCostInBaseCurrency": { "Commission": 5.81 }, "MarketValue": -478, "MarketValueInBaseCurrency": -316.77, "OpenCost": { "Commission": 8.79 }, "OpenCostInBaseCurrency": { "Commission": 5.83 } }, "NetPositionId": "GBPCAD__FxSpot", "NetPositionView": { "AverageOpenPrice": 1.75824, "CalculationReliability": "Ok", "CurrentPrice": 1.75346, "CurrentPriceDelayMinutes": 0, "CurrentPriceType": "Bid", "Exposure": 100000, "ExposureCurrency": "GBP", "ExposureInBaseCurrency": 116228, "InstrumentPriceDayPercentChange": -0.15, "PositionCount": 1, "PositionsNotClosedCount": 1, "ProfitLossOnTrade": -478, "ProfitLossOnTradeInBaseCurrency": -316.77, "Status": "Open", "TradeCostsTotal": -17.56, "TradeCostsTotalInBaseCurrency": -11.64 } } ``` ``` -------------------------------- ### GetAllocationKeys request setup Source: https://saxo-openapi.readthedocs.io/en/latest/endpoints/trading/allocationkeys/GetAllocationKeys.html Imports the required modules, creates an API client, and defines the query parameters for the GetAllocationKeys request. The parameters include $top, $skip, AccountKey, ClientKey, and Statuses. ```python >>> import saxo_openapi >>> import saxo_openapi.endpoints.trading as tr >>> import json >>> client = saxo_openapi.API(access_token=...) >>> params = { "$top": 601, "$skip": 22968, "AccountKey": "...", "ClientKey": "...", "Statuses": "Active,OneTime" } ``` -------------------------------- ### GET openapi/ref/v1/instruments/tradingschedule/{Uic}/{AssetType} Source: https://saxo-openapi.readthedocs.io/en/latest/endpoints/referencedata/instruments/TradingSchedule.html This snippet documents the TradingSchedule endpoint, which retrieves trading schedule data for a given instrument. It includes the endpoint path, required path parameters, and a usage example. ```APIDOC ## [GET] openapi/ref/v1/instruments/tradingschedule/{Uic}/{AssetType} ### Description Get TradingSchedule data for a specific instrument identified by its Uic and AssetType. ### Method GET ### Endpoint openapi/ref/v1/instruments/tradingschedule/{Uic}/{AssetType} ### Parameters #### Path Parameters - **Uic** (string) - Required - The Uic of the instrument - **AssetType** (string) - Required - The AssetType of the instrument ### Request Example ``` >>> import json >>> import saxo_openapi >>> import saxo_openapi.endpoints.referencedata as rd >>> client = saxo_openapi.API(access_token=...) >>> Uic = 21 >>> AssetType = "FxSpot" >>> r = rd.instruments.TradingSchedule( ... Uic=Uic, ... AssetType=AssetType) >>> client.request(r) >>> print(json.dumps(r.response, indent=4)) ``` ### Response #### Success Response (200) - **response** - The response of the request. #### Response Example ``` {_v3_TradingSchedule_resp} ``` ``` -------------------------------- ### ExerciseAmount request and response example Source: https://saxo-openapi.readthedocs.io/en/latest/endpoints/trading/positions/ExerciseAmount.html Shows how to instantiate the ExerciseAmount request, send it with the client, and print the response. ```python >>> r = tr.positions.ExerciseAmount(data=data) >>> rv = client.request(r) >>> print(json.dumps(rv, indent=2)) ``` ```json { "PositionId": "1019942426" } ``` -------------------------------- ### Import and setup AccountPerformance request Source: https://saxo-openapi.readthedocs.io/en/latest/endpoints/accounthistory/performance/AccountPerformance.html Imports required modules, creates an API client, and defines the ClientKey and query parameters (FromDate, ToDate) for the performance request. ```python >>> import saxo_openapi >>> import saxo_openapi.endpoints.accounthistory as ah >>> import json >>> client = saxo_openapi.API(access_token=...) >>> ClientKey = 'Cf4xZWiYL6W1nMKpygBLLA==' >>> params = { "FromDate": "2019-03-01", "ToDate": "2019-03-10" } ``` -------------------------------- ### Get (class in saxo_openapi.endpoints.rootservices.diagnostics) Source: https://saxo-openapi.readthedocs.io/en/latest/genindex.html Class representing the Get endpoint in the rootservices diagnostics service. Used to perform a GET request for diagnostics. ```APIDOC ## Get ### Description Class representing the Get endpoint in the rootservices diagnostics service. Used to perform a GET request for diagnostics. ### Method GET ### Endpoint /rootservices/diagnostics ``` -------------------------------- ### Import and setup client for AccountGroupDetails Source: https://saxo-openapi.readthedocs.io/en/latest/endpoints/portfolio/accountgroups/AccountGroupDetails.html Imports the saxo_openapi library and portfolio endpoints, creates an API client with an access token, and defines the required query parameters including ClientKey. ```python >>> import saxo_openapi >>> import saxo_openapi.endpoints.portfolio as pf >>> import json >>> client = saxo_openapi.API(access_token=...) >>> params = { "ClientKey": "Cf4xZWiYL6W1nMKpygBLLA==" } ``` -------------------------------- ### PositionByQuote response example Source: https://saxo-openapi.readthedocs.io/en/latest/endpoints/trading/positions/PositionByQuote.html Example response from the PositionByQuote request, containing the new PositionId. ```json { "PositionId": "1019942426" } ``` -------------------------------- ### MarginOverview request setup and execution Source: https://saxo-openapi.readthedocs.io/en/latest/endpoints/portfolio/balances/MarginOverview.html Shows how to instantiate a MarginOverview request with a ClientKey parameter and then execute it via the client, printing the JSON response. ```python >>> import saxo_openapi >>> import saxo_openapi.endpoints.portfolio as pf >>> import json >>> client = saxo_openapi.API(access_token=...) >>> params = { "ClientKey": "Cf4xZWiYL6W1nMKpygBLLA==" } ``` ```python >>> r = pf.balances.MarginOverview(params=params) >>> client.request(r) >>> print(json.dumps(r.response, indent=4)) ``` -------------------------------- ### Install saxo_openapi from GitHub with pip Source: https://saxo-openapi.readthedocs.io/en/latest/installation.html Installs the latest development version of the saxo_openapi package directly from the GitHub repository. Requires a token and an account to use the REST API. Consider using a virtual environment before installing. ```bash $ pip install git+https://github.com/hootnot/saxo_openapi.git ``` -------------------------------- ### RemoveSubscriptions params example Source: https://saxo-openapi.readthedocs.io/en/latest/endpoints/eventnotificationservices/clientactivities/RemoveSubscriptions.html Example of the params dictionary for the RemoveSubscriptions request, setting the 'Tag' to 'PAGE2'. ```python params = { "Tag": "PAGE2" } ``` -------------------------------- ### GET openapi/port/v1/netpositions/me Source: https://saxo-openapi.readthedocs.io/en/latest/endpoints/portfolio/netpositions/NetPositionsMe.html Get netpositions for the logged-in client. This endpoint returns the net positions for the authenticated user. ```APIDOC ## GET openapi/port/v1/netpositions/me ### Description Get netpositions for the logged-in client. ### Method GET ### Endpoint openapi/port/v1/netpositions/me ### Parameters #### Query Parameters - **params** (dict) - Optional - dict representing the querystring parameters ### Request Example ``` >>> import saxo_openapi >>> import saxo_openapi.endpoints.portfolio as pf >>> import json >>> client = saxo_openapi.API(access_token=...) >>> params = {} >>> r = pf.netpositions.NetPositionsMe(params=params) >>> client.request(r) >>> print(json.dumps(r.response, indent=4)) ``` ### Response #### Success Response (200) - **response** - The response from the API, typically a JSON object containing net positions. #### Response Example ``` { "response": "..." } ``` ``` -------------------------------- ### Python: CreateInfoPriceSubscription request setup Source: https://saxo-openapi.readthedocs.io/en/latest/endpoints/trading/infoprices/CreateInfoPriceSubscription.html Imports the required modules, creates an API client, and defines the data payload for the CreateInfoPriceSubscription request. The data includes Arguments with AccountKey, AssetType, FieldGroups, and Uics, along with ContextId, ReferenceId, and RefreshRate. ```python >>> import saxo_openapi >>> import saxo_openapi.endpoints.trading as tr >>> import json >>> client = saxo_openapi.API(access_token=...) >>> data = { "Arguments": { "AccountKey": "LZTc7DdejXODf-WSl2aCyQ==", "AssetType": "FxSpot", "FieldGroups": [ "DisplayAndFormat", "HistoricalChanges", "InstrumentPriceDetails", "PriceInfo", "PriceInfoDetails", "Quote" ], "Uics": "22,23" }, "ContextId": "20190307094456688", "ReferenceId": "IP17820", "RefreshRate": 1000 } ``` -------------------------------- ### POST openapi/port/v1/accounts/subscriptions/ Source: https://saxo-openapi.readthedocs.io/en/latest/endpoints/portfolio/accounts/SubscriptionCreate.html Set up a subscription and returns an initial snapshot containing a list of accounts as specified by the parameters in the request. ```APIDOC ## POST openapi/port/v1/accounts/subscriptions/ ### Description Set up a subscription and returns an initial snapshot containing a list of accounts as specified by the parameters in the request. ### Method POST ### Endpoint openapi/port/v1/accounts/subscriptions/ ### Parameters #### Request Body - **data** (dict) - Required - dict representing the request body. ### Request Example { "Arguments": { "ClientKey": "Cf4xZWiYL6W1nMKpygBLLA==" }, "ContextId": "explorer_1551455553043", "ReferenceId": "I_213" } ### Response #### Success Response (201) - **ContextId** (string) - The context ID of the subscription. - **Format** (string) - The format of the response. - **InactivityTimeout** (integer) - The inactivity timeout in seconds. - **ReferenceId** (string) - The reference ID of the subscription. - **RefreshRate** (integer) - The refresh rate in milliseconds. - **Snapshot** (object) - The initial snapshot containing account data. - **Data** (array) - List of account objects. - **AccountGroupKey** (string) - The account group key. - **AccountId** (string) - The account ID. - **AccountKey** (string) - The account key. - **AccountType** (string) - The account type. - **Active** (boolean) - Whether the account is active. - **CanUseCashPositionsAsMarginCollateral** (boolean) - Whether cash positions can be used as margin collateral. - **ClientId** (string) - The client ID. - **ClientKey** (string) - The client key. - **CreationDate** (string) - The creation date of the account. - **Currency** (string) - The account currency. - **CurrencyDecimals** (integer) - The number of currency decimals. - **DirectMarketAccess** (boolean) - Whether direct market access is enabled. - **DisplayName** (string) - The display name of the account. - **IndividualMargining** (boolean) - Whether individual margining is enabled. - **IsCurrencyConversionAtSettlementTime** (boolean) - Whether currency conversion is at settlement time. - **IsMarginTradingAllowed** (boolean) - Whether margin trading is allowed. - **IsShareable** (boolean) - Whether the account is shareable. - **IsTrialAccount** (boolean) - Whether the account is a trial account. - **LegalAssetTypes** (array) - List of legal asset types. - **Sharing** (array) - List of sharing settings. - **SupportsAccountValueProtectionLimit** (boolean) - Whether the account supports value protection limit. - **UseCashPositionsAsMarginCollateral** (boolean) - Whether to use cash positions as margin collateral. - **State** (string) - The state of the subscription. #### Response Example { "ContextId": "explorer_1551455553043", "Format": "application/json", "InactivityTimeout": 30, "ReferenceId": "I_213", "RefreshRate": 5000, "Snapshot": { "Data": [ { "AccountGroupKey": "Cf4xZWiYL6W1nMKpygBLLA==", "AccountId": "9226397", "AccountKey": "Cf4xZWiYL6W1nMKpygBLLA==", "AccountType": "Normal", "Active": true, "CanUseCashPositionsAsMarginCollateral": true, "ClientId": "9226397", "ClientKey": "Cf4xZWiYL6W1nMKpygBLLA==", "CreationDate": "2019-02-02T10:47:42.313000Z", "Currency": "EUR", "CurrencyDecimals": 2, "DirectMarketAccess": false, "DisplayName": "bram", "IndividualMargining": false, "IsCurrencyConversionAtSettlementTime": true, "IsMarginTradingAllowed": true, "IsShareable": false, "IsTrialAccount": true, "LegalAssetTypes": [ "FxSpot", "FxForwards", "FxVanillaOption", "FxKnockInOption", "FxKnockOutOption", "FxOneTouchOption", "FxNoTouchOption" ], "Sharing": [ "NoSharing" ], "SupportsAccountValueProtectionLimit": false, "UseCashPositionsAsMarginCollateral": true } ] }, "State": "Active" } ``` -------------------------------- ### GET openapi/port/v1/accounts/ Source: https://saxo-openapi.readthedocs.io/en/latest/endpoints/portfolio/accounts/AccountListByClient.html Get all accounts owned by the specified client. The request must include a ClientKey parameter. ```APIDOC ## [GET] openapi/port/v1/accounts/ ### Description Get all accounts owned by the specified client. ### Method GET ### Endpoint openapi/port/v1/accounts/ ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **params** (dict) - Required - Must contain at least the ClientKey. ### Request Example ``` >>> import saxo_openapi >>> import saxo_openapi.endpoints.portfolio as pf >>> import json >>> client = saxo_openapi.API(access_token=...) >>> params = { "ClientKey": "Cf4xZWiYL6W1nMKpygBLLA==" } ``` ### Response #### Success Response (200) - **Data** (array) - List of account objects. - **IsMarginTradingAllowed** (boolean) - Indicates if margin trading is allowed. - **DirectMarketAccess** (boolean) - Indicates if direct market access is enabled. - **AccountId** (string) - The account ID. - **ClientId** (string) - The client ID. - **CreationDate** (string) - The creation date of the account. - **SupportsAccountValueProtectionLimit** (boolean) - Indicates if account value protection limit is supported. - **CurrencyDecimals** (integer) - Number of currency decimals. - **ClientKey** (string) - The client key. - **IsTrialAccount** (boolean) - Indicates if it is a trial account. - **Sharing** (array) - Sharing settings. - **IsCurrencyConversionAtSettlementTime** (boolean) - Indicates if currency conversion is at settlement time. - **AccountType** (string) - The account type. - **Active** (boolean) - Indicates if the account is active. - **IndividualMargining** (boolean) - Indicates if individual margining is used. - **CanUseCashPositionsAsMarginCollateral** (boolean) - Indicates if cash positions can be used as margin collateral. - **AccountKey** (string) - The account key. - **AccountGroupKey** (string) - The account group key. - **Currency** (string) - The account currency. - **IsShareable** (boolean) - Indicates if the account is shareable. - **UseCashPositionsAsMarginCollateral** (boolean) - Indicates if cash positions are used as margin collateral. - **LegalAssetTypes** (array) - List of legal asset types. #### Response Example ``` { "Data": [ { "IsMarginTradingAllowed": true, "DirectMarketAccess": false, "AccountId": "9226397", "ClientId": "9226397", "CreationDate": "2019-02-02T10:47:42.313000Z", "SupportsAccountValueProtectionLimit": false, "CurrencyDecimals": 2, "ClientKey": "Cf4xZWiYL6W1nMKpygBLLA==", "IsTrialAccount": true, "Sharing": [ "NoSharing" ], "IsCurrencyConversionAtSettlementTime": true, "AccountType": "Normal", "Active": true, "IndividualMargining": false, "CanUseCashPositionsAsMarginCollateral": true, "AccountKey": "Cf4xZWiYL6W1nMKpygBLLA==", "AccountGroupKey": "Cf4xZWiYL6W1nMKpygBLLA==", "Currency": "EUR", "IsShareable": false, "UseCashPositionsAsMarginCollateral": true, "LegalAssetTypes": [ "FxSpot", "FxForwards", "FxVanillaOption", "FxKnockInOption", "FxKnockOutOption", "FxOneTouchOption", "FxNoTouchOption" ] } ] } ``` ``` -------------------------------- ### Import and setup for GetOpenOrder Source: https://saxo-openapi.readthedocs.io/en/latest/endpoints/portfolio/orders/GetOpenOrder.html Imports the required modules and sets up the client and parameters for a GetOpenOrder request. The ClientKey and OrderId are required, and params is optional. ```python >>> import saxo_openapi >>> import saxo_openapi.endpoints.portfolio as pf >>> import json >>> client = saxo_openapi.API(access_token=...) >>> ClientKey = 'Cf4xZWiYL6W1nMKpygBLLA==' >>> OrderId = '76332324' >>> params = {} ``` -------------------------------- ### MarginOverview response example Source: https://saxo-openapi.readthedocs.io/en/latest/endpoints/portfolio/balances/MarginOverview.html Example response from the MarginOverview endpoint, showing a group with contributors and total margin. ```json { "Groups": [ { "Contributors": [ { "AssetTypes": [ "FxSpot" ], "InstrumentDescription": "British Pound/Canadian Dollar", "InstrumentSpecifier": "GBPCAD", "Margin": 2908, "Uic": 23 }, { "AssetTypes": [ "FxSpot" ], "InstrumentDescription": "British Pound/Australian Dollar", "InstrumentSpecifier": "GBPAUD", "Margin": 14540, "Uic": 22 }, { "AssetTypes": [ "FxSpot" ], "InstrumentDescription": "British Pound/US Dollar", "InstrumentSpecifier": "GBPUSD", "Margin": 291, "Uic": 31 } ], "GroupType": "FX", "TotalMargin": 17739 } ] } ``` -------------------------------- ### GET openapi/root/v1/diagnostics/get/ Source: https://saxo-openapi.readthedocs.io/en/latest/endpoints/rootservices/diagnostics/Get.html Sends a GET request to the diagnostics endpoint and returns a 200 OK response. No data is returned. ```APIDOC ## GET openapi/root/v1/diagnostics/get/ ### Description Sends a GET request to the diagnostics endpoint and returns a 200 OK response. No data is returned. ### Method GET ### Endpoint openapi/root/v1/diagnostics/get/ ### Parameters None ### Request Example ```python >>> import saxo_openapi >>> import saxo_openapi.endpoints.rootservices as rs >>> import json >>> client = saxo_openapi.API(access_token=...) >>> r = rs.diagnostics.Get() >>> rv = client.request(r) >>> assert r.status_code == r.expected_status ``` ### Response #### Success Response (200) No data is returned. #### Response Example No response body. ``` -------------------------------- ### Python example: Request AccountSummary Source: https://saxo-openapi.readthedocs.io/en/latest/endpoints/accounthistory/accountvalues/AccountSummary.html Shows how to instantiate an AccountSummary request with a ClientKey, send it via the client, and print the response as JSON. Requires an authenticated saxo_openapi client. ```python >>> import saxo_openapi >>> import saxo_openapi.endpoints.accounthistory as ah >>> import json >>> client = saxo_openapi.API(access_token=...) >>> ClientKey = 'Cf4xZWiYL6W1nMKpygBLLA==' >>> r = ah.accountvalues.AccountSummary(ClientKey=ClientKey) >>> client.request(r) >>> print(json.dumps(r.response, indent=2)) ``` -------------------------------- ### Import and setup for creating OCO orders Source: https://saxo-openapi.readthedocs.io/en/latest/contrib/orders/onfill.html Imports required modules and initializes the API client, retrieves the first account, and extracts its AccountKey. This setup is needed before constructing orders. ```python >>> import json >>> from saxo_openapi import API >>> import saxo_openapi.endpoints.trading as tr >>> import saxo_openapi.endpoints.portfolio as pf >>> from saxo_openapi.contrib.orders import ( ... tie_account_to_order, ... MarketOrderFxSpot, ... TakeProfitDetails, ... StopLossDetails) >>> token = "..." >>> client = API(access_token=token) >>> r = pf.accounts.AccountsMe() >>> rv = client.request(r) >>> # take the first account ... >>> acct = rv['Data'][0] >>> AccountKey = acct['AccountKey'] ``` -------------------------------- ### GET openapi/port/v1/clients/ Source: https://saxo-openapi.readthedocs.io/en/latest/endpoints/portfolio/clients/ClientDetailsByOwner.html Get details about clients under a particular owner. This endpoint requires an OwnerKey parameter in the query string. ```APIDOC ## GET openapi/port/v1/clients/ ### Description Get details about clients under a particular owner. ### Method GET ### Endpoint openapi/port/v1/clients/ ### Parameters #### Query Parameters - **OwnerKey** (string) - Required - The key identifying the owner. ### Request Example ``` { "OwnerKey": "Cf4xZWiYL6W1nMKpygBLLA==" } ``` ### Response #### Success Response (200) - **Data** (array) - List of client details. - **AccountValueProtectionLimit** (number) - Account value protection limit. - **ClientId** (string) - Client identifier. - **ClientKey** (string) - Client key. - **CurrencyDecimals** (integer) - Number of currency decimals. - **DefaultAccountId** (string) - Default account identifier. - **DefaultAccountKey** (string) - Default account key. - **DefaultCurrency** (string) - Default currency. - **IsMarginTradingAllowed** (boolean) - Whether margin trading is allowed. - **IsVariationMarginEligible** (boolean) - Whether variation margin is eligible. - **LegalAssetTypes** (array of strings) - Legal asset types. - **LegalAssetTypesAreIndicative** (boolean) - Whether legal asset types are indicative. - **Name** (string) - Client name. - **PositionNettingMode** (string) - Position netting mode. - **SupportsAccountValueProtectionLimit** (boolean) - Whether account value protection limit is supported. #### Response Example ``` { "Data": [ { "AccountValueProtectionLimit": 10000, "ClientId": "9226397", "ClientKey": "Cf4xZWiYL6W1nMKpygBLLA==", "CurrencyDecimals": 2, "DefaultAccountId": "9226397", "DefaultAccountKey": "Cf4xZWiYL6W1nMKpygBLLA==", "DefaultCurrency": "EUR", "IsMarginTradingAllowed": true, "IsVariationMarginEligible": false, "LegalAssetTypes": [ "FxSpot", "FxForwards", "FxVanillaOption", "FxKnockInOption", "FxKnockOutOption", "FxOneTouchOption", "FxNoTouchOption" ], "LegalAssetTypesAreIndicative": false, "Name": "F. Brekeveld", "PositionNettingMode": "EndOfDay", "SupportsAccountValueProtectionLimit": true } ] } ``` ``` -------------------------------- ### InstrumentsDetails request setup and execution Source: https://saxo-openapi.readthedocs.io/en/latest/endpoints/referencedata/instruments/InstrumentsDetails.html Shows how to instantiate an InstrumentsDetails request with the required querystring parameters (AccountKey and Uics) and then send it via the client, printing the JSON response. ```python >>> import json >>> import saxo_openapi >>> import saxo_openapi.endpoints.referencedata as rd >>> client = saxo_openapi.API(access_token=...) >>> params = { "AccountKey": "Cf4xZWiYL6W1nMKpygBLLA==", "Uics": "23" } ``` ```python >>> r = rd.instruments.InstrumentsDetails(params=params) >>> client.request(r) >>> print(json.dumps(r.response, indent=4)) ``` -------------------------------- ### Example usage of FxSpotExposureMe Source: https://saxo-openapi.readthedocs.io/en/latest/endpoints/portfolio/exposure/FxSpotExposureMe.html Shows how to instantiate the FxSpotExposureMe endpoint, make a request, and print the response. Requires an access token for the API client. ```python >>> import saxo_openapi >>> import saxo_openapi.endpoints.portfolio as pf >>> import json >>> client = saxo_openapi.API(access_token=...) >>> r = pf.exposure.FxSpotExposureMe() >>> client.request(r) >>> print(json.dumps(r.response, indent=2)) ``` ```json [ { "Amount": 431950, "AmountInCalculationEntityCurrency": 57878, "Currency": "DKK" }, { "Amount": 60000, "AmountInCalculationEntityCurrency": 60000, "Currency": "EUR" }, { "Amount": -50000, "AmountInCalculationEntityCurrency": -57878, "Currency": "GBP" }, { "Amount": -67402.2, "AmountInCalculationEntityCurrency": -60000, "Currency": "USD" } ] ``` -------------------------------- ### Cultures response example Source: https://saxo-openapi.readthedocs.io/en/latest/endpoints/referencedata/cultures/Cultures.html Example JSON response from the Cultures endpoint, showing a list of culture codes and names. ```json { "Data": [ { "CultureCode": "af-ZA", "Name": "Afrikaans (South Africa)" }, { "CultureCode": "am-ET", "Name": "Amharic (Ethiopia)" }, { "CultureCode": "ar-AE", "Name": "Arabic (U.A.E.)" }, { "CultureCode": "ar-BH", "Name": "Arabic (Bahrain)" }, { "CultureCode": "ar-DZ", "Name": "Arabic (Algeria)" }, { "CultureCode": "...", "Name": "..." }, { "CultureCode": "zh-CN", "Name": "Chinese (Simplified, PRC)" }, { "CultureCode": "zh-HK", "Name": "Chinese (Traditional, Hong Kong S.A.R.)" }, { "CultureCode": "zh-MO", "Name": "Chinese (Traditional, Macao S.A.R.)" }, { "CultureCode": "zh-SG", "Name": "Chinese (Simplified, Singapore)" }, { "CultureCode": "zh-TW", "Name": "Chinese (Traditional, Taiwan)" }, { "CultureCode": "zu-ZA", "Name": "isiZulu (South Africa)" } ] } ``` -------------------------------- ### ClientDetailsUpdate request data example Source: https://saxo-openapi.readthedocs.io/en/latest/endpoints/portfolio/clients/ClientDetailsUpdate.html Example of constructing the data dictionary for a ClientDetailsUpdate request, including AccountValueProtectionLimit and NewPositionNettingMode. ```python >>> import saxo_openapi >>> import saxo_openapi.endpoints.portfolio as pf >>> import json >>> client = saxo_openapi.API(access_token=...) >>> data = { "AccountValueProtectionLimit": 10000, "NewPositionNettingMode": "EndOfDay" } ```