Resolution

All pages

Saxo Bank

How the fund talks to Saxo, what it refuses to do, and how to set it up. The decision record is decisions/0019-saxo.md. Saxo is the second live venue. It sits behind the same approval ladder, the same signature and the same HARD rules as Interactive Brokers. Only one broker is configured at a time (BROKER=ibkr or BROKER=saxo).

The fund reaches Saxo through Saxo's OpenAPI, with an app you register yourself. You log in on Saxo's own page, and the fund never sees, asks for or stores your Saxo password. The settings store refuses any field named like one. You sign every order and you sign the go-live. Nothing in this document changes that.

The honest limit. This venue has been built from Saxo's published reference and tested only against a scripted fake (test/helpers/fake-saxo.ts). It has never run against a real Saxo account, simulation or live. The shapes it is least sure of are listed under Uncertain shapes. Run it in Saxo's simulation environment first, and do not sign a live go-live on Saxo until a simulation round trip (connect, check instruments, a signed order, a fill, a reconciliation) has worked end to end on your own account.

Setting it up

  1. Register an app. Log in at developer.saxo with your Saxo login and create an application for the simulation environment. Choose the authorization code grant with PKCE. As its redirect address, register the fund's address followed by /oauth/saxo/callback, for example https://my-fund.tailnet-name.ts.net/oauth/saxo/callback. Saxo sends your browser back only to an address registered exactly.

  2. Enter the settings. In Connections, open the broker card, choose Saxo Bank and fill in:

    SettingWhat it is
    BROKERsaxo
    SAXO_APP_KEYThe app key Saxo shows for your app (the OAuth client id)
    SAXO_APP_SECRETOnly if your app has a secret. A PKCE app does not. Sealed like every secret
    SAXO_REDIRECT_URLThe redirect address registered in step 1, exactly
    SAXO_ENVsim (the default) or live
    SAXO_ACCOUNTOptional: the AccountId to trade. Unset, the client's default account is used

    Or set them in the environment, which always wins over the dashboard:

    # .env
    BROKER=saxo
    SAXO_APP_KEY=<your app key>
    SAXO_REDIRECT_URL=https://my-fund.tailnet-name.ts.net/oauth/saxo/callback
    SAXO_ENV=sim
    

    Settings saved in the dashboard take effect at once; settings in the environment are read at start.

  3. Connect. Press Connect Saxo on the broker card. Your browser goes to Saxo's login page, you log in there, and Saxo sends you back to /oauth/saxo/callback with a one-time code. The fund exchanges it for tokens and returns you to the dashboard. The Connect is single use and expires after ten minutes.

  4. Check the instruments. Press Check instruments. Every name in the universe is mapped to exactly one Saxo instrument: ISIN first, on the home market, with the currency checked. A name that maps to none, or to more than one, is listed and will not be traded.

  5. Rehearse. On the Connections page, the dry run asks Saxo's precheck for one share of the benchmark. Nothing is placed. Then go live in the broker panel, in the simulation environment first. The go-live is the same signed terms, rung check and account check as for IBKR.

SAXO_ENV=live points the same app at Saxo's live gateway. A token issued for the simulation environment is never used against the live one: changing the environment means connecting again. You also need to register a live app at developer.saxo, which Saxo approves separately.

The connection

The tokens are sealed with the integrations key and kept in <data>/saxo-token.json with mode 0600, bound to the environment and app key they were issued for. They never reach the browser, the Record or a log. Without a data directory (--memory) they live in memory and a restart means connecting again.

The access token is renewed a minute before it expires, one renewal at a time, and again once if Saxo answers 401. When Saxo refuses the renewal, or the refresh token has expired, the connection is forgotten and the broker card and topbar ask you to connect again. A network failure during a renewal keeps the connection for the next try.

Disconnect forgets the tokens on this server. It is refused while the fund is live on Saxo; go back to paper first.

Orders: what the fund guarantees

