smallcase Transactions: AMO cancellation

smallcase AMO orders

For certain smallcase order types (BUY, INVESTMORE, EXIT, SIP, PARTIALEXIT & FIX) and supported broker, after market orders are allowed.
When such an order is placed, the order is considered in an "open state", and the user might want to cancel any such open order. To facilitate this, CANCEL_AMO intent can be used.

AMO orders can be identified by looking at the amoPending key in the flags object while fetching investment details. If amoPending is true, it means the order was placed after market hours and the order is in open state. The orders are to be executed by the broker when the market opens the next day.

If the user wishes to cancel the AMO order, they can do so via a transaction with the CANCEL_AMO intent. A transactionId has to be created using the create transaction API with CANCEL_AMO intent and the iscid for the smallcase order that is in the open state. This transactionId can then be used with the trigger transaction method of SDKs to initiate the transaction. Once complete SDK will return information regarding the cancellation.

Integration details

Step 1: Create a transaction on your server

When the user intends to cancel a smallcase AMO order, a transactionId has to be created for the SDK interaction.
Use create transaction API on your server to create and fetch a unique transactionId.
The payload to create CANCEL_AMO transaction should look like this.

{
  intent: ‘CANCEL_AMO’,
  orderConfig: {
    iscid: ‘<iscid>’
  },
  notes: 'test string'
}

The api will perform basic validations and return the transactionId. This transactionId can then be sent your client application.

Step 2: trigger the transaction from sdk

The transactionId received from the transaction API can now be used with Gateway SDKs. Pass the transactionId to SDK's trigger transaction method. Gateway SDK will now open the cancellation dialog and the user can proceed to cancel the AMO order. If successful, the AMO order will get canceled and the broker won't place the order when the market reopens.

Once the transaction is complete, SDK will share JSON data containing relevant information.

{
  "smallcaseAuthToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzbWFsbGNhc2VBdXRoSWQiOiI2MWZhNGU3OTZkZGEwZDNlMGVjOWU3MzgiLCJpYXQiOjE2NDM4NzAxOTgsImV4cCI6MTY0Mzg3Mzc5OH0.XkKOIbsrB3-w7E5Ue-gU6T81mbPovJTIH6kOOtDFvNo",
  "name": "All Weather Investing",
  "scid": "SCAW_0001",
  "source": "PROFESSIONAL",
  "batches": [
    {
      "label": "BUY",
      "originalLabel": "BUY",
      "status": "CANCELLED",
      "transactionId": "TRX_1753588628d543999e594c84aaf2fe69", // transactionId used to place the AMO order
      "variety": "amo",
      "buyAmount": 0,
      "sellAmount": 0,
      "completedDate": "2022-02-03T06:36:57.747Z",
      "quantity": 4,
      "filled": 0,
      "batchId": "61fb77c58c6d325ea3ffff06",
      "orders": [
        {
          "orderType": "MARKET",
          "product": "CNC",
          "exchange": "NSE",
          "status": "CANCELLED AMO",
          "quantity": 43,
          "tradingsymbol": "GOLDBEES",
          "transactionType": "BUY",
          "filledQuantity": 0
        },
        {
          "orderType": "MARKET",
          "product": "CNC",
          "exchange": "NSE",
          "status": "CANCELLED AMO",
          "quantity": 2,
          "tradingsymbol": "JUNIORBEES",
          "transactionType": "BUY",
          "filledQuantity": 0
        },
      ],
      "unplaced": []
    }
  ],
  "iscid": "61fb77c58c6d325ea3ffff04",
  "imageUrl": "https://assets.smallcase.com/images/smallcases/200/SCAW_0001.png",
  "transactionId": "TRX_eec80fb5e0e3435d893aa4ac30e820fa" // transactionId for the CANCEL_AMO intent
}

Whether or not the cancellation was a success can be identified from the batch status and order status. If successful, batch status(batches[].status) will be CANCELLED and order status(batches[].orders[].status) will be CANCELLED AMO.

The amoPending flag from investment details can also be used to confirm cancellation.
Batch status can also have the following values

  • COMPLETED: the order got executed by the broker
  • ERROR: the order failed due to some reason