alpacahq / alpaca-trade-api-csharp Goto Github PK
View Code? Open in Web Editor NEWC# SDK for Alpaca Trade API https://docs.alpaca.markets/
License: Apache License 2.0
C# SDK for Alpaca Trade API https://docs.alpaca.markets/
License: Apache License 2.0
The alpha and beta both fail with 404- Not Found when trying to call the Calendar endpoint. My example failing case is with a date range specified.
_alpacaRestApi.ListCalendarAsync(startDateInclusive: DateTime.Now.AddYears(-2), endDateInclusive: DateTime.Now.AddDays(-1));
This happened to me before, when I tried to embed the version number in the base address, so maybe it is related to that?
DividentsRate should be DividendsRate
NuGet is default way for packaging .NET libraries in both .NET Framework and .NET Core so it would be very helpful to publish SDK on NuGet servers.
Automate build process - test, pack, sign (optional), publish on NuGet and GitHub
I ran into a scenario where JSON parsing failed in the SockClient, and the exception crashed my application. The error was related to the fact that TradeUpdate.Event != OrderStatus, e.g. TradeUpdate.Event will be "fill" instead of "filled". I believe I've fixed those scenarios in the API v02 PR, but would expect that in the event of such exceptions, that they be caught and reported via the SockClient.OnError event, rather than throwing an exception I have no way to catch.
My application used the Nuget package and this morning I updated it, but the Nuget package for 3.0.1 does not contain some of the API. e.g. Post orders, list orders, GetAccountAsync, etc...
After downloading the source repository and compiling it in my project, those functions now are available.
Don't know if the Nuget got corrupted or something is missing with it.
EDIT:
E.g.
Client = new RestClient(key, pkey, url);
Account = await Client.GetAccountAsync();
var clock = await Client.GetClockAsync();
GetAccountAsync(), and GetClockAsync() is not in the Repository.
There are several NATS client problems in current solution:
According to Alpaca REST API documentation it returns HTTP status code 429 in case of number of request per minute it greater than 200. Throttling should be implemented for all request and retry logic should be added for all GET requests.
We need XML documentation for all SDK public interface - it will help users to explore API from VisualStudio UI using tool tips and IDE suggestions.
I am getting 401 error from ListDayAggregatesAsync()
using my production key. I have verified this key works in python client. As far as I can tell, getDefaultPolygonApiQueryBuilder()
is unconditionally setting staging=true
According to the documentation our TimeInForce options are day, gtc, opg, ioc, and fok.
https://docs.alpaca.markets/broker-functions/orders/#time-in-force
However, the SDK only offers Dat, Gtc, and Opg.
Running Alpaca.Markets 2.0.0-beta
Now SDK uses WebSocket4Net library for implementing WebSocket connection. .NET Framework itself contains WebSocket client but it works only on Windows 8 and later. There are some alternative WebSocket client implementations available on NuGet which can conflict with our default choice (see QuantConnect/Lean case). Idea of this change is to abstract concrete WebSocket client and provide default implementation based on built-in client with ability to override it and replace it if required.
It would be nice to have small tutorial for creating new simple application from scratch using this SDK.
Not all HTTP responses with error codes contains extended data in response body. In this case user receives generic JSON parsing error - we should handle this case correctly and throw our own exception type with basic information from HTTP response itself. See more details in issue #84 (HTTP code 404).
ListMinuteAggregatesAsync
Does not function as expected.
What I'm trying:
var test = await client.ListMinuteAggregatesAsync("AAPL", limit:100);
What I expect to happen:
I expect that the last 100 minutes from AAPL's most recent session is returned to me.
What actually happens:
I receive an exception stating that the TimeSpan overflowed because the duration is too long.
Crash:
at System.TimeSpan.Interval (System.Double value, System.Int32 scale) [0x00056] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-02/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/timespan.cs:235
at System.TimeSpan.FromSeconds (System.Double value) [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-02/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/timespan.cs:255
at Alpaca.Markets.DateTimeHelper.FromUnixTimeMilliseconds (System.Int64 linuxTimeStamp) [0x00006] in <8cf8058b94944c6684bcb18c0af60f9c>:0
at Alpaca.Markets.JsonMinuteBar.OnDeserializedMethod (System.Runtime.Serialization.StreamingContext context) [0x00007] in <8cf8058b94944c6684bcb18c0af60f9c>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-02/external/bockbuild/builds/mono-x64/mcs/class/corlib/System.Reflection/MonoMethod.cs:305
--- End of inner exception stack trace ---
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00043] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-02/external/bockbuild/builds/mono-x64/mcs/class/corlib/System.Reflection/MonoMethod.cs:313
at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-02/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/reflection/methodbase.cs:229
at Newtonsoft.Json.Serialization.JsonContract+<>c__DisplayClass57_0.<CreateSerializationCallback>b__0 (System.Object o, System.Runtime.Serialization.StreamingContext context) [0x00000] in <07e3893119a945b29a35e81930b1c8ad>:0
at Newtonsoft.Json.Serialization.JsonContract.InvokeOnDeserialized (System.Object o, System.Runtime.Serialization.StreamingContext context) [0x0001d] in <07e3893119a945b29a35e81930b1c8ad>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.OnDeserialized (Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonContract contract, System.Object value) [0x00049] in <07e3893119a945b29a35e81930b1c8ad>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject (System.Object newObject, Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty member, System.String id) [0x002f9] in <07e3893119a945b29a35e81930b1c8ad>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) [0x00161] in <07e3893119a945b29a35e81930b1c8ad>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) [0x0006d] in <07e3893119a945b29a35e81930b1c8ad>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList (System.Collections.IList list, Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonArrayContract contract, Newtonsoft.Json.Serialization.JsonProperty containerProperty, System.String id) [0x00175] in <07e3893119a945b29a35e81930b1c8ad>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, System.Object existingValue, System.String id) [0x000dc] in <07e3893119a945b29a35e81930b1c8ad>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) [0x0007f] in <07e3893119a945b29a35e81930b1c8ad>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue (Newtonsoft.Json.Serialization.JsonProperty property, Newtonsoft.Json.JsonConverter propertyConverter, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty, Newtonsoft.Json.JsonReader reader, System.Object target) [0x00061] in <07e3893119a945b29a35e81930b1c8ad>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject (System.Object newObject, Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty member, System.String id) [0x00266] in <07e3893119a945b29a35e81930b1c8ad>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) [0x00161] in <07e3893119a945b29a35e81930b1c8ad>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) [0x0006d] in <07e3893119a945b29a35e81930b1c8ad>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Boolean checkAdditionalContent) [0x000db] in <07e3893119a945b29a35e81930b1c8ad>:0
at Newtonsoft.Json.JsonSerializer.DeserializeInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00054] in <07e3893119a945b29a35e81930b1c8ad>:0
at Newtonsoft.Json.JsonSerializer.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00000] in <07e3893119a945b29a35e81930b1c8ad>:0
at Newtonsoft.Json.JsonSerializer.Deserialize[T] (Newtonsoft.Json.JsonReader reader) [0x00000] in <07e3893119a945b29a35e81930b1c8ad>:0
at Alpaca.Markets.RestClient+<getSingleObjectAsync>d__7`2[TApi,TJson].MoveNext () [0x000a9] in <8cf8058b94944c6684bcb18c0af60f9c>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00037] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-02/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-02/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-02/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128
at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-02/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:357
at {DerpBot}Machine.Core.Services.AlpacaService+<GetData>d__0.MoveNext () [0x000e1] in /Users/danbeaulieu/Documents/Dev-personal/{DerpBot}Machine/{DerpBot}Machine/Services/AlpacaServices.cs:27
I've also tried adding dates:
await client.ListMinuteAggregatesAsync("AAPL",dateFromInclusive:DateTime.Now, dateIntoInclusive:DateTime.Now.AddDays(-1), limit:100);
and
await client.ListMinuteAggregatesAsync("AAPL",dateFromInclusive:DateTime.Now.AddDays(-1), dateIntoInclusive:DateTime.Now, limit:100);
When using the above two approaches I do NOT get a crash but I get zero items back from the server.
Please let me know if I'm doing something incorrectly.
.NetStandard 2.0
Alpaca.Markets 2.0.0-alpha
As reported by a user on Slack:
I download Alpaca.Markets and run the test OrderActionsTest in Alpca,Markets.Tests, I got the following error: Newtonsoft.Json.JsonSerializationException
HResult=0x80131500
Message=Error converting value "fill" to type 'Alpaca.Markets.OrderStatus'. Path 'data.event', line 1, position 48.
Source=Newtonsoft.Json
StackTrace:
at Newtonsoft.Json.Converters.StringEnumConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.Linq.JToken.ToObject(Type objectType, JsonSerializer jsonSerializer)
at Newtonsoft.Json.Linq.JToken.ToObject(Type objectType)
at Newtonsoft.Json.Linq.JToken.ToObject[T]()
at Alpaca.Markets.SockClient.handleDataReceived(Object sender, DataReceivedEventArgs e) in C:\Users\chu\OneDrive\Alpaca\alpaca-trade-api-csharp-master\alpaca-trade-api-csharp-master\Alpaca.Markets\SockClient.cs:line 170
at WebSocket4Net.WebSocket.OnDataReceived(Byte[] data, Int32 offset, Int32 length)
at SuperSocket.ClientEngine.AuthenticatedStreamTcpSession.<ReadAsync>d__12.MoveNext()
Inner Exception 1:
ArgumentException: Requested value 'fill' was not found.
The enum value here should be fixed.
Check NuGet dependencies and upgrade them in scope on upcoming minor release.
I've recently set up the Nats client in my application and found that AggReceived
never fires while TradeReceived
and QuoteReceived
fire continuoulsy as expected.
Here is a console application that illustrates the problem.
AlpacaNatsTest.zip
And code for good measure:
class Program
{
public static void Main(string[] args)
=> new Program().MainAsync().GetAwaiter().GetResult();
public async Task MainAsync()
{
var _natsClient = new NatsClient("API_KEY", false);
_natsClient.Open();
_natsClient.OnError += OnNatsClientError;
_natsClient.AggReceived += OnBarReceived;
_natsClient.TradeReceived += OnTradeReceived;
_natsClient.QuoteReceived += OnQuoteReceived;
_natsClient.SubscribeTrade("NFLX");
_natsClient.SubscribeQuote("NFLX");
_natsClient.SubscribeMinuteAgg("NFLX");
System.Console.ReadLine();
_natsClient.Close();
}
private void OnQuoteReceived(IStreamQuote obj)
{
System.Diagnostics.Debug.WriteLine($"Quote {obj.AskPrice}");
}
private void OnTradeReceived(IStreamTrade obj)
{
System.Diagnostics.Debug.WriteLine($"Trade {obj.Price}");
}
private void OnBarReceived(IStreamAgg obj)
{
System.Diagnostics.Debug.WriteLine($"Bar {obj.Close}"); // NEVER fires
}
private void OnNatsClientError(string obj)
{
System.Diagnostics.Debug.WriteLine(obj);
}
}
Using Alpaca.Markets 2.1.2 SDK
Right now all configuration parameters related to request throttling passed into RestClient
constructor but in fact they override properties of static throttler object. It's not good from design and end-user perspective.
I have an idea - create ThrotterFactory
which will create IThrottler
object using data provided by IConfiguration
interface or initialized by Setup method call. This change should make RestClient
and IThrottler
interfaces more clear for use.
I've tried to use sockclient to get trade updates from the websocket.
So far, the sockclient is able to get 'Authorized' message from the server but it never receives any trade-related messages whenever a market order is issued.
I tried other Python API(alpaca-trade-api-python) and it worked well using the same API key.
Please help me.
Thanks.
P.S. The SockClient returns error in Netframework 4.5.2. I temporarily fixed it by manually specifying crypto suites. May need help for this too.
Line 58 of JsonStreamAgg:
EndTime = DateTime.SpecifyKind( DateTimeOffset.FromUnixTimeMilliseconds(StartTimeOffset) .DateTime, DateTimeKind.Utc);
Should reference EndTimeOffset instead of StartTimeOffset. Happy to submit a PR for this
Found Alpaca.Markets.OrderStatus.PendingMew
for PendingNew.
One thing I might change is the verb 'Get' for plural resources such as positions. In my opinion the REST convention is to use the verb 'List' for those, unless there is strong reason.
For better diagnosis build result we have to do next changes on Appveyor build:
Release
configuration instead of default Debug
configuration (add -c Release
flag into dotnet build
command).push
command completion (not sure it's possible but would be very helpful).See issue #55 for more details about build result problem.
There are lot of compiler warnings in this code - we can resolve most of them without affecting code readability.
I'm attempting to set up a NatsClient using the following code:
_natsClient = new NatsClient(myApiKey, true);
_natsClient.Open();
I've tried passing in both my paper API key and my Live api key but both yeild the same error:
NATS.Client.NATSConnectionException: 'Authorization Violation'
at NATS.Client.Connection.connect () [0x00063] in <ccdb36acc9744f499b8322baf250c000>:0
at NATS.Client.ConnectionFactory.CreateConnection (NATS.Client.Options opts) [0x00016] in <ccdb36acc9744f499b8322baf250c000>:0
at Alpaca.Markets.NatsClient.Open () [0x00006] in <efd439f57ff24b40b03331a0e8059cb6>:0
Unfortunately this isn't a lot of information to go on, but I'm assuming there are more steps here that I'm missing.
What are the steps to properly setting up the NatsClient?
Also, I'd like to see a README.md style doc somewhere in the repo (if I am not missing it). This document can contains small tutorial from #1 issue.
Instead of providing specific interface for each type of response/update merge similar interfaces into single one for better client experience.
The new Aggregate function to retrieve Candle data from the Polygon server is not returning the current candle, it only always returns up to the TODATE exclusive. See, https://api.polygon.io/v2/aggs/ticker/ENT/range/1/day/2019-06-10/2019-06-19?unadjusted=false&apiKey= use your own API key. There is no way to retrieve today's 1day Candle. If you change the parameters to 1 hour, you can get today's data, but now you are pulling way more data from the server than what is required to calculate a single days candle.
Use this great Python tutorial as base point and prepare .NET Core based version using C# and latest version of SDK.
Review fixed made in scope of QuantConnect/Lean integration task and back-port all critical changes into this SDK mainline.
It would be nice to have some example algorithms in this repo that people could clone and run to help them get started. Ideally, there should be example scripts that demonstrate how to use the REST endpoints and how to open streaming connections with Alpaca and Polygon.
Add headers for allowing free version of PVS Studio (see details here) to statically analyze source code.
Please refer to alpacahq/alpaca-trade-api-python#49
Alpaca.Markets Package Version: 3.1.1
Issue: When attempting to call GetBarSetAsync a json deserialization error is thrown. Error message states that the required 'code' property is not set, this seems to be swallowing the actual error being thrown, since the message isn't being deserialized properly.
Error Message: Required property 'code' not found in JSON. Path '', line 1, position 34.
Reproduction Code Sample:
using Alpaca.Markets;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace ConsoleApp1
{
public static class Program
{
private static readonly string KEY_ID = "your_key_id";
private static readonly string SECRET_KEY = "your_secret_key";
public static async Task Main(string[] args)
{
var restClient = new RestClient(keyId: KEY_ID, secretKey: SECRET_KEY, alpacaRestApi: "https://paper-api.alpaca.markets", apiVersion: 2);
try
{
Console.WriteLine(restClient.GetClockAsync().Result.IsOpen); //Works fine
var symbs = new List<string> { "AAPL" };
var bars = await restClient.GetBarSetAsync(symbs, TimeFrame.Day, 5); // Fails here
var startPrice = bars.First().Value.First().Open;
var endPrice = bars.Last().Value.Last().Close;
var percentChange = (endPrice - startPrice) / startPrice * 100;
Console.WriteLine($"AAPL moved {percentChange} over the last 5 days.");
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.Read();
}
}
}
Update NuGet dependencies for 3.0.0 release using latest stable versions of 3rd party libraries.
I think it would be more correct for the open/close values in a calendar response, e.g.
{
"date": "2018-01-03",
"open": "09:30",
"close": "16:00"
}
to be interpreted as TimeSpans rather than DateTimes, as they are converted to DateTimes using default values for year/month/day, which usually wind up being wrong. We could do that by implementing a custom TimeSpan converter, like this - https://stackoverflow.com/a/52504446. Alternatively, we could leave them as DateTimes and find a way to pass in the date field as well, but I'm not sure if that's workable with the way converters are done field-by-field.
The current solution to this issue is doing something like this, which I'm not a big fan of:
var calendars = restClient.ListCalendarAsync(DateTime.Today).Result;
var calendarDate = calendars.First().TradingDate;
var closingTime = calendars.First().TradingCloseTime;
closingTime = new DateTime(calendarDate.Year, calendarDate.Month, calendarDate.Day, closingTime.Hour, closingTime.Minute, closingTime.Second);
When I call RestClient.ListHistoricalQuotesAsync('AAPL', new DateTime(2018,8,5)), there is an unhandled exception.
I digged into this, and found 2018-8-5 is Sunday and the polygon api returns null for the 'ticks'.
Is there any way to return null instead of exception in situations like this?
Also in the RestClient.ListDayAggregatesAsync/ListMinuteAggregatesAsync, an unhandled exception(HTTPStatus of 500) is happening.
I remember it worked before and I think the polygon api tightened the requirements for the parameters.
When I changed the format from "dd-MM-yyyy" to "yyyy-MM-dd", all two methods worked as well.
It'd be great to have these issues fixed.
Thanks for the great integration.
Regards.
Here is the full code for the .NET test application and it throws this error:
CS1503 Argument 3: cannot convert from 'System.Uri' to 'string'
using System;
namespace Test
{
class Program
{
static void Main(string[] args)
{
Uri Endpoint = new Uri("https://paper-api.alpaca.markets");
var KeyId = "my_KEY_ID";
var SecretKey = "my_SECRET_KEY";
var client = new Alpaca.Markets.RestClient(
KeyId, SecretKey, Endpoint);
var clock = client.GetClockAsync().Result;
if (clock != null)
{
Console.WriteLine(
"Timestamp: {0}, NextOpen: {1}, NextClose: {2}",
clock.Timestamp, clock.NextOpen, clock.NextClose);
}
}
}
}
Time zone names in Windows and Linux/MacOS are not same. For instance Eastern Standard Time
time zone has America/New_York
name in Linux. SDK will throw exception and we should prevent it.
API base URL would be the same for 99% with api.alpaca.markets so it does not make much sense to give it as a parameter. Also, I would rather want to have config file to feed API key than giving it as parameters.
Hi
Thank you for offerring this wonderfull api to us.
I am using "ListOrdersAsync" to fetch orders. But when I specify after and until parameter.
The service return an exception with error code "422".
Could you please help to figure it out?
Nuget Package Version: 2.1.4
CoreCLR Version: 4.6.27617.4
Description: The process was terminated due to an unhandled exception.
Exception Info: Newtonsoft.Json.JsonSerializationException: Error converting value "partial_fill" to type 'Alpaca.Markets.OrderStatus'. Path 'data.event', line 1, position 56. ---> System.ArgumentException: Requested value 'partial_fill' was not found.
at Newtonsoft.Json.Utilities.EnumUtils.ParseEnum(Type enumType, NamingStrategy namingStrategy, String value, Boolean disallowNumber)
at Newtonsoft.Json.Converters.StringEnumConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
--- End of inner exception stack trace ---
at Newtonsoft.Json.Converters.StringEnumConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.Linq.JToken.ToObject(Type objectType, JsonSerializer jsonSerializer)
at Newtonsoft.Json.Linq.JToken.ToObject(Type objectType)
at Newtonsoft.Json.Linq.JToken.ToObjectT
at Alpaca.Markets.SockClient.handleDataReceived(Object sender, DataReceivedEventArgs e)
at WebSocket4Net.WebSocket.OnDataReceived(Byte[] data, Int32 offset, Int32 length)
at SuperSocket.ClientEngine.AuthenticatedStreamTcpSession.ReadAsync()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
at System.Threading.ThreadPoolWorkQueue.Dispatch()
Change DateTimeHelper class implementation and move all conditional logic into this class for more simple support and QuantConnect merging.
Fundamentals, Bars and Quotes are deprecated.
Appears the way that datetime parameters are getting added aren't working on the latest api. One example is GetBarSetAsync
The Alpaca docs state that dates should be formatted as '2019-04-15T09:30:00-04:00'
Currently it's passed in another format and ends up being ignored by the api.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.