In case someone lands here instea of the other thread.
This is what i have had success with but only after updating/reinstalling the alpaca module in my terminal.
the useful info for V2 is on the git page not the main website for alpaca.
Umm, yes it appears c# is no longer supported. Did they take down the V1 API?
I would like a c# example of how to replace this v1:
var bars = await client.GetBarSetAsync(new BarSetRequest(ticker, TimeFrame.Day) { Limit = days });
With V1 there was an example that go me up and running. It looks like they took down the V1 API and now I’m left out in the cold.
What is going on?
Please post a working example of C# using the V2 interface to get historical data.
The announcement about the v1 API deprecation was published on all public channels (this forum, email, documentation pages) many months ago. In any case, the v2 API is mostly compatible with the old one and the upgrade shouldn’t take too much time.
But in your case, you have to calculate both start and end dates for the request upfront and check your code for any assumptions about results ordering. The old API returns data in descending time order but the new one do it in the opposite order.
In general request will look like this:
var page = await alpacaDataClient.ListHistoricalBarsAsync(
new HistoricalBarsRequest(symbol, startDate, endDate, BarTimeFrame.Day));
var bars = page.Items;
Yes, there is an example as follows. However when I get API keys, they now appear to be a long HEX value, instead of a string. When I enter them as the string, I get “Forbidden”. I am simply trying to execute the provided example. Please help me get the example to work.
using Alpaca.Markets;
using System;
using System.Linq;
using System.Threading.Tasks;
namespace CodeExamples
{
internal static class Example
{
private static string API_KEY = “your_api_key”;
private static string API_SECRET = "your_secret_key";
public static async Task Main(string[] args)
{
// First, open the API connection
var client = Alpaca.Markets.Environments.Paper
.GetAlpacaDataClient(new SecretKey(API_KEY, API_SECRET));
var into = DateTime.Today;
var from = into.AddDays(-5);
// Get daily price data for AAPL over the last 5 trading days.
var bars = await client.ListHistoricalBarsAsync(
new HistoricalBarsRequest("AAPL", from, into, BarTimeFrame.Day));
// See how much AAPL moved in that timeframe.
var startPrice = bars.Items.First().Open;
var endPrice = bars.Items.Last().Close;
var percentChange = (endPrice - startPrice) / startPrice;
Console.WriteLine($"AAPL moved {percentChange:P} over the last 5 days.");
Console.Read();
}
}
I am doing a lot of machine learning to develop buying algorithms and have about 40 stocks bought so far in my portfolio (real money). I would be happy to discuss trading ideas.
It would be interesting to see what you are doing.
I have written a Windows app that uses indicators to trigger events in a state machine. The states are like: trending up / trending down / ranging (long or no position).
The indicators have parameter ranges, for example SMA could be 50/60/70/80/90/100 days.
The app then backtests the state machine to determine the optimal parameter set for each ticker.
Based on this optimized model, the present state of each ticker is listed, with a recommended action (buy/sell/hold/wait).
This could be considered AI, but it is very deliberate and structured. I’m not pointing the computer at data sets and having it “find” relationships. I have designed a very specific framework and the computer needs to learn within specific bounds.