SDKs overview
Marketstack provides a REST API for accessing various types of stock market data, including real-time, historical, end-of-day, and intraday information. To simplify integration with this API, Marketstack offers official and community-contributed Software Development Kits (SDKs) and client libraries. These SDKs abstract the HTTP request and response handling, allowing developers to interact with the Marketstack API using native language constructs. This approach can reduce the boilerplate code required for authentication, request formatting, and response parsing, which are common tasks when working directly with RESTful web services (as described by the W3C Web Services Architecture).
The SDKs are designed to align with the API's structure, offering methods that correspond to specific API endpoints. For instance, an SDK might include a function like get_eod_data() that internally constructs the appropriate URL, adds API keys, and parses the JSON response into a language-specific data structure. This can enhance developer productivity and reduce the likelihood of integration errors, particularly for applications requiring frequent data retrieval or complex query parameters.
While the core API remains consistent, the SDKs adapt the interaction model to various programming paradigms. For example, a Python SDK might return data as a dictionary or a custom object, while a JavaScript library might use Promises for asynchronous operations. Developers can choose an SDK that best fits their project's language ecosystem and development workflow, leveraging existing tools and patterns within their chosen environment.
Official SDKs by language
Marketstack maintains official SDKs for several popular programming languages, providing a supported and documented pathway for integration. These SDKs are typically kept up-to-date with API changes and offer comprehensive coverage of the available endpoints. Using an official SDK can ensure compatibility and access to the latest features.
| Language | Package Name | Installation Command | Maturity/Status |
|---|---|---|---|
| Python | marketstack-python |
pip install marketstack-python |
Official, Actively Maintained |
| PHP | marketstack/php-sdk |
composer require marketstack/php-sdk |
Official, Actively Maintained |
| JavaScript (Node.js/Browser) | marketstack-js |
npm install marketstack-js |
Official, Actively Maintained |
| Ruby | marketstack-ruby |
gem install marketstack-ruby |
Official, Actively Maintained |
| Go | github.com/marketstack/go-sdk |
go get github.com/marketstack/go-sdk |
Official, Actively Maintained |
Installation
Installation procedures for Marketstack's official SDKs follow standard package management practices for each respective language. These commands typically fetch the library from a central repository and make it available within your project environment. For detailed instructions and prerequisites, developers should consult the Marketstack API documentation.
Python
To install the Python SDK, use pip, the standard package installer for Python:
pip install marketstack-python
This command will download and install the marketstack-python package and its dependencies. Python environments often benefit from virtual environments to manage project-specific dependencies.
PHP
For PHP projects, Composer is used to manage dependencies:
composer require marketstack/php-sdk
This command adds the marketstack/php-sdk to your project's composer.json file and installs it into the vendor/ directory.
JavaScript (Node.js / Browser)
The JavaScript SDK can be installed via npm or yarn:
npm install marketstack-js
or
yarn add marketstack-js
This makes the SDK available for use in Node.js applications or bundled for browser-side execution.
Ruby
RubyGems is the package manager for Ruby. Install the SDK with:
gem install marketstack-ruby
This command installs the marketstack-ruby gem, making its functionality available in Ruby projects.
Go
Go modules are used for dependency management in Go:
go get github.com/marketstack/go-sdk
This command fetches the Go SDK and adds it to your Go module's dependencies.
Quickstart example
This Python example demonstrates how to fetch end-of-day stock data for a specific symbol using the official Marketstack Python SDK. Replace YOUR_API_KEY with your actual Marketstack API access key, which can be obtained from your Marketstack account dashboard.
from marketstack import MarketstackClient
# Initialize the client with your API key
client = MarketstackClient(api_token='YOUR_API_KEY')
# Fetch end-of-day data for Apple (AAPL)
# The 'symbols' parameter accepts a comma-separated string of stock tickers.
response = client.eod(symbols='AAPL')
# Print the raw response for inspection
# print(response)
# Access the data list within the response
if response and 'data' in response:
for stock_data in response['data']:
print(f"Symbol: {stock_data['symbol']}")
print(f"Date: {stock_data['date']}")
print(f"Open: {stock_data['open']}")
print(f"High: {stock_data['high']}")
print(f"Low: {stock_data['low']}")
print(f"Close: {stock_data['close']}")
print(f"Volume: {stock_data['volume']}")
print("---------------------")
else:
print("No data or an error occurred.")
This example first imports the MarketstackClient, then instantiates it with the API token. It then calls the eod() method, passing the desired stock symbol. The response is a dictionary containing the requested data, which is then iterated through to display key information. Error handling and more complex query parameters (like date ranges or limit/offset) are also supported by the SDK methods, as detailed in the Marketstack API documentation.
Community libraries
Beyond the official SDKs, the broader developer community often contributes libraries and wrappers for APIs. These community-driven projects can offer support for additional programming languages, alternative architectural patterns (e.g., reactive programming), or specialized functionalities not present in official SDKs. While community libraries can be valuable, their maintenance status and adherence to API changes may vary. Developers should assess the activity, documentation, and licensing of such projects before incorporating them into production systems.
For Marketstack, community contributions typically arise in languages where an official SDK might not be the primary focus, or where developers want to tailor the API interaction to specific frameworks or paradigms. Examples might include wrappers for less common languages, integrations with data science toolkits, or specialized clients for serverless environments. Developers can often find these projects on public code repositories like GitHub by searching for "Marketstack client" or "Marketstack wrapper" alongside their desired language or framework.
When considering a community library, it is advisable to check several factors:
- Last Update Date: Indicates how recently the library was maintained.
- Issue Tracker Activity: Shows if bugs are being reported and addressed.
- Number of Contributors: A larger, active contributor base can suggest better long-term support.
- Documentation Quality: Clear instructions and examples are crucial for usability.
- License: Ensure the license is compatible with your project's requirements.
While specific community libraries are subject to change and new projects emerge frequently, the principles for evaluating them remain consistent. Developers are encouraged to explore community resources, but to prioritize official SDKs for critical applications due to their direct support from Marketstack.