Get trades data (also known as time and sales)
curl --request GET \
--url https://openapi.ainvest.com/open/marketdata/trades \
--header 'Authorization: Bearer <token>'import requests
url = "https://openapi.ainvest.com/open/marketdata/trades"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://openapi.ainvest.com/open/marketdata/trades', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://openapi.ainvest.com/open/marketdata/trades",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://openapi.ainvest.com/open/marketdata/trades"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://openapi.ainvest.com/open/marketdata/trades")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://openapi.ainvest.com/open/marketdata/trades")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"data": {
"data": [
{
"t": 123,
"p": 123,
"q": 123
}
]
},
"status_code": 123,
"status_msg": "<string>"
}{
"status_code": 4012,
"status_msg": "Invalid param"
}Market Data
Trades
Use this endpoint to get count trades for a specific stock ticker, printed immediately before the to timestamp. The trades are ordered by time, ascending.
GET
/
marketdata
/
trades
Get trades data (also known as time and sales)
curl --request GET \
--url https://openapi.ainvest.com/open/marketdata/trades \
--header 'Authorization: Bearer <token>'import requests
url = "https://openapi.ainvest.com/open/marketdata/trades"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://openapi.ainvest.com/open/marketdata/trades', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://openapi.ainvest.com/open/marketdata/trades",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://openapi.ainvest.com/open/marketdata/trades"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://openapi.ainvest.com/open/marketdata/trades")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://openapi.ainvest.com/open/marketdata/trades")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"data": {
"data": [
{
"t": 123,
"p": 123,
"q": 123
}
]
},
"status_code": 123,
"status_msg": "<string>"
}{
"status_code": 4012,
"status_msg": "Invalid param"
}Currently only returns data for current trading day. Access to historical tick data is not implemented yet
Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your key. Get the key here
Query Parameters
US stock market ticker symbol, e.g. AAPL, TSLA, etc.
The number of trades to return
End of the requested period, unix timestamp with milliseconds