i can’t fetch data from alpaca Account - Documentation | Alpaca
when I try to fetch data from alpaca GitHub - infinitered/apisauce: Axios + standardized errors + request/response transforms.
using react component https://reactjs.org/docs/react-component.html
import alpacaApi from '../services/alpaca'
componentDidMount() {
console.log('fetch data from alpaca')
const api = alpacaApi()
api.getAccount().then((response) => {
console.log(response)
})
}
here is alpacaApi.js file
import apisauce from 'apisauce'
const alpacaApi = (baseURL = config.BASE_URL) => {
const api = apisauce.create({
baseURL: config.BASE_URL,
headers: {
'APACA-API-KEY-ID': config.ALPACA_API_KEY_ID,
'APACA-API-SECRET-KEY': config.ALPACA_API_SECRET_KEY
},
timeout: 5000
})
const getAccount = () => api.get('v2/account')
const getPostitions = () => api.get('v2/positions')
return {
getAccount,
getPostitions
}
}
const config = {
ALPACA_API_KEY_ID: "apikey",
ALPACA_API_SECRET_KEY: "secretkey",
BASE_URL: "https://paper-api.alpaca.markets"
}
export default alpacaApi
it shows error
LOG fetch data from alpaca
LOG {"config": {"adapter": [Function xhrAdapter], "baseURL": "https://paper-api.alpaca.markets", "data": undefined, "headers": {"APACA-API-KEY-ID": "apikey", "APACA-API-SECRET-KEY": "secretkey", "Accept": "application/json"}, "maxBodyLength": -1, "maxContentLength": -1, "method": "get", "params": {}, "timeout": 5000, "transformRequest": [[Function transformRequest]], "transformResponse": [[Function transformResponse]], "transitional": {"clarifyTimeoutError": false, "forcedJSONParsing": true, "silentJSONParsing": true}, "url": "v2/account", "validateStatus": [Function validateStatus], "xsrfCookieName": "XSRF-TOKEN", "xsrfHeaderName": "X-XSRF-TOKEN"}, "data": {"message": "forbidden."}, "duration": 956, "headers": {"connection": "keep-alive", "content-length": "26", "content-type": "application/json", "date": "Wed, 07 Dec 2022 02:36:19 GMT"}, "ok": false, "originalError": [Error: Request failed with status code 403], "problem": "CLIENT_ERROR", "status": 403}
it didn’t show a properties data.
what should i do ??