The same guards as IBKR, in the same order, before anything is sent. Each refusal names its reason, and nothing is sent.

  • Saved before sent. Every order is written as sending before the request leaves.
  • ExternalReference is the client order id. Every order is a DAY limit order with ManualOrder: true (you decided it) and the fund's client order id as ExternalReference. A lost answer is looked up by it in Saxo's open orders and order activities, and an order found there is adopted.
  • A lost answer is never resent. Unlike IBKR, Saxo does not refuse a second order with the same reference. So an order whose answer was lost (a timeout, a dropped connection, a server error after the write) stays unknown until Saxo shows it or you resolve it. An order the process was sending when it stopped becomes unknown on restart, with that reason. Recovery and the poll look such an order up and never send it again. Past ORDER_STUCK_MIN it is flagged like any other: see operating.md.
  • No order on a stale price. Only a Tradable bid and ask on an open market price an order. An indicative price or a closed market refuses it. A delayed price is allowed and noted on the order.
  • The collar. The limit must be within 2% of Saxo's price (the mid of bid and ask).
  • No margin. A buy must be covered by the account's cash balance and by what Saxo reports as available for trading. Either figure missing refuses the order.
  • No shorts. A sell must be covered by the shares the account holds at Saxo.
  • EUR only, for now. The account must be in EUR, the order in EUR, and Saxo's instrument in EUR. There is no signed conversion leg to Saxo yet.
  • The precheck is signed. When the fund is live on Saxo, each order you are asked to sign carries Saxo's precheck with its time and hash: the commission and its currency, the cash required, the fund's euro rate and warnings. The digest you sign covers it. A precheck Saxo refuses, or one that raises a pre-trade disclaimer (a PRIIPs/KID notice), cannot be signed: the fund never accepts a disclaimer on your behalf.
  • The precheck is checked when you sign and again before sending, with the same tolerance as IBKR's preview: the commission may move by the larger of EUR 1 and 20%; a commission that appears, vanishes or changes currency, a new warning, an error or a block refuses the signature (or rejects the order unsent), and the approval is issued again for a new signature.
  • Pacing. At most 2 requests a second, and a second between order requests (placement, precheck, cancel). On a 429 a read waits for Saxo's X-RateLimit-*-Reset (a second when it gives none) and is tried once more; an order is never retried. A second 429 in a row pauses every call for a minute or Saxo's reset, whichever is longer. Nothing is sent during the pause.

Fills and reconciliation

The fund polls Saxo's order activities for its orders. Each Fill or FinalFill activity is booked once, by Saxo's execution id. Reconciliation compares the fund's positions and euro cash with Saxo's positions and balance, as for IBKR. The cash compared is the account's cash in its own currency (EUR, since live trading on Saxo is EUR-only). There is no Flex statement at Saxo; the daily statement check is IBKR-only.

Uncertain shapes

Every Saxo field name the fund relies on is in src/broker/saxo/api.ts and nowhere else. These are the ones the published reference did not settle. Where a name is uncertain the reader takes the documented one first and a known alternative second, and returns nothing rather than a guess, which refuses the order.

WhereWhat the fund readsWhy it is uncertain
Precheck costsCost.Long / Cost.Short .Commission, else Costs.*, Commissions[0].Value, EstimatedCommissionThe cost breakdown's layout for FieldGroups: ['Costs'] differs between reference pages
Precheck currencyCost.Currency, else CostCurrency, else the order's currencyNot shown on every example
Pre-trade disclaimersPreTradeDisclaimers.DisclaimerTokens, else its DisclaimerContextAny disclaimer blocks, whatever its shape
Cash availableCashAvailableForTrading, else MarginAvailableForTradingThe second includes margin on some account types; the cash balance is checked too
PositionsPositionBase or NetPositionBase, Uic and AmountNet and per-position views both exist
Instrument marketThe part of Symbol after the colon (ASML:xams), read as the MICObserved in examples, not specified
Instrument idIdentifier, else UicThe search answer names it Identifier
Fill quantity and priceFillAmount / FilledAmount, ExecutionPrice / AveragePriceActivity fields vary by activity type
Fill idExecutionId, else order id, time and sequenceAn activity without an execution id is identified by its position
Rate limitsThe smallest X-RateLimit-*-Reset header, in secondsSaxo sends several dimensions
Order statusFinalFill, Fill, Cancelled, Expired, Rejected, ErrorOther statuses are treated as working

Not done yet

  • Running against a real Saxo account. See the honest limit at the top.
  • Streaming prices and order events. The fund polls.
  • Sending a currency conversion to Saxo, and with it live trading in currencies other than EUR.
  • Accepting a pre-trade disclaimer. An order that raises one is refused; place it at Saxo yourself if you accept it.
  • Keeping the instrument map across restarts. It is cached in memory and signed into the go-live terms.