I am currently trying to write something that does orders. But the issue is that I am getting a status 307 and a redirect to another endpoint.
(defn make-order []
(let [response (client/post "https://paper-api.alpaca.markets/v2/orders/"
{:headers {:APCA-API-KEY-ID "PK5XVNGP4R05QXHZM99Y",
:APCA-API-SECRET-KEY "Wb2EOOWKjoL9sJ33zl0ZEJ2SWJMzxnCQ89hRytio6"}
:body (json/write-str {:symbol "GOOGL"
:qty "1"
:side "buy"
:type "market"
:time_in_force "day"})}
)
response-body (:body response)]
;; (json/read-str response-body)
response
))
response:
{:cached nil,
:request-time 113,
:repeatable? false,
:protocol-version {:name “HTTP”, :major 1, :minor 1},
:streaming? false,
:http-client
#object[org.apache.http.impl.client.InternalHttpClient 0x5e1e8f9d “org.apache.http.impl.client.InternalHttpClient@5e1e8f9d”],
:chunked? false,
:reason-phrase “Temporary Redirect”,
:headers
{“Server” “nginx/1.16.1”,
“Date” “Thu, 21 May 2020 16:00:15 GMT”,
“Content-Length” “0”,
“Connection” “close”,
“Location” “/papertrader/api/v2/orders”},
:orig-content-encoding nil,
:status 307,
:length 0,
:body “”,
:trace-redirects }
Why don’t you remove the trailing slash in the URL?
Thank you hitoshi for that suggestion!
I did that and now I am getting an error I don’t understand:
Show: Project-Only All
Hide: Clojure Java REPL Tooling Duplicates (11 frames hidden)
1. Unhandled clojure.lang.ExceptionInfo
clj-http: status 401
{:cached nil,
:request-time 438,
:repeatable? false,
:protocol-version {:name "HTTP", :major 1, :minor 1},
:streaming? true,
:http-client
#object[org.apache.http.impl.client.InternalHttpClient 0x7d3d3bd8 "org.apache.http.impl.client.InternalHttpClient@7d3d3bd8"],
:chunked? false,
:type :clj-http.client/unexceptional-status,
:reason-phrase "Unauthorized",
:headers
{"Server" "nginx/1.16.1",
"Date" "Thu, 21 May 2020 16:35:30 GMT",
"Content-Type" "application/json; charset=UTF-8",
"Content-Length" "83",
"Connection" "close",
"Vary" "Origin"},
:orig-content-encoding nil,
:status 401,
:length 83,
:body
"{\"code\":40110000,\"message\":\"access key verification failed : verification failure\"}",
:trace-redirects []}
support.clj: 201 slingshot.support/stack-trace
client.clj: 240 clj-http.client/exceptions-response
client.clj: 231 clj-http.client/exceptions-response
client.clj: 249 clj-http.client/wrap-exceptions/fn
client.clj: 726 clj-http.client/wrap-accept/fn
client.clj: 748 clj-http.client/wrap-accept-encoding/fn
client.clj: 709 clj-http.client/wrap-content-type/fn
client.clj: 950 clj-http.client/wrap-form-params/fn
client.clj: 984 clj-http.client/wrap-nested-params/fn
client.clj: 1008 clj-http.client/wrap-flatten-nested-params/fn
client.clj: 884 clj-http.client/wrap-method/fn
cookies.clj: 131 clj-http.cookies/wrap-cookies/fn
links.clj: 63 clj-http.links/wrap-links/fn
client.clj: 1037 clj-http.client/wrap-unknown-host/fn
client.clj: 1165 clj-http.client/request*
client.clj: 1158 clj-http.client/request*
client.clj: 1183 clj-http.client/post
client.clj: 1179 clj-http.client/post
RestFn.java: 423 clojure.lang.RestFn/invoke
core.clj: 49 tradeur.core/make-order
core.clj: 48 tradeur.core/make-order
REPL: 211 tradeur.core/eval16988
REPL: 211 tradeur.core/eval16988
Compiler.java: 7177 clojure.lang.Compiler/eval
Compiler.java: 7132 clojure.lang.Compiler/eval
core.clj: 3214 clojure.core/eval
core.clj: 3210 clojure.core/eval
interruptible_eval.clj: 91 nrepl.middleware.interruptible-eval/evaluate/fn
main.clj: 437 clojure.main/repl/read-eval-print/fn
main.clj: 437 clojure.main/repl/read-eval-print
main.clj: 458 clojure.main/repl/fn
main.clj: 458 clojure.main/repl
main.clj: 368 clojure.main/repl
RestFn.java: 137 clojure.lang.RestFn/applyTo
core.clj: 665 clojure.core/apply
core.clj: 660 clojure.core/apply
regrow.clj: 20 refactor-nrepl.ns.slam.hound.regrow/wrap-clojure-repl/fn
RestFn.java: 1523 clojure.lang.RestFn/invoke
interruptible_eval.clj: 84 nrepl.middleware.interruptible-eval/evaluate
interruptible_eval.clj: 56 nrepl.middleware.interruptible-eval/evaluate
interruptible_eval.clj: 155 nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
AFn.java: 22 clojure.lang.AFn/run
session.clj: 190 nrepl.middleware.session/session-exec/main-loop/fn
session.clj: 189 nrepl.middleware.session/session-exec/main-loop
AFn.java: 22 clojure.lang.AFn/run
Thread.java: 834 java.lang.Thread/run
What does Unauthorized mean? I assume my alpaca id and alpaca secret still work, as they work for my get-account function.
That means API key is not matching. Are you sure you are sending the same way as Account API?