Stock Data
This section provides examples on retrieving the list of stocks supported on Dinari and supporting metadata for those stocks.
SDK References
SDK Examples
Get list of Stocks
import Dinari from '@dinari/api-sdk';
const client = new Dinari({
apiKeyID: process.env['DINARI_API_KEY_ID'], // This is the default and can be omitted
apiSecretKey: process.env['DINARI_API_SECRET_KEY'], // This is the default and can be omitted
environment: 'sandbox', // defaults to 'production'
});
async function main() {
const stocks = await client.v2.marketData.stocks.list();
console.log(stocks);
}
main();
import os
from dinari_api_sdk import Dinari
client = Dinari(
api_key_id=os.environ.get("DINARI_API_KEY_ID"), # This is the default and can be omitted
api_secret_key=os.environ.get("DINARI_API_SECRET_KEY"), # This is the default and can be omitted
environment="sandbox", # defaults to "production"
)
stocks = client.v2.market_data.stocks.list()
package main
import (
"context"
"fmt"
"log"
dinari "github.com/dinaricrypto/dinari-api-sdk-go"
"github.com/dinaricrypto/dinari-api-sdk-go/option"
)
func main() {
// DINARI_API_KEY_ID and DINARI_API_SECRET_KEY should be set as environment variables
client := dinari.NewClient(
option.WithEnvironmentSandbox(), // Defaults to production when omitted
)
// Example: Get a list of all stocks
stocks, err := client.V2.MarketData.Stocks.List(context.TODO(), dinari.V2MarketDataStockListParams{})
if err != nil {
log.Fatalf("Failed to list stocks: %v", err)
}
fmt.Printf("Stocks: %+v\\n", stocks)
}
Get historical prices for a Stock
import Dinari from '@dinari/api-sdk';
const client = new Dinari({
apiKeyID: process.env['DINARI_API_KEY_ID'], // This is the default and can be omitted
apiSecretKey: process.env['DINARI_API_SECRET_KEY'], // This is the default and can be omitted
environment: 'sandbox', // defaults to 'production'
});
async function main() {
const stockID = 'stock-id-here';
const prices = await client.v2.marketData.stocks.retrieveHistoricalPrices(stockID, {
timespan: 'DAY',
});
console.log(prices);
}
main();
import os
from dinari_api_sdk import Dinari
client = Dinari(
api_key_id=os.environ.get("DINARI_API_KEY_ID"), # This is the default and can be omitted
api_secret_key=os.environ.get("DINARI_API_SECRET_KEY"), # This is the default and can be omitted
environment="sandbox", # defaults to "production"
)
prices = client.v2.market_data.stocks.retrieve_historical_prices(
stock_id="stock_xxx", # Replace with the actual Stock ID
timespan="DAY",
)
package main
import (
"context"
"fmt"
"log"
"os"
dinari "github.com/dinaricrypto/dinari-api-sdk-go"
"github.com/dinaricrypto/dinari-api-sdk-go/option"
)
func main() {
// DINARI_API_KEY_ID and DINARI_API_SECRET_KEY are set as environment variables
client := dinari.NewClient(
option.WithEnvironmentSandbox(), // Defaults to production when omitted
)
stockID := "target-stock-uuid"
queryParams := dinari.V2MarketDataStockGetHistoricalPricesParams{
Timespan: dinari.V2MarketDataStockGetHistoricalPricesParamsTimespanDay,
}
resp, err := client.V2.MarketData.Stocks.GetHistoricalPrices(context.TODO(), stockID, queryParams)
if err != nil {
log.Fatalf("Error getting historical prices: %v", err)
}
fmt.Printf("Response: %+v\\n", resp)
}
Get news for a Stock
import Dinari from '@dinari/api-sdk';
const client = new Dinari({
apiKeyID: process.env['DINARI_API_KEY_ID'], // This is the default and can be omitted
apiSecretKey: process.env['DINARI_API_SECRET_KEY'], // This is the default and can be omitted
environment: 'sandbox', // defaults to 'production'
});
async function main() {
const stockID = 'stock-id-here'; // Replace with the actual stock ID
// Optionally specify a limit on the number of news articles returned
const news = await client.v2.marketData.stocks.retrieveNews(stockID, { limit: 5 });
console.log(news);
}
main();
import os
from dinari_api_sdk import Dinari
client = Dinari(
api_key_id=os.environ.get("DINARI_API_KEY_ID"), # This is the default and can be omitted
api_secret_key=os.environ.get("DINARI_API_SECRET_KEY"), # This is the default and can be omitted
environment="sandbox", # defaults to "production"
)
news = client.v2.market_data.stocks.retrieve_news(
stock_id="stock_xxx", # Replace with the actual Stock ID
limit=5,
)
package main
import (
"context"
"fmt"
"log"
dinari "github.com/dinaricrypto/dinari-api-sdk-go"
"github.com/dinaricrypto/dinari-api-sdk-go/option"
)
func main() {
// DINARI_API_KEY_ID and DINARI_API_SECRET_KEY are set as environment variables
client := dinari.NewClient(
option.WithEnvironmentSandbox(), // Defaults to production when omitted
)
stockID := "target-stock-uuid"
queryParams := dinari.V2MarketDataStockGetNewsParams{
Limit: dinari.Int(5),
}
news, err := client.V2.MarketData.Stocks.GetNews(context.TODO(), stockID, queryParams)
if err != nil {
log.Fatalf("Failed to get stock news: %v", err)
}
fmt.Printf("News: %+v\\n", news)
}
Get live market quote for a Stock
import Dinari from '@dinari/api-sdk';
const client = new Dinari({
apiKeyID: process.env['DINARI_API_KEY_ID'], // This is the default and can be omitted
apiSecretKey: process.env['DINARI_API_SECRET_KEY'], // This is the default and can be omitted
environment: 'sandbox', // defaults to 'production'
});
async function main() {
const stockID = 'stock-id-here';
const quote = await client.v2.marketData.stocks.retrieveQuote(stockID);
console.log(quote);
}
main();
import os
from dinari_api_sdk import Dinari
client = Dinari(
api_key_id=os.environ.get("DINARI_API_KEY_ID"), # This is the default and can be omitted
api_secret_key=os.environ.get("DINARI_API_SECRET_KEY"), # This is the default and can be omitted
environment="sandbox", # defaults to "production"
)
quote = client.v2.market_data.stocks.retrieve_quote(
stock_id="stock_xxx" # Replace with the actual Stock ID
)
package main
import (
"context"
"fmt"
"log"
dinari "github.com/dinaricrypto/dinari-api-sdk-go"
"github.com/dinaricrypto/dinari-api-sdk-go/option"
)
func main() {
// DINARI_API_KEY_ID and DINARI_API_SECRET_KEY are set as environment variables
client := dinari.NewClient(
option.WithEnvironmentSandbox(), // Defaults to production when omitted
)
stockID := "target-stock-uuid"
stockQuote, err := client.V2.MarketData.Stocks.GetQuote(context.TODO(), stockID)
if err != nil {
log.Fatalf("Failed to get stock quote: %v", err)
}
fmt.Printf("Quote: %+v\\n", stockQuote)
}
Updated 14 days ago