Newbie question - POST to /v2/orders

Just created the account today to try out the API.

Sorry if this is not a correct sub-forum, please move appropriately if so.

In what form the server expects the data? I am using the following Delphi code and get 400 Bad Request.

vUrl := ALPACA_URL + ‘/v2/orders’;
vPostData := TStringList.Create;
try
vPostData.Add(‘symbol=’ + ‘AAPL’);
vPostData.Add(‘qty=’ + ‘1’);
//vPostData.Add(‘notional=’ + ‘100’);
vPostData.Add(‘side=’ + ‘buy’);
vPostData.Add(‘type=’ + ‘market’);
vPostData.Add(‘time_in_force=’ + ‘day’);
vResult := FHTTP.Post(vUrl, vPostData);
finally
vPostData.Free;
end;

Cok tesekkurler ederim!

Actually i got it solved, thats the code for everyone using Delphi

JsonToSend := TStringStream.Create(‘{ “symbol”: “TSLA”, “qty”: “2.5”, “side”: “buy”, “type”: “market”, “time_in_force”: “day”}’);
try
FHTTP.Request.ContentType := ‘application/json’;
FHTTP.Request.ContentEncoding := ‘utf-8’;

try
  sResponse := FHTTP.Post(vUrl, JsonToSend);

  ShowMessage(sResponse);
except
  on E: Exception do
    ShowMessage('Error on request: '#13#10 + e.Message);
end;

finally
JsonToSend.Free();
end;

1 Like

Glad you got it solved! Reading your post caught me a little off guard. I learned Turbo Pascal in the late, late 80’s or early, early 90’s. The “:=” is bringing back memories… So, I googled Delphi and was happy to see that it is still out there!

1 Like