phpExt / Trader v2 API / Update Watchlist
Back to Collection Items
<?php
include("chilkat.php");
// Use "chilkat_9_5_0.php" for versions of Chilkat < 10.0.0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
$http = new CkHttp();
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "name": "my first watchlist",
// "symbol": [
// "GOOG",
// "TSLA",
// "FB",
// "MSFT"
// ]
// }
$json = new CkJsonObject();
$json->UpdateString('name','my first watchlist');
$json->UpdateString('symbol[0]','GOOG');
$json->UpdateString('symbol[1]','TSLA');
$json->UpdateString('symbol[2]','FB');
$json->UpdateString('symbol[3]','MSFT');
$http->SetRequestHeader('Apca-Api-Secret-Key','{{APCA_API_SECRET_KEY}}');
$http->SetRequestHeader('Apca-Api-Key-Id','{{APCA_API_KEY_ID}}');
$sbRequestBody = new CkStringBuilder();
$json->EmitSb($sbRequestBody);
// resp is a CkHttpResponse
$resp = $http->PTextSb('PUT','https://domain.com/v2/watchlists/:watchlist_id',$sbRequestBody,'utf-8','application/json',false,false);
if ($http->get_LastMethodSuccess() == false) {
print $http->lastErrorText() . "\n";
exit;
}
print $resp->get_StatusCode() . "\n";
print $resp->bodyStr() . "\n";
?>
Curl Command
curl -X PUT
-H "Apca-Api-Key-Id: {{APCA_API_KEY_ID}}"
-H "Apca-Api-Secret-Key: {{APCA_API_SECRET_KEY}}"
-d '{
"name": "my first watchlist",
"symbol": ["GOOG","TSLA","FB","MSFT"]
}'
https://domain.com/v2/watchlists/:watchlist_id
Postman Collection Item JSON
{
"name": "Update Watchlist",
"request": {
"method": "PUT",
"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 \"name\": \"my first watchlist\",\n \"symbol\": [\"GOOG\",\"TSLA\",\"FB\",\"MSFT\"]\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": [
]
}