OpenAPI

In may 2021 Saxo Bank introduced CryptoFX: a new set of instruments that enables clients to gains exposure to the volatility of prices on crypto currencies like Bitcoin and Ethereum. This article covers how to use Saxo's OpenAPI to trade with these new instruments.

Crypto FX for developers

Saxo Banks new CryptoFX instruments are essentially regular FX crosses. This means that they are traded in an identical matter to the regular FX instruments like EURUSD or USDJPY. Crypto FX are implemented as a cross between a primary crypto currency: Bitcoin, Ethereum and Litecoin and a secondary major currency like USD, EUR and JPY.

This means that:

  1. P/L are always in a major currency like USD.
  2. Cryptos can not be traded against each other. Pairs like ETHBTC or LTCBTC are not possible to trade.

Because Crypto FX are implemented as other FX instruments, they behave in the same way: eg they are traded through the same endpoints and have the same AssetType parameter, available order types, response parameters etc. 

Please refer to the section on our home page: https://www.home.saxo/products/crypto for more information about our Crypto offering

Trading Crypto FX on OpenAPI

Instrument information 

Here are some handpicked details about the first Crypto FX instruments that are being released:

Symbol

Uic

AssetType

Description

Decimals

Minimum amount

Max Autotrade size

BTCUSD21700189FxSpotBitcoin/US Dollar20.01 BTC5 BTC
BTCEUR21776927FxSpotBitcoin/Euro20.01 BTC5 BTC
BTCJPY21776937FxSpotBitcoin/Japanese Yen20.01 BTC5 BTC
LTCUSD21750299FxSpotLitecoin/US Dollar21 LTC600 LTC
LTCEUR21776934FxSpotLitecoin/Euro21 LTC600 LTC
LTCJPY21776939FxSpotLitecoin/Japanese Yen21 LTC600 LTC
ETHUSD21750301FxSpotEthereum/US Dollar20.10 ETH60 ETH
ETHEUR21776932FxSpotEthereum/Euro20.10 ETH60 ETH
ETHJPY21776938FxSpotEthereum/Japanese Yen20.10 ETH60 ETH

Info Prices

Indicative prices can be retrieved through the /trade/v1/infoprices endpoint. This provides information on prices, market state etc.

Example: Get info price for BTCUSD:

GET https://gateway.saxobank.com/sim/openapi/trade/v1/infoprices/?AssetType=FxSpot&Uic=21700189
 
HTTP/1.1 200 OK
{
  "AssetType": "FxSpot",
  "LastUpdated": "2021-06-08T07:14:39.460000Z",
  "PriceSource": "SBFX",
  "Quote": {
    "Amount": 0,
    "Ask": 32950.5,
    "Bid": 32808.5,
    "DelayedByMinutes": 0,
    "ErrorCode": "None",
    "MarketState": "Open",
    "Mid": 32879.5,
    "PriceSource": "SBFX",
    "PriceSourceType": "Firm",
    "PriceTypeAsk": "Tradable",
    "PriceTypeBid": "Tradable"
  },
  "Uic": 21700189
}

Read more about the endpoints request/response parameters here: https://www.developer.saxo/openapi/referencedocs/trade/v1/infoprices.

Historical prices and charts 

It's possible to get historical price data for the Crypto FX Instruments back to 19-04-2021 using the chart/v1/charts endpoint. The endpoint requires a specification of the Uic, AssetType and a Horizon. See the table above for which Uics and AssetType to use and the endpoint reference docs for available horizons.

Example: Get hourly samples for ETHJPY

GET https://gateway.saxobank.com/sim/openapi/chart/v1/charts/?AssetType=FxSpot&Count=2&Horizon=60&Mode=Upto&Time=2021-06-08T07:00:00.000000Z&Uic=21776938
 
HTTP/1.1 200 OK
{
  "Data": [
    {
      "CloseAsk": 274953,
      "CloseBid": 273925,
      "HighAsk": 275728,
      "HighBid": 274675,
      "LowAsk": 269026,
      "LowBid": 267860,
      "OpenAsk": 274174,
      "OpenBid": 273170,
      "Time": "2021-06-08T05:00:00.000000Z"
    },
    {
      "CloseAsk": 271013,
      "CloseBid": 269935,
      "HighAsk": 275871,
      "HighBid": 274880,
      "LowAsk": 270679,
      "LowBid": 269640,
      "OpenAsk": 274879,
      "OpenBid": 273925,
      "Time": "2021-06-08T06:00:00.000000Z"
    }
  ],
  "DataVersion": 1547692380
}

