OpenAPI

What it is

An order activity represents an event or a change which has happened on an order. These events and changes can be an order placement event, an order cancelation event or an event of fully filling of an order. Therefore, an order usually has a lot of order activities during its lifecycle. By putting all the order activities of an order together, we can tell the history of an order. By looking at the latest order activity of an order, we can tell its status. 

Who Needs it

With the /cs/v1/audit/orderactivities endpoint, a trading client can:

  • get the latest execution status of his or her orders by setting EntryType=Last
  • audit how were the orders executed by getting all the historical order activities by setting EntryType=All

In term of a partner client who usually owns a lot of end treading clients, by setting IncludeSubAccounts=true, the partner can

  • get the latest execution status of all its end trading clients' orders
  • get the whole order history of all its end trading clients


Get the Execution History of my Orders

An immediately filled order might be the most simplest case to show order activities. Such order usually has 2 order activities or events, Placed and FinalFilled.

  1. A client placed an order to buy a share.  This action in turn created an Order Placed entry in /orderactivities, which was the first order activity of this order;
  2. Then immediately, the order was filled on the market, which in turn created an Order FinalFilled entry in /orderactivities. 

In order to get all what happened on this order,  the client can query the /audit/orderactivities endpoint as below:

GET https://gateway.saxobank.com/sim/openapi/cs/v1/audit/orderactivities/?OrderId=1000001&EntryType=All
200 - OK

{
  "__count": 2,
  "Data": [
    {
      "ActivityTime": "2018-05-15T15:14:43.908000Z",
      "LogId": "34139673",
      "OrderId": "1000001",
      "Status": "Placed",
      "SubStatus": "Confirmed",
	  ...
      ...
    },
    {
      "ActivityTime": "2018-05-15T15:14:44.588000Z",
      "LogId": "34139673",
      "OrderId": "1000001",
      "Status": "FinalFilled",
      "SubStatus": "Confirmed"
	  ...
	  ...
    }
  ]
}

The first field is called "__count" field. just as its name indicates, this field shows how many order activities are there in the response. There were 2 events in our example.

Then the "Data" field contains the details of each order activity. Here we condensed each activity into 5 fields to simplify the example. 

  • "ActivityTime" means when was this event happen
  • "LogId" is the identifier of each event or order activity
  • "OrderId" shows which order owns this activuty
  • "Status" specifies what kind of event has happened on an order. Order status those will be presented to end clients as agreed with Business are :
    1. Placed: Orders has been placed with Saxo.
    2. Changed: Order has been changed.
    3. Fill - First fill or subsequent fill (but still not 100% filled)
    4. FinalFill: Order is 100%filled
    5. Cancelled: Order is cancelled
    6. Expired: Order is expired.
    7. DoneForDay: Order has been cancelled for today, will be replaced tomorrow.
  • The most common values of "SubStatus" are "Requested", "Confirmed" and "Rejected". For example,
    1. A {"OrderId": 10002,  Status": "Placed", "SubStatus": "Confirmed" } order activity means the order has been successfully placed;
    2. A {"OrderId": 10002, Status": "Cancelled", "SubStatus": "Requested" } order activity indicates that the client has requested to cancel an order but the cancellation is still under execution;
    3. A {"OrderId": 10002, Status": "Cancelled", "SubStatus": "Confirmed" } order activity means that the cancellation has been successfully executed;
    4. In case that the cancellation cannot be executed if the order has already been filled, there would be a {"OrderId": 10002, Status": "Cancelled", "SubStatus": "Rejected" } entry.

For more filters in the request and fields in the response, please refer to https://www.developer.saxo/openapi/referencedocs/cs/v1/audit-orderactivities/getorderstatesasync/88396c9accc21e373925b5cd2ce134dd 


Getting the Last Status of My Orders

It is common that after placing an order, a client needs to know about the latest order status after placing an order. In this case, it is not necessary for the client to know the whole order history but the order activity entry having the last status.

Taking an immediately filled order as an example, the query asking for the last order status is like below:

GET https://gateway.saxobank.com/sim/openapi/cs/v1/audit/orderactivities/?OrderId=1000001&EntryType=Last
200 - OK

{
  "__count": 1,
  "Data": [
    {
      "ActivityTime": "2018-05-15T15:14:44.588000Z",
      "LogId": "34139673",
      "OrderId": "1000001",
      "Status": "FinalFilled",
      "SubStatus": "Confirmed"
	  ...
	  ...
    }
  ]
}


It is also important to notice that the order activity entry having the last status is not always the last event or entry in an order history. Here is an example

  1. a client requested to cancel his order => {"OrderId": 10003, Status": "Cancelled", "SubStatus": "Requested"}
  2. Unfortunately the order was just filled at the same time  => {"OrderId": 10003, Status": "FinalFilled", "SubStatus": "Confirmed"}
  3. The cancelation order then got rejected  => {"OrderId": 10003, Status": "Cancelled", "SubStatus": "Rejected"}

In this case, there were 3 order events or activities. The last order activity in this order history was the Rejected-Canceled one since it happened at last. But it is not the entry having the last order status, the last status is the FinalFilled-Confirmed one, which happened prior to the Rejected-Canceled event.  By specifying EntryType=Last, SAXO will infer the last order status according to the whole history and return {"OrderId": 10003, Status": "FinalFilled", "SubStatus": "Confirmed"} in the response, 



Synchronize Order Activities for All Trading Clients

It is a common requirement for partner companies that they need to