Stock Index API - Ruby Gem
Stock Index is a tool for retrieving current and historical stock market index values. It supports the S&P 500, Dow Jones, Nasdaq Composite, VIX, Nikkei 225, and more.
Installation
Add this line to your application's Gemfile:
gem 'apiverve_stockindex'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install apiverve_stockindex
Getting Started
Get your API key at APIVerve
Basic Usage
require 'apiverve_stockindex'
# Initialize the client
client = APIVerve::Stockindex::Client.new(api_key: "YOUR_API_KEY")
# Make a request
response = client.execute({
index: "sp500",
year: 2023,
month: 6
})
# Print the response
puts response
Error Handling
begin
response = client.execute({ index: "sp500", year: 2023, month: 6 })
puts response["data"]
rescue APIVerve::Stockindex::ValidationError => e
puts "Validation error: #{e.errors.join(', ')}"
rescue APIVerve::Stockindex::APIError => e
puts "API error: #{e.}"
puts "Status code: #{e.status_code}"
end
Debug Mode
# Enable debug logging
client = APIVerve::Stockindex::Client.new(
api_key: "YOUR_API_KEY",
debug: true
)
Example Response
{
"status": "ok",
"error": null,
"data": {
"index": "sp500",
"name": "S&P 500",
"year": 2023,
"month": 6,
"count": 21,
"entries": [
{
"date": "2023-06-01",
"value": 4221.02
},
{
"date": "2023-06-02",
"value": 4282.37
},
{
"date": "2023-06-05",
"value": 4273.79
}
]
}
}
Documentation
For more information, visit the API Documentation.
Support
- Website: https://stockindex.apiverve.com?utm_source=ruby&utm_medium=readme
- Email: hello@apiverve.com
License
This gem is available under the MIT License.