Swift3 / Trader v2 API / Update Watchlist
Back to Collection Items
func chilkatTest() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = CkoHttp()!
var success: Bool
// 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"
// ]
// }
let json = CkoJsonObject()!
json.update("name", value: "my first watchlist")
json.update("symbol[0]", value: "GOOG")
json.update("symbol[1]", value: "TSLA")
json.update("symbol[2]", value: "FB")
json.update("symbol[3]", value: "MSFT")
http.setRequestHeader("Apca-Api-Secret-Key", value: "{{APCA_API_SECRET_KEY}}")
http.setRequestHeader("Apca-Api-Key-Id", value: "{{APCA_API_KEY_ID}}")
let sbRequestBody = CkoStringBuilder()!
json.emitSb(sbRequestBody)
var resp: CkoHttpResponse? = http.pTextSb("PUT", url: "https://domain.com/v2/watchlists/:watchlist_id", textData: sbRequestBody, charset: "utf-8", contentType: "application/json", md5: false, gzip: false)
if http.lastMethodSuccess == false {
print("\(http.lastErrorText!)")
return
}
print("\(resp!.statusCode.intValue)")
print("\(resp!.bodyStr!)")
resp = nil
}
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": [
]
}