# Get Trading Data for Charts

## Get Candles and Indicators for a Security

{% content-ref url="/pages/-MCzCy-Ef5yyxUh0gAN1" %}
[Get Candles and Indicators for a Security](/rest-api/trading-api/historical-data/get-candles-and-indicators-for-charts.md)
{% endcontent-ref %}

{% tabs %}
{% tab title="Python" %}

```python
import requests

class AutosharesAPIRequest:

    baseURL = "https://pub-api-et-demo-prod.etnasoft.us/api/"
    EtAppKey = "Et App Key from the BO Companies widget"

    token = 'uninitialized'

    username = "your username"
    password = "your password"

    def simpleAuth(self):
        authenticationRequest = requests.post(self.baseURL + 'token', 
                                              headers = {"Accept" : "application/json", "Et-App-Key" : self.EtAppKey, "Username":self.username, "Password":self.password})

        print('Authorization status code: ' + str(authenticationRequest.status_code) + '\n')

        try:
            responseJSON = authenticationRequest.json()
            print(responseJSON)
            self.token = "Bearer " + responseJSON["Token"]
            return responseJSON
        except:
            return "No response"


    def getCandlesAndIndicators(self, securityInfoBody):

        getCandlesAndIndicatorsRequest = requests.put(self.baseURL + 'v1.0/history/symbols/',
                                                      headers = {"Accept" : "application/json", "Et-App-Key" : self.EtAppKey, "Authorization":self.token},
                                                      json = securityInfoBody
                                                      )

        try:
            responseJSON = getCandlesAndIndicatorsRequest.json()
            print (responseJSON)
            return responseJSON
        except:
            return "No response"

#Performing initial Authentication
sampleRequest = AutosharesAPIRequest()
sampleRequest.simpleAuth()

#declaring chart model
chartDataModel = {
"Security":
    {"Symbol":"AAPL",
    "Exchange":"XNAS",
    "Currency":"USD"},    
"SecurityHistorySettings":
    {"StartDate":1542776400,
    "EndDate":1550764844,
    "CandlesCount":-1,
    "Period":"4h",
    "Interval":-7,
    "IncludeNonMarketData":False},
"IndicatorsHistorySettings":[
    {"Signature":"MACD|4h|false|12|26|9",
    "Interval":-7,
    "StartDate":1542776400,
    "EndDate":1550764844,
    "CandlesCount":-1,
    "Offset":0,
    "Indicator":{
        "id":4,
        "indicatorId":1,
        "type":"movingAverageConvergenceDivergenceIndicator",
        "position":"lower",
        "external":True,
        "settings":{
            "id":4,
            "type":"movingAverageConvergenceDivergenceIndicator",
            "shortThickness":2,
            "longThickness":2,
            "shortBrush":"32c814",
            "longBrush":"dc1414",
            "signalBrush":"ff9900",
            "shortPeriod":12,
            "longPeriod":26,
            "signalPeriod":9,
            "showLastValue":True,
            "showCurrentPoint":True,
            "showLevelBands":False}}}]
}

#retrieving candles and indicators for the Apple stock
sampleRequest.getCandlesAndIndicators(chartDataModel)
```

This method — `getCandlesAndIndicators()` — enables you to retrieve chart data (candles and indicators) for a specific security. In response to this request, you'll receive a JSON file with the pricing data that can be used to draw charts.
{% endtab %}

{% tab title="JavaScript" %}

{% endtab %}

{% tab title="C#" %}

{% endtab %}
{% endtabs %}

### CURL

```
curl -X PUT --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: Bearer yourToken' --header 'Et-App-Key: yourKey' -d '{"Security": \ 
     {"Symbol":"AAPL", \ 
     "Exchange":"XNAS", \ 
     "Currency":"USD"}, \ 
      \ 
 "SecurityHistorySettings": \ 
     {"StartDate":1542776400, \ 
     "EndDate":1550764844, \ 
     "CandlesCount":-1, \ 
     "Period":"4h", \ 
     "Interval":-7, \ 
     "IncludeNonMarketData":false}, \ 
  \ 
 "IndicatorsHistorySettings":[ \ 
     {"Signature":"MACD|4h|false|12|26|9", \ 
     "Interval":-7, \ 
     "StartDate":1542776400, \ 
     "EndDate":1550764844, \ 
     "CandlesCount":-1, \ 
     "Offset":0, \ 
     "Indicator":{ \ 
         "id":4, \ 
         "indicatorId":1, \ 
         "type":"movingAverageConvergenceDivergenceIndicator", \ 
         "position":"lower", \ 
         "external":true, \ 
         "settings":{ \ 
             "id":4, \ 
             "type":"movingAverageConvergenceDivergenceIndicator", \ 
             "shortThickness":2, \ 
             "longThickness":2, \ 
             "shortBrush":"32c814", \ 
             "longBrush":"dc1414", \ 
             "signalBrush":"ff9900", \ 
             "shortPeriod":12, \ 
             "longPeriod":26, \ 
             "signalPeriod":9, \ 
             "showLastValue":true, \ 
             "showCurrentPoint":true, \ 
             "showLevelBands":false}}}] \ 
 }' 'https://pub-api-et-demo-prod.etnasoft.us/api/v1.0/history/symbols'
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://api-documentation.autoshares.dev/rest-api/trading-api/code-samples/get-trading-data-for-charts.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
