Chilkat Online Tools

C / Trader v2 API / Asset to Watchlist

Back to Collection Items

#include <C_CkHttp.h>
#include <C_CkJsonObject.h>
#include <C_CkHttpResponse.h>

void ChilkatSample(void)
    {
    HCkHttp http;
    BOOL success;
    HCkJsonObject json;
    HCkHttpResponse resp;

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    http = CkHttp_Create();

    // Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // {
    //   "symbol": "DIS"
    // }

    json = CkJsonObject_Create();
    CkJsonObject_UpdateString(json,"symbol","DIS");

    CkHttp_SetRequestHeader(http,"Apca-Api-Secret-Key","{{APCA_API_SECRET_KEY}}");
    CkHttp_SetRequestHeader(http,"Apca-Api-Key-Id","{{APCA_API_KEY_ID}}");

    resp = CkHttp_PostJson3(http,"https://domain.com/v2/watchlists/:watchlist_id","application/json",json);
    if (CkHttp_getLastMethodSuccess(http) == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(json);
        return;
    }

    printf("%d\n",CkHttpResponse_getStatusCode(resp));
    printf("%s\n",CkHttpResponse_bodyStr(resp));
    CkHttpResponse_Dispose(resp);


    CkHttp_Dispose(http);
    CkJsonObject_Dispose(json);

    }

Curl Command

curl -X POST
	-H "Apca-Api-Key-Id: {{APCA_API_KEY_ID}}"
	-H "Apca-Api-Secret-Key: {{APCA_API_SECRET_KEY}}"
	-d '{
  "symbol": "DIS"
}'
https://domain.com/v2/watchlists/:watchlist_id

Postman Collection Item JSON

{
  "name": "Asset to Watchlist",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Apca-Api-Key-Id",
        "value": "{{APCA_API_KEY_ID}}",
        "type": "text"
      },
      {
        "key": "Apca-Api-Secret-Key",
        "value": "{{APCA_API_SECRET_KEY}}",
        "type": "text"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"symbol\": \"DIS\"\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{HOST}}/v2/watchlists/:watchlist_id",
      "host": [
        "{{HOST}}"
      ],
      "path": [
        "v2",
        "watchlists",
        ":watchlist_id"
      ],
      "variable": [
        {
          "key": "watchlist_id",
          "value": null
        }
      ]
    }
  },
  "response": [
  ]
}