Authentication overview
Styvio provides access to its financial market data APIs through a straightforward authentication mechanism centered on API keys. This method is designed to be simple for developers to integrate while maintaining a necessary level of security for accessing sensitive financial information. All interactions with Styvio's API endpoints require a valid API key to be included in the request, ensuring that only authorized users can retrieve data. The API key serves as a unique identifier and credential, linking API requests back to a specific Styvio account and its associated usage limits and permissions. Styvio's approach aligns with common practices for RESTful API authentication in data-centric services, offering a balance between ease of use and security for applications ranging from quantitative analysis to trading and portfolio management applications.
Integrating the API key into your application typically involves passing it as a query parameter or an HTTP header, depending on the specific endpoint requirements. Styvio's SDKs for languages like Python, Node.js, and Go streamline this process by abstracting the HTTP request details, allowing developers to focus on data consumption rather than authentication mechanics. For direct HTTP requests, developers must manually ensure the API key is correctly formatted and included. The system also relies on HTTPS/TLS for all communication, encrypting data in transit to protect both the API key and the financial data being exchanged from interception or tampering. This standard security measure is critical for maintaining the integrity and confidentiality of API interactions.
Supported authentication methods
Styvio primarily supports API Key authentication for accessing its market data APIs. This method is widely adopted for its simplicity and effectiveness in controlling access to resources. API keys are long, randomly generated strings that act as both an identifier and a secret token. When an API request is made, the key is presented to the Styvio API server, which then verifies its validity and the permissions associated with the key before processing the request. This approach simplifies client-side implementation as it does not require complex token exchange flows like OAuth 2.0, which are typically used for delegated authorization rather than direct application access to its own resources. The use of API keys is appropriate for server-to-server communication or applications where the API key can be securely stored and managed.
While API keys are the primary method, it's important to understand their context within the broader landscape of authentication. More complex systems, such as OAuth 2.0, are often used for scenarios where a third-party application needs limited access to a user's resources without exposing the user's credentials to the application developer (e.g., Google's OAuth 2.0 implementation). However, for a direct data access API like Styvio's, API keys provide an efficient and secure solution when handled correctly. Styvio enforces HTTPS for all API interactions, ensuring that API keys and data are encrypted during transmission, mitigating risks associated with man-in-the-middle attacks. Developers can also rotate their API keys periodically from the Styvio dashboard to further enhance security, a practice recommended for any long-lived credentials.
| Method | When to Use | Security Level |
|---|---|---|
| API Key | Direct application access, server-side integrations, services managing their own credentials. | High (when combined with HTTPS, secure storage, and key rotation). |
Getting your credentials
To begin using Styvio's APIs, you first need to obtain your unique API key. This key serves as your primary credential for authenticating all requests to the Styvio platform. The process is straightforward and can be completed through your Styvio account dashboard. If you don't already have a Styvio account, you will need to register for one on the Styvio homepage.
- Create or Log in to Your Styvio Account: Navigate to the Styvio website and either sign up for a new account or log in to your existing one. Access to the API key management section is typically restricted to authenticated users.
- Access the Dashboard: Once logged in, locate the user dashboard or developer portal. This is usually accessible via a link like "Dashboard," "My Account," or "Developer Settings."
- Find the API Key Section: Within the dashboard, look for a section specifically labeled "API Keys," "Developer API," or similar. Styvio's developer documentation provides specific navigation instructions if needed.
- Generate Your API Key: If you haven't generated a key before, there will likely be an option to "Generate New API Key" or "Create Key." Clicking this will securely generate a unique API key for your account.
- Copy and Securely Store Your Key: Once generated, your API key will be displayed. It is crucial to copy this key immediately and store it in a secure location. For security reasons, Styvio may only display the full key once, or portions of it may be masked after initial generation. Do not embed your API key directly into client-side code that could be publicly accessible (e.g., JavaScript in a web browser). Instead, use environment variables, secret management services, or a secure backend server to store and utilize the key.
- Review Usage and Limits: While on the dashboard, you can also review your current API usage, remaining requests, and any specific plan details or limits associated with your account, including the Styvio free tier of 50 API requests per day.
Remember that your API key is sensitive information. Treat it like a password. If you suspect your API key has been compromised, you should immediately generate a new one from your Styvio dashboard and revoke the old key. Styvio provides tools within the dashboard for key management, including rotation and revocation features, which are important for maintaining the security of your integrations.
Authenticated request example
Once you have obtained your API key, you can include it in your API requests to Styvio's endpoints. Styvio supports passing the API key as a query parameter in the URL. Below are examples using cURL for direct HTTP requests and Python with the requests library, demonstrating how to authenticate with your key. These examples assume you want to retrieve real-time stock data, one of Styvio's core data products.
cURL example
This example demonstrates a GET request to a hypothetical real-time stock data endpoint, including YOUR_API_KEY as a query parameter.
curl -X GET "https://api.styvio.com/v1/stock/quote?symbol=AAPL&apikey=YOUR_API_KEY"
Replace YOUR_API_KEY with your actual Styvio API key. The symbol=AAPL parameter specifies that you are requesting data for Apple Inc.'s stock.
Python example
For Python developers, using the requests library is a common and idiomatic way to interact with RESTful APIs. Styvio also offers an official Python SDK that simplifies this further.
import requests
import os
# It's best practice to store your API key as an environment variable
API_KEY = os.environ.get('STYVIO_API_KEY')
BASE_URL = "https://api.styvio.com/v1"
if API_KEY is None:
print("Error: STYVIO_API_KEY environment variable not set.")
exit()
endpoint = f"{BASE_URL}/stock/quote"
params = {
'symbol': 'MSFT',
'apikey': API_KEY
}
try:
response = requests.get(endpoint, params=params)
response.raise_for_status() # Raise an HTTPError for bad responses (4xx or 5xx)
data = response.json()
print("Successfully retrieved stock data:")
print(data)
except requests.exceptions.HTTPError as http_err:
print(f"HTTP error occurred: {http_err}")
except requests.exceptions.ConnectionError as conn_err:
print(f"Connection error occurred: {conn_err}")
except requests.exceptions.Timeout as timeout_err:
print(f"Timeout error occurred: {timeout_err}")
except requests.exceptions.RequestException as req_err:
print(f"An error occurred: {req_err}")
Before running the Python example, ensure you have the requests library installed (pip install requests). You should also set your API key as an environment variable named STYVIO_API_KEY (e.g., export STYVIO_API_KEY='YOUR_API_KEY' in your terminal before running the script).
Security best practices
Securing your API keys and interactions with the Styvio API is paramount to protect your data and prevent unauthorized access or usage billing. Adhering to these best practices will help maintain the integrity and confidentiality of your financial data applications.
- Keep API Keys Confidential: Treat your API key as you would a password. Do not hardcode it directly into source code, especially for client-side applications that might be publicly accessible. Avoid committing API keys to version control systems like Git.
- Use Environment Variables or Secret Management: Store API keys in environment variables on your server or use a dedicated secret management service (e.g., AWS Secrets Manager, Google Secret Manager, Azure Key Vault). This separates credentials from your code and makes them easier to manage securely. For local development,
.envfiles are a common practice, but ensure they are excluded from version control. - Restrict Access to API Keys: Limit who has access to your API keys. Only individuals or systems that absolutely require access should have it. Implement proper access controls on servers or environments where keys are stored.
- Utilize HTTPS/TLS: Styvio mandates HTTPS for all API communication. This encrypts data in transit, protecting your API key and the data exchanged from eavesdropping. Always ensure your application uses HTTPS endpoints (
https://) when making requests. - Implement IP Whitelisting (if available): If Styvio offers IP whitelisting capabilities, configure your API key to only accept requests originating from a list of trusted IP addresses. This adds an extra layer of security, preventing unauthorized use even if your key is compromised.
- Rotate API Keys Regularly: Periodically generate new API keys and revoke old ones. This practice reduces the window of exposure if a key is ever compromised without your knowledge. Styvio's dashboard typically offers key rotation features.
- Monitor API Usage: Regularly check your Styvio dashboard for unusual API usage patterns. Spikes in requests or activity from unexpected locations could indicate a compromised key.
- Graceful Error Handling: Implement robust error handling in your application. Specifically, handle authentication errors (e.g., 401 Unauthorized) gracefully. Do not expose sensitive error details to end-users that could aid an attacker.
- Secure Development Practices: Follow general secure development lifecycle (SDL) practices. This includes regular security audits of your code, vulnerability scanning, and staying updated with security advisories for your libraries and frameworks. For broader guidance on securing APIs, resources like the OWASP API Security Top 10 provide valuable insights.