<jupyter_start><jupyter_text>Accounts[index](./index.ipynb) |[balances](./balances.ipynb) |[instruments](./instrumentlookup.ipynb) |[trading](./trading.ipynb)<jupyter_code>from saxo_openapi import API
import saxo_openapi.endpoints.portfolio as pf
from pprint import pprint
import juputil

token = juputil.read_token()
client = API(access_token=token)<jupyter_output><empty_output><jupyter_text>Get some account details<jupyter_code>r = pf.accounts.AccountsMe()
rv = client.request(r)
pprint(rv)
juputil.request_info(r)
# process all accounts in Data[]
for acct in rv['Data']:
    for k in ['AccountId', 'AccountKey', 'AccountGroupKey', 'ClientId', 'ClientKey']: 
        print("{:<20s} : {:s}".format(k, acct[k]))<jupyter_output>API-endpoint   : openapi/port/v1/accounts/me
METHOD         : GET
Response status: 200
AccountId            : 9300675
AccountKey           : <KEY>
AccountGroupKey      : <KEY>
ClientId             : 9300675
ClientKey            : <KEY>==<jupyter_text>Get details by the **AccountId**<jupyter_code># Save the AccountKey from prior request
AccountKey = rv['Data'][0]['AccountKey']
# ... and initiate another request
r = pf.accounts.AccountDetails(AccountKey=AccountKey)
rv = client.request(r)
pprint(rv)<jupyter_output>{'AccountGroupKey': '<KEY>',
 'AccountId': '9300675',
 'AccountKey': '<KEY>',
 'AccountType': 'Normal',
 'Active': True,
 'CanUseCashPositionsAsMarginCollateral': True,
 'CfdBorrowingCostsActive': False,
 'ClientId': '9300675',
 'ClientKey': '<KEY>',
 'CreationDate': '2019-03-11T11:39:00.000000Z',
 'Currency': 'EUR',
 'CurrencyDecimals': 2,
 'DirectMarketAccess': False,
 'IndividualMargining': False,
 'IsCurrencyConversionAtSettlementTime': True,
 'IsMarginTradingAllowed': True,
 'IsShareable': False,
 'IsTrialAccount': True,
 'LegalAssetTypes': ['FxSpot',
                     'FxForwards',
                     'FxVanillaOption',
                     'ContractFutures',
                     'FuturesOption',
                     'Stock',
                     'StockOption',
                     'CfdOnStock',
                     'Bond',
                     'MutualFund',
                     'CfdOnFutures',
                     'FxK[...]<jupyter_text>Account informationA lot of endpoints require the *AccountKey* or *ClientKey*. The *saxo_openapi.contrib.session* module providesa function *account_info()* to fetch some key properties as a *named tuple*.<jupyter_code>from saxo_openapi.contrib.session import account_info
ai = account_info(client)
print(ai)
# or by property
print("\nAccountKey: ", ai.AccountKey)<jupyter_output>AcctInfo(ClientId='9300675', ClientKey='<KEY>==', AccountId='9300675', AccountKey='<KEY>==')

AccountKey:  fOA0tvOyQqW2aHpWi9P5bw==
{'fraction_non_alphanumeric': 0.14049282824567855, 'fraction_numerical': 0.02721588819418904, 'mean_word_length': 3.8226950354609928, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '206000', 'license': 'MIT', 'n_tokens_mistral': 975, 'n_tokens_neox': 904, 'n_words': 174, 'path': 'jupyter/accounts.ipynb', 'repo_name': 'zeoses/saxo_openapi', 'size': '2865'}