Read more about the charts service group here: https://www.developer.saxo/openapi/referencedocs/chart/v1/charts.

Streaming Price Updates

Just like for regular FX crosses you may setup subscriptions to get real-time updated price and chart data. The example below illustrates how to subscribe to chart updates. 

Example: creating streaming subscription to LTCEUR

Create a subscription for the instruments you want updates for:

POST https://gateway.saxobank.com/sim/openapi/chart/v1/charts/subscriptions
BODY
{
    "Arguments": {
        "AssetType": "FxSpot",
        "Horizon": 1,
        "Uic": 21776934
    },
    "ContextId": "ContextIdString",
    "ReferenceId": "ReferenceIdString"
}

This will returns a response containing a confirmation that the subscription has been created and a snapshot of the most recent data:

HTTP/1.1 201 Created
{
  "ContextId": "ContextIdString",
  "InactivityTimeout": 30,
  "ReferenceId": "ReferenceIdString",
  "RefreshRate": 300,
  "Snapshot": {
    "Data": [
      {
        "CloseAsk": 149.9,
        "CloseBid": 149.1,
        "HighAsk": 150,
        "HighBid": 149.1,
        "LowAsk": 149.6,
        "LowBid": 148.6,
        "OpenAsk": 149.7,
        "OpenBid": 148.8,
        "Time": "2021-06-07T12:32:00.000000Z"
      },
    .
    .
    .
    .
      {
        "CloseAsk": 131.8,
        "CloseBid": 130.9,
        "HighAsk": 131.9,
        "HighBid": 131.1,
        "LowAsk": 131.8,
        "LowBid": 130.8,
        "OpenAsk": 131.9,
        "OpenBid": 131,
        "Time": "2021-06-08T08:38:00.000000Z"
      }
    ],
    "DataVersion": 1547806127
  },
  "State": "Active"
}

Using the ReferenceId and Contextid you can now open a websocket connection and listen for updates on CryptoFX instruments. To read more about our streaming options go here: https://www.developer.saxo/openapi/learn/streaming. To see a full implementation of a working streaming connection over websocket, go here: https://github.com/SaxoBank/openapi-samples-js/tree/main/websockets/historical-market-data

Placing orders 

CryptoFX instruments can be traded through OpenAPI by sending a POST request with order details to the /orders endpoint. The following order types are supported:

  • Stop
  • Limit
  • Market
  • StopLimit
  • TrailingStop

Example: buying 100.00 LTCUSD

POST  https://gateway.saxobank.com/sim/openapi/trade/v2/orders
BODY
{
  "AccountKey": "xxxxxxxxxxxxxxxxxxxx",
  "Amount": 100.0,
  "AssetType": "FxSpot",
  "BuySell": "Buy",
  "OrderType": "Market",
  "Uic": 21750299,
  "ManualOrder": false,
  "QuoteCurrency": false
}
 
HTTP/1.1 200 OK
{
  "OrderId": "yyyyyyyyyy"
}

Please note: Quote Currency must be left blank or set to FALSE as CryptoFX does not support placing orders in quote currency.

For more information on placing orders or changing/canceling them read here: https://www.developer.saxo/openapi/referencedocs/trade/v2/orders 

Things to beware

Here is a description of the limitations our current CryptoFX implementation holds.

Trading Times

Like other FX crosses, Crypto FX are traded in the weekdays and NOT in the weekends. This means that it is not possible to either open or close positions over the weekend. Please refer to the FAQ section on our home page: https://www.home.saxo/products/crypto for more information about trading times. 

Charts and historical data

Saxo Bank can only distribute historical prices via OpenAPI going back to the 19th of April 2021.

This has the following implications:

  1. Queries to the /chart endpoint for any CryptoFX pair will only fetch data going back to the 19th of April 2021 00:00:00 no matter the horizon. Thus calling a horizon of for example one year will per June 2021 only return one sample starting the 1st of January 2021.  
  2. Comparing charts of historical data between OpenAPI and SaxoTrader GO/PRO yields the same results from the 19th of April 2021 and forward. Before this date the charts on SaxoTrader GO/PRO will show historical prices and OpenAPI will not.