Skip to content

Commit

Permalink
other observer related merge fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveSkender committed Jan 3, 2024
1 parent af0251e commit e38bbad
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@
"Naming",
"CA1716:Identifiers should not match keywords",
Justification = "The microsoft OnError implementation uses reserved word Error",
Scope = "member", Target = "~M:Skender.Stock.Indicators.TupleObserver.OnError(System.Exception)")]
Scope = "member", Target = "~M:Skender.Stock.Indicators.TupleObserver.OnError(System.Exception)")]
4 changes: 2 additions & 2 deletions src/_common/Observables/ChainProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public abstract class ChainProvider
// initialize
protected ChainProvider()
{
observers = new();
ProtectedChain = new();
observers = [];
ProtectedChain = [];
Warmup = true;
}

Expand Down
4 changes: 2 additions & 2 deletions src/_common/Observables/QuoteProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public class QuoteProvider : IObservable<Quote>
// initialize
public QuoteProvider()
{
observers = new();
ProtectedQuotes = new();
observers = [];
ProtectedQuotes = [];
}

// properties
Expand Down
4 changes: 2 additions & 2 deletions src/_common/Observables/TupleProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public abstract class TupleProvider
// initialize
protected TupleProvider()
{
observers = new();
ProtectedTuples = new();
observers = [];
ProtectedTuples = [];
}

// properties
Expand Down
2 changes: 1 addition & 1 deletion src/e-k/Ema/Ema.Observer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public EmaObserver(
int lookbackPeriods)
{
Supplier = provider;
ProtectedResults = new();
ProtectedResults = [];

LookbackPeriods = lookbackPeriods;
K = 2d / (lookbackPeriods + 1);
Expand Down
9 changes: 2 additions & 7 deletions src/s-z/Sma/Sma.Observer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public SmaObserver(
int lookbackPeriods)
{
Supplier = provider;
ProtectedResults = new();
ProtectedResults = [];

LookbackPeriods = lookbackPeriods;

Expand Down Expand Up @@ -65,17 +65,12 @@ internal static double Increment(
// add new tuple quote
internal void Add((DateTime Date, double Value) tp)
{
if (Supplier == null)
{
throw new ArgumentNullException(nameof(Supplier), "Could not find data source.");
}

// candidate result
SmaResult r = new(tp.Date);

// initialize
int lengthRes = ProtectedResults.Count;
int lengthSrc = Supplier.ProtectedTuples.Count;
int lengthSrc = Supplier!.ProtectedTuples.Count; // merge fix, okay to replace

// handle first value
if (lengthRes == 0)
Expand Down
10 changes: 4 additions & 6 deletions tests/observe/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal class Program
{
private static async Task Main(string[] args)
{
if (args.Any())
if (args.Length != 0)
{
Console.WriteLine(args);
}
Expand Down Expand Up @@ -56,10 +56,8 @@ IAlpacaCryptoStreamingClient client

await client.ConnectAndAuthenticateAsync();

AutoResetEvent[] waitObjects = new[] // todo: is this needed?
{
new AutoResetEvent(false)
};
// todo: is this needed?
AutoResetEvent[] waitObjects = [new AutoResetEvent(false)];

IAlpacaDataSubscription<IBar> quoteSubscription
= client.GetMinuteBarSubscription(symbol);
Expand Down Expand Up @@ -114,4 +112,4 @@ IAlpacaDataSubscription<IBar> quoteSubscription
Console.WriteLine($"{symbol} {s.Date:s} ${s.Sma:N2}");
}
}
}
}

0 comments on commit e38bbad

Please sign in to comment.