In the modern financial world, a stock API is the pillar of many financial products and companies, from trading apps, financial tools to quantitative analysis for banks and asset managers. In this tutorial, we will take you step-by-step through the process of integrating our stock API with Bavest so that you can integrate financial data such as stock prices, ETF data and more into your applications.
Where to get an API key and what exactly you need to do is explained in this blog article.
Before you start integrating our API, be sure to read our Statuspage and API documentation carefully. The status page gives you an overview of the current availability and possible maintenance work of our services. The API documentation is your guide to using our API and provides detailed information about available endpoints, data formats, and authentication methods.
Before you start the integration process, there are a few important technical and organizational aspects to consider:
Make sure your tech stack is compatible with our API. Our API supports various programming languages and frameworks, including Python, JavaScript (Node.js), and PHP. Choose the language that best suits your project.
If you want to host your application in the cloud, you should choose an appropriate cloud provider. Our API can be integrated with various cloud services, such as AWS, Google Cloud, and Azure. Make sure your cloud provider provides the resources and services you need.
Before you can use our API, you must have a test API key with support@bavest.co request. You will receive an API key that you can use to access our data.
Our API documentation contains all necessary information to use our interface. Visit the documentation page to learn about available endpoints, data formats, and authentication methods.
With your API key, you can now make your first request to our API. The following is an example of how you can retrieve stock prices.
To retrieve a company's current stock prices, use the following endpoint:
In this example, the share price is retrieved from Apple (symbol: AAPL). Substitute API KEY with your personal API key.
Sample code in Python
Here's sample code in Python that shows how you can use our API:
1import requests
2
3url = "https://api.bavest.co/v0/quote"
4
5headers = {
6 "accept": "application/json",
7 "content-type": "application/json",
8 "x-api-key": "API-Key"
9}
10
11response = requests.post(url, headers=headers)
12
13print(response.text)
Now we want to make sure that the Bavest API does not return an error and actually delivers the latest course from Apple, then the code looks like this:
1import requests
2
3url = "https://api.bavest.co/v0/quote"
4
5payload = {
6 "symbol": "AAPL",
7 "currency": "EUR"
8}
9headers = {
10 "accept": "application/json",
11 "content-type": "application/json",
12 "x-api-key": "API-Key"
13}
14
15response = requests.post(url, json=payload, headers=headers)
16
17if response.status_code == 200:
18 json_data = response.json()
19
20 # Extracting the historical price data for "day"
21 if 'historical_price' in json_data and 'day' in json_data['historical_price']:
22 historical_day_prices = json_data['historical_price']['day']
23
24 # Print the latest update (assuming the latest is the last in the list)
25 if historical_day_prices:
26 latest_price_update = historical_day_prices[-1]
27 print("Latest price update:", latest_price_update)
28 else:
29 print("No historical day prices available.")
30 else:
31 print("Historical price data for 'day' not found in the response.")
32else:
33 print('Error:', response.status_code, response.text)
This code performs the following actions:
- It sends a POST request to the API using the specified URL, payload, and headers.
- Checks whether the response status is 200 (which indicates success).
- Analyze the JSON response and extract the “historical_price” for “day.”
- Shows the last price update from the “historical_price” “day” data.
Depending on which programming language or platform you use, you can integrate our API into your application. Here are a few examples for different languages:
JavaScript (Node.js)
Let's use node-fetch-requests:
npm install node-fetch@2 --save
1const fetch = require('node-fetch');
2
3const url = 'https://api.bavest.co/v0/quote';
4const options = {
5 method: 'POST',
6 headers: {
7 accept: 'application/json',
8 'content-type': 'application/json',
9 'x-api-key': 'API-Key'
10 },
11 body: JSON.stringify({symbol: 'AAPL', currency: 'EUR'})
12};
13
14fetch(url, options)
15 .then(res => res.json())
16 .then(json => console.log(json))
17 .catch(err => console.error('error:' + err));
PHP
For php, we use guzzle-requests:
composer require guzzlehttp/guzzle
1<?php
2require_once('vendor/autoload.php');
3
4$client = new \GuzzleHttp\Client();
5
6$response = $client->request('POST', 'https://api.bavest.co/v0/quote', [
7 'body' => '{"symbol":"AAPL","currency":"EUR"}',
8 'headers' => [
9 'accept' => 'application/json',
10 'content-type' => 'application/json',
11 'x-api-key' => 'API-Key',
12 ],
13]);
14
15echo $response->getBody();
To integrate real-time data via Websockets, you can use wscat. wscat is a WebSocket client that allows you to receive real-time data from our API.
Installing wscat
npm install -g wscat
Make a connection
wscat -c "wss://ws.bavest.co/v0" -H "x-api-key: <API KEY>"
Our API supports various exchanges. To get real-time data for a specific symbol from a specific exchange, append the stock exchange symbol as a suffix to the symbol. For example:
To retrieve fundamental financial data, use the following endpoint: Bavest API Docs: Fundamentals →
Sample code in Python
Request in general:
1const url = 'https://api.bavest.co/v0/stock/fundamentals';
2const options = {
3 method: 'POST',
4 headers: {
5 accept: 'application/json',
6 'content-type': 'application/json',
7 'x-api-key': 'API-Key'
8 },
9 body: JSON.stringify({symbol: 'AAPL'})
10};
11
12fetch(url, options)
13 .then(res => res.json())
14 .then(json => console.log(json))
15 .catch(err => console.error('error:' + err));
Expanded code to save the API response:
1import requests
2import json
3
4url = 'https://api.bavest.co/v0/stock/fundamentals'
5headers = {
6 'accept': 'application/json',
7 'content-type': 'application/json',
8 'x-api-key': 'API-Key'
9}
10data = {
11 'symbol': 'AAPL'
12}
13
14response = requests.post(url, headers=headers, data=json.dumps(data))
15
16if response.status_code == 200:
17 json_data = response.json()
18 print(json_data)
19else:
20 print('Fehler:', response.status_code, response.text)
To retrieve financial data, use the following endpoint: Bavest API Docs: Financials →
The endpoint returns financial data from the income sheet, balance sheet, and cash flow statement, such as the balance sheet, income statement, or cash flow statement.
Sample code in Python
1const fetch = require('node-fetch');
2
3const url = 'https://api.bavest.co/v0/stock/financials';
4const options = {
5 method: 'POST',
6 headers: {
7 accept: 'application/json',
8 'content-type': 'application/json',
9 'x-api-key': 'API-Key'
10 },
11 body: JSON.stringify({
12 symbol: 'AAPL.DE',
13 freq: 'quarterly',
14 statement: 'cf',
15 currency: 'EUR',
16 limit: 1
17 })
18};
19
20fetch(url, options)
21 .then(res => res.json())
22 .then(json => console.log(json))
23 .catch(err => console.error('error:' + err));
When choosing a stock market API, there are several important criteria to consider to ensure that it meets the needs of your project. Here are the key points:
1. Data coverage
2. Data quality and timeliness
3. Reliability and availability
4. Documentation and Support
5. Costs and subscription plans
6. Technical aspects and integration
7. Security and authentication
8. Additional Features
9. User reviews and reputation
10. Flexibility and adaptability
By carefully reviewing these criteria, you can choose the exchange API that best suits your needs and requirements.
Our stock API at Bavest offers numerous benefits:
Bavest stands out for its user-centered model, which emphasizes simplicity and transparency. Customers benefit from:
Bavest caters to a wide range of business types, including asset managers, fintech companies, banks, family offices, consulting firms, companies, and media organizations. The infrastructure supports various applications, from automating research processes to developing innovative financial products
With our infrastructure at Bavest, you can quickly and easily integrate financial data into your applications. Regardless of whether you need current stock prices, historical data or ETF information, alternative data or quantitative portfolio analysis, our API provides you with the necessary basis for your product or asset management.
Are you interested? Then book a demo and talk to us. We look forward to meeting you and would like to get to know you and learn more about your company.
blog