diff --git a/docker/linux b/docker/linux index 95918627c..735b68832 160000 --- a/docker/linux +++ b/docker/linux @@ -1 +1 @@ -Subproject commit 95918627ce8493c90c0337d47427e77161ead7d0 +Subproject commit 735b68832737b750201b677211e3c2b200808fee diff --git a/externals b/externals index 9dd9d7a5d..445b75b8c 160000 --- a/externals +++ b/externals @@ -1 +1 @@ -Subproject commit 9dd9d7a5dd6d751fb58ae240eaac6d8cbb8f0b25 +Subproject commit 445b75b8cca5b492580a802ade8d85457f998ffa diff --git a/spark_client.sln b/spark_client.sln index 644cf1a65..861cc23c7 100644 --- a/spark_client.sln +++ b/spark_client.sln @@ -1,10 +1,10 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.27004.2005 +VisualStudioVersion = 15.0.27130.2024 MinimumVisualStudioVersion = 15.0.26124.0 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "spark_api", "src\client\spark_api\spark_api.csproj", "{DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "spark_lib", "build\src\lib\spark_lib.vcxproj", "{9186D3A8-1C5C-372A-A4EE-E1045BCCB0C7}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "spark_lib", "build\src\lib\spark_lib.vcxproj", "{502FD050-679A-3B50-B438-098500700919}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Spark", "src\client\spark\Spark.csproj", "{9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}" EndProject @@ -12,12 +12,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "sparkcmd", "src\client\spar EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "spark_core", "src\client\spark_core\spark_core.csproj", "{6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ZERO_CHECK", "build\ZERO_CHECK.vcxproj", "{33E7E6C5-04E3-36A8-A751-639BE5E72B9B}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ZERO_CHECK", "build\ZERO_CHECK.vcxproj", "{2256015B-E7D5-3614-8F39-814CA68A4444}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "spark_sdk", "src\client\spark_sdk\spark_sdk.csproj", "{6963C314-83C4-4667-B0D0-C2F7AE208C29}" + ProjectSection(ProjectDependencies) = postProject + {502FD050-679A-3B50-B438-098500700919} = {502FD050-679A-3B50-B438-098500700919} + EndProjectSection EndProject Global - GlobalSection(Performance) = preSolution - HasPerformanceSessions = true - EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Debug|x64 = Debug|x64 @@ -53,22 +55,22 @@ Global {DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.RelWithDebInfo|x64.Build.0 = Release|x64 {DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.RelWithDebInfo|x86.ActiveCfg = Release|x64 {DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.RelWithDebInfo|x86.Build.0 = Release|x64 - {9186D3A8-1C5C-372A-A4EE-E1045BCCB0C7}.Debug|Any CPU.ActiveCfg = Debug|x64 - {9186D3A8-1C5C-372A-A4EE-E1045BCCB0C7}.Debug|x64.ActiveCfg = Debug|x64 - {9186D3A8-1C5C-372A-A4EE-E1045BCCB0C7}.Debug|x64.Build.0 = Debug|x64 - {9186D3A8-1C5C-372A-A4EE-E1045BCCB0C7}.Debug|x86.ActiveCfg = Debug|x64 - {9186D3A8-1C5C-372A-A4EE-E1045BCCB0C7}.MinSizeRel|Any CPU.ActiveCfg = MinSizeRel|x64 - {9186D3A8-1C5C-372A-A4EE-E1045BCCB0C7}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64 - {9186D3A8-1C5C-372A-A4EE-E1045BCCB0C7}.MinSizeRel|x64.Build.0 = MinSizeRel|x64 - {9186D3A8-1C5C-372A-A4EE-E1045BCCB0C7}.MinSizeRel|x86.ActiveCfg = MinSizeRel|x64 - {9186D3A8-1C5C-372A-A4EE-E1045BCCB0C7}.Release|Any CPU.ActiveCfg = Release|x64 - {9186D3A8-1C5C-372A-A4EE-E1045BCCB0C7}.Release|x64.ActiveCfg = Release|x64 - {9186D3A8-1C5C-372A-A4EE-E1045BCCB0C7}.Release|x64.Build.0 = Release|x64 - {9186D3A8-1C5C-372A-A4EE-E1045BCCB0C7}.Release|x86.ActiveCfg = Release|x64 - {9186D3A8-1C5C-372A-A4EE-E1045BCCB0C7}.RelWithDebInfo|Any CPU.ActiveCfg = RelWithDebInfo|x64 - {9186D3A8-1C5C-372A-A4EE-E1045BCCB0C7}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64 - {9186D3A8-1C5C-372A-A4EE-E1045BCCB0C7}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64 - {9186D3A8-1C5C-372A-A4EE-E1045BCCB0C7}.RelWithDebInfo|x86.ActiveCfg = RelWithDebInfo|x64 + {502FD050-679A-3B50-B438-098500700919}.Debug|Any CPU.ActiveCfg = Debug|x64 + {502FD050-679A-3B50-B438-098500700919}.Debug|x64.ActiveCfg = Debug|x64 + {502FD050-679A-3B50-B438-098500700919}.Debug|x64.Build.0 = Debug|x64 + {502FD050-679A-3B50-B438-098500700919}.Debug|x86.ActiveCfg = Debug|x64 + {502FD050-679A-3B50-B438-098500700919}.MinSizeRel|Any CPU.ActiveCfg = MinSizeRel|x64 + {502FD050-679A-3B50-B438-098500700919}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64 + {502FD050-679A-3B50-B438-098500700919}.MinSizeRel|x64.Build.0 = MinSizeRel|x64 + {502FD050-679A-3B50-B438-098500700919}.MinSizeRel|x86.ActiveCfg = MinSizeRel|x64 + {502FD050-679A-3B50-B438-098500700919}.Release|Any CPU.ActiveCfg = Release|x64 + {502FD050-679A-3B50-B438-098500700919}.Release|x64.ActiveCfg = Release|x64 + {502FD050-679A-3B50-B438-098500700919}.Release|x64.Build.0 = Release|x64 + {502FD050-679A-3B50-B438-098500700919}.Release|x86.ActiveCfg = Release|x64 + {502FD050-679A-3B50-B438-098500700919}.RelWithDebInfo|Any CPU.ActiveCfg = RelWithDebInfo|x64 + {502FD050-679A-3B50-B438-098500700919}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64 + {502FD050-679A-3B50-B438-098500700919}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64 + {502FD050-679A-3B50-B438-098500700919}.RelWithDebInfo|x86.ActiveCfg = RelWithDebInfo|x64 {9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.Debug|Any CPU.ActiveCfg = Debug|x64 {9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.Debug|x64.ActiveCfg = Debug|x64 {9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.Debug|x64.Build.0 = Debug|x64 @@ -129,22 +131,42 @@ Global {6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.RelWithDebInfo|x64.Build.0 = Release|x64 {6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.RelWithDebInfo|x86.ActiveCfg = Release|x64 {6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.RelWithDebInfo|x86.Build.0 = Release|x64 - {33E7E6C5-04E3-36A8-A751-639BE5E72B9B}.Debug|Any CPU.ActiveCfg = Debug|x64 - {33E7E6C5-04E3-36A8-A751-639BE5E72B9B}.Debug|x64.ActiveCfg = Debug|x64 - {33E7E6C5-04E3-36A8-A751-639BE5E72B9B}.Debug|x64.Build.0 = Debug|x64 - {33E7E6C5-04E3-36A8-A751-639BE5E72B9B}.Debug|x86.ActiveCfg = Debug|x64 - {33E7E6C5-04E3-36A8-A751-639BE5E72B9B}.MinSizeRel|Any CPU.ActiveCfg = MinSizeRel|x64 - {33E7E6C5-04E3-36A8-A751-639BE5E72B9B}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64 - {33E7E6C5-04E3-36A8-A751-639BE5E72B9B}.MinSizeRel|x64.Build.0 = MinSizeRel|x64 - {33E7E6C5-04E3-36A8-A751-639BE5E72B9B}.MinSizeRel|x86.ActiveCfg = MinSizeRel|x64 - {33E7E6C5-04E3-36A8-A751-639BE5E72B9B}.Release|Any CPU.ActiveCfg = Release|x64 - {33E7E6C5-04E3-36A8-A751-639BE5E72B9B}.Release|x64.ActiveCfg = Release|x64 - {33E7E6C5-04E3-36A8-A751-639BE5E72B9B}.Release|x64.Build.0 = Release|x64 - {33E7E6C5-04E3-36A8-A751-639BE5E72B9B}.Release|x86.ActiveCfg = Release|x64 - {33E7E6C5-04E3-36A8-A751-639BE5E72B9B}.RelWithDebInfo|Any CPU.ActiveCfg = RelWithDebInfo|x64 - {33E7E6C5-04E3-36A8-A751-639BE5E72B9B}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64 - {33E7E6C5-04E3-36A8-A751-639BE5E72B9B}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64 - {33E7E6C5-04E3-36A8-A751-639BE5E72B9B}.RelWithDebInfo|x86.ActiveCfg = RelWithDebInfo|x64 + {2256015B-E7D5-3614-8F39-814CA68A4444}.Debug|Any CPU.ActiveCfg = Debug|x64 + {2256015B-E7D5-3614-8F39-814CA68A4444}.Debug|x64.ActiveCfg = Debug|x64 + {2256015B-E7D5-3614-8F39-814CA68A4444}.Debug|x64.Build.0 = Debug|x64 + {2256015B-E7D5-3614-8F39-814CA68A4444}.Debug|x86.ActiveCfg = Debug|x64 + {2256015B-E7D5-3614-8F39-814CA68A4444}.MinSizeRel|Any CPU.ActiveCfg = MinSizeRel|x64 + {2256015B-E7D5-3614-8F39-814CA68A4444}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64 + {2256015B-E7D5-3614-8F39-814CA68A4444}.MinSizeRel|x64.Build.0 = MinSizeRel|x64 + {2256015B-E7D5-3614-8F39-814CA68A4444}.MinSizeRel|x86.ActiveCfg = MinSizeRel|x64 + {2256015B-E7D5-3614-8F39-814CA68A4444}.Release|Any CPU.ActiveCfg = Release|x64 + {2256015B-E7D5-3614-8F39-814CA68A4444}.Release|x64.ActiveCfg = Release|x64 + {2256015B-E7D5-3614-8F39-814CA68A4444}.Release|x64.Build.0 = Release|x64 + {2256015B-E7D5-3614-8F39-814CA68A4444}.Release|x86.ActiveCfg = Release|x64 + {2256015B-E7D5-3614-8F39-814CA68A4444}.RelWithDebInfo|Any CPU.ActiveCfg = RelWithDebInfo|x64 + {2256015B-E7D5-3614-8F39-814CA68A4444}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64 + {2256015B-E7D5-3614-8F39-814CA68A4444}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64 + {2256015B-E7D5-3614-8F39-814CA68A4444}.RelWithDebInfo|x86.ActiveCfg = RelWithDebInfo|x64 + {6963C314-83C4-4667-B0D0-C2F7AE208C29}.Debug|Any CPU.ActiveCfg = Debug|x64 + {6963C314-83C4-4667-B0D0-C2F7AE208C29}.Debug|x64.ActiveCfg = Debug|x64 + {6963C314-83C4-4667-B0D0-C2F7AE208C29}.Debug|x64.Build.0 = Debug|x64 + {6963C314-83C4-4667-B0D0-C2F7AE208C29}.Debug|x86.ActiveCfg = Debug|x64 + {6963C314-83C4-4667-B0D0-C2F7AE208C29}.MinSizeRel|Any CPU.ActiveCfg = Release|x64 + {6963C314-83C4-4667-B0D0-C2F7AE208C29}.MinSizeRel|Any CPU.Build.0 = Release|x64 + {6963C314-83C4-4667-B0D0-C2F7AE208C29}.MinSizeRel|x64.ActiveCfg = Release|x64 + {6963C314-83C4-4667-B0D0-C2F7AE208C29}.MinSizeRel|x64.Build.0 = Release|x64 + {6963C314-83C4-4667-B0D0-C2F7AE208C29}.MinSizeRel|x86.ActiveCfg = Release|x64 + {6963C314-83C4-4667-B0D0-C2F7AE208C29}.MinSizeRel|x86.Build.0 = Release|x64 + {6963C314-83C4-4667-B0D0-C2F7AE208C29}.Release|Any CPU.ActiveCfg = Release|x64 + {6963C314-83C4-4667-B0D0-C2F7AE208C29}.Release|x64.ActiveCfg = Release|x64 + {6963C314-83C4-4667-B0D0-C2F7AE208C29}.Release|x64.Build.0 = Release|x64 + {6963C314-83C4-4667-B0D0-C2F7AE208C29}.Release|x86.ActiveCfg = Release|x64 + {6963C314-83C4-4667-B0D0-C2F7AE208C29}.RelWithDebInfo|Any CPU.ActiveCfg = Release|x64 + {6963C314-83C4-4667-B0D0-C2F7AE208C29}.RelWithDebInfo|Any CPU.Build.0 = Release|x64 + {6963C314-83C4-4667-B0D0-C2F7AE208C29}.RelWithDebInfo|x64.ActiveCfg = Release|x64 + {6963C314-83C4-4667-B0D0-C2F7AE208C29}.RelWithDebInfo|x64.Build.0 = Release|x64 + {6963C314-83C4-4667-B0D0-C2F7AE208C29}.RelWithDebInfo|x86.ActiveCfg = Release|x64 + {6963C314-83C4-4667-B0D0-C2F7AE208C29}.RelWithDebInfo|x86.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -152,4 +174,7 @@ Global GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {422D1620-0166-4C26-9A81-CA8A2EB1AB58} EndGlobalSection + GlobalSection(Performance) = preSolution + HasPerformanceSessions = true + EndGlobalSection EndGlobal diff --git a/src/client/spark/Spark.csproj b/src/client/spark/Spark.csproj index 6019d857a..ac69b632a 100644 --- a/src/client/spark/Spark.csproj +++ b/src/client/spark/Spark.csproj @@ -17,7 +17,8 @@ bts 7.1 true - + + 1.0.0 diff --git a/src/client/spark/view/Spark/Ladder/RecenterCountdown.cs b/src/client/spark/view/Spark/Ladder/RecenterCountdown.cs index 54903e305..78d1e1aff 100644 --- a/src/client/spark/view/Spark/Ladder/RecenterCountdown.cs +++ b/src/client/spark/view/Spark/Ladder/RecenterCountdown.cs @@ -37,7 +37,7 @@ namespace mbts.spark { if (_settings != null && _security != null) { var mid = _handle.mid(); (double low, double high) = tick_range(_last_mid, _settings.ticks_to_recenter, _security.Value.ContractSpec); - if (mid < low || mid > high || + if (//mid < low || mid > high || (_last_recenter + TimeSpan.FromSeconds(_settings.seconds_to_recenter) < DateTime.UtcNow)) { trigger_recenter(mid); } diff --git a/src/client/spark_api/security/Security.cs b/src/client/spark_api/security/Security.cs index 02a194374..f239b8f32 100644 --- a/src/client/spark_api/security/Security.cs +++ b/src/client/spark_api/security/Security.cs @@ -17,7 +17,7 @@ namespace bts.api { public string ToString(string format, IFormatProvider formatProvider=null) => Format(this, string.IsNullOrEmpty(format) ? _standard_format : Parse(format)); - public static security_key key(Security s) { return s.Id; } + public static security_key key(Security s) { return s.Id; } } partial struct SecurityImmutable : IComparable, IComparable { diff --git a/src/client/spark_api/security/SecurityExtensions.cs b/src/client/spark_api/security/SecurityExtensions.cs new file mode 100644 index 000000000..910cefa13 --- /dev/null +++ b/src/client/spark_api/security/SecurityExtensions.cs @@ -0,0 +1,10 @@ +using System; +using bts.api; + +namespace bts.api +{ + public static class SecurityExtensions + { + public static SecurityType security_type(this Security s) { return ((SecurityImmutable)s).security_type(); } + } +} \ No newline at end of file diff --git a/src/client/spark_api/spark_api.csproj b/src/client/spark_api/spark_api.csproj index b6e63e137..57fe9e5c9 100644 --- a/src/client/spark_api/spark_api.csproj +++ b/src/client/spark_api/spark_api.csproj @@ -1,7 +1,6 @@ netstandard2.0 - true Blue Trading Systems Blue Trading Systems Spark @@ -11,6 +10,7 @@ AnyCPU true + 1.0.0 @@ -22,7 +22,8 @@ - + + diff --git a/src/client/spark_core/spark_core.csproj b/src/client/spark_core/spark_core.csproj index 4f70a77f5..c0afb60fb 100644 --- a/src/client/spark_core/spark_core.csproj +++ b/src/client/spark_core/spark_core.csproj @@ -7,6 +7,7 @@ AnyCPU true + 1.0.0 @@ -17,12 +18,11 @@ - - - + + diff --git a/src/client/spark_sdk/Properties/AssemblyAttributes.cs b/src/client/spark_sdk/Properties/AssemblyAttributes.cs new file mode 100644 index 000000000..116424f20 --- /dev/null +++ b/src/client/spark_sdk/Properties/AssemblyAttributes.cs @@ -0,0 +1,2 @@ +using System.Runtime.CompilerServices; + diff --git a/src/client/spark_sdk/samples/Main.cs b/src/client/spark_sdk/samples/Main.cs new file mode 100644 index 000000000..8e2376232 --- /dev/null +++ b/src/client/spark_sdk/samples/Main.cs @@ -0,0 +1,121 @@ +using System; +using System.Linq; +using System.Threading.Tasks; + +using bts.api; +using bts.api.core; + +namespace bts.sdk +{ + + public class MainClass + { + public static void Main(string[] args) + { + MarketDataClient client = new MarketDataClient(); + if (args.FirstOrDefault() == "ui") + { + if (args.Length >= 5) + { + using (var ui = new ui.UISample(client)) + { + ui.simple_price_ui(args[1], args[2], args[3], args[4]); + } + } + else + ui_help(); + } + else + { + MarketDataSample s = new MarketDataSample(client); + if (args.FirstOrDefault() == "md") + { + if (args.Length >= 4) + { + s.print_channel(args[1], args[2], args[3]); + } + else + md_help(); + } + else if (args.FirstOrDefault() == "md_threaded") + { + if (args.Length >= 4) + { + s.print_channel(args[1], args[2], args[3], + System.Reactive.Concurrency.Scheduler.Default); + } + else + md_help(); + } + else + { + help(); + } + + int ms = 10; + string p = args.FirstOrDefault(x => x.Contains("--pump=")); + if (p != null) + ms = int.Parse(p.Replace("--pump=", string.Empty)); + client.start_pump(TimeSpan.FromMilliseconds(ms)) + .ContinueWith(ex => Console.WriteLine(ex.ToString()), TaskContinuationOptions.OnlyOnFaulted); + wait_for_stop(client); + } + } + + static void wait_for_stop(MarketDataClient client) + { + Console.WriteLine("Hit q to stop"); + ConsoleKeyInfo c; + do + { + c = Console.ReadKey(); + Console.WriteLine(); + } while (c.KeyChar != 'q'); + client.Dispose(); + } + + static void help() + { + Console.WriteLine("BTS Spark SDK"); + Console.WriteLine("Usages: spark_sdk [command] [arguments]"); + Console.WriteLine(); + Console.WriteLine("Commands:"); + Console.WriteLine(" md "); + Console.WriteLine(" md_threaded "); + Console.WriteLine(" ui"); + Console.WriteLine(" orders"); + Console.WriteLine("Arguments:"); + Console.WriteLine(" --pump="); + Environment.Exit(1); + } + + static void md_help() + { + Console.WriteLine("md "); + Console.WriteLine("This command subscribes to market data for an exchange-type-symbol channel and writes to console."); + Console.WriteLine("Marketdata is read off the wire on the same thread as is used to read and print"); + Console.WriteLine(" example: ui GLBX Future ES 12/21/2018"); + Console.WriteLine(" ui GLBX Spread ES 12/21/2018"); + Environment.Exit(1); + } + + static void md_threaded_help() + { + Console.WriteLine("md_threaded "); + Console.WriteLine("This command subscribes to market data for an exchange-type-symbol channel and writes to console."); + Console.WriteLine("Marketdata is read off the wire on one thread and read and printed on another through IScheduler"); + Console.WriteLine(" example: md_threaded GLBX Future ES"); + Console.WriteLine(" md_threaded GLBX Spread ES"); + Environment.Exit(1); + } + + static void ui_help() + { + Console.WriteLine("ui "); + Console.WriteLine("This command subscribes to market data for a specific security and writes to a UI on a specified refresh interval (in ms)."); + Console.WriteLine("Marketdata is read off the wire on one thread and posted to the GUI on another through Observable.Timer()"); + Console.WriteLine(" example: ui GLBX Future ES 12/21/2018 25"); + Environment.Exit(1); + } + } +} diff --git a/src/client/spark_sdk/samples/MarketDataClient.cs b/src/client/spark_sdk/samples/MarketDataClient.cs new file mode 100644 index 000000000..28b1258c1 --- /dev/null +++ b/src/client/spark_sdk/samples/MarketDataClient.cs @@ -0,0 +1,163 @@ +using System; +using System.Linq; +using System.Collections.Generic; +using System.Collections.Concurrent; +using System.Threading; +using System.Threading.Tasks; +using System.Reactive.Linq; +using System.Reactive.Concurrency; +using System.Reactive.Subjects; + +using bts.api; +using bts.api.core; +using bts.co2; + +namespace bts.sdk +{ + using SecurityChannelKey = System.Tuple; + using security_key = System.UInt32; + + public class MarketDataClient : IDisposable + { + readonly ConcurrentDictionary> _replies = + new ConcurrentDictionary>(); + readonly List _disps = new List(); + readonly ConcurrentDictionary _data = new ConcurrentDictionary(); + readonly CancellationTokenSource _cts = new CancellationTokenSource(); + + readonly Lazy _md = new Lazy( () => locate(), true); + public MarketDataClient() + { + } + + static MarketDataRelay locate() + { + using (var ctx = new api.core.ServiceContext()) + { + //locate the service using the ServiceContext and cache it. + //this represents a connection to the server, so we don't want more than one of these instances per application, if we can avoid it + return ctx.locate(); + } + } + + /// + /// Subscribe to a data channel. This callback comes on the pump thread, you don't want to hold this up + /// + /// + /// + /// + /// + public IObservable subscribe(Venue exchange, api.SecurityType sectype, string symbol) + { + var key = Tuple.Create(exchange, sectype, symbol); + SecurityChannel channel = new SecurityChannel() + { + Exchange = exchange, + Type = sectype, + Symbol = symbol, + Flags = (System.UInt32) (MDRequest.Types.Flags.Security | MDRequest.Types.Flags.Bbo | MDRequest.Types.Flags.Depth), + }; + ChannelReply initial = new ChannelReply() { Channel = channel }; + var sub = new BehaviorSubject(initial); + _replies[key] = sub; + return sub; + } + + /// + /// Subscribe to a data channel. This callback comes on the scheduler thread, so you don't have to worry about holding up the pump + /// + /// + /// + /// + /// + /// + public IObservable subscribe(Venue exchange, api.SecurityType sectype, string symbol, IScheduler scheduler) + { + if(scheduler == null) + return subscribe(exchange, sectype, symbol); + else + return subscribe(exchange, sectype, symbol).ObserveOn(scheduler); + } + + IObservable timer_observable(TimeSpan interval, IScheduler scheduler = null) + { + IObservable timer; + if (scheduler != null) + timer = Observable.Timer(interval, scheduler); + else + timer = Observable.Timer(interval); + return timer; + } + + + /// + /// Subscribe to updates for a single security on a specified update_interval + /// + /// + /// + /// + public IObservable subscribe(Security security, TimeSpan update_interval) + { + return subscribe(security, update_interval, null); + } + + /// + /// Subscribe to updates for a single security on a specified update_interval, on the specified scheduler + /// + /// + /// + /// + /// + public IObservable subscribe(Security security, TimeSpan update_interval, IScheduler scheduler) + { + var timer = timer_observable(update_interval, scheduler); + return timer.Select(x => + { + ChannelUpdate update; + var key = Security.key(security); + if (_data.TryGetValue(key, out update)) + return update; + else + return new ChannelUpdate() { Key = key, Security = security }; + }); + } + + /// + /// Start pumping market data for all subscribed channels and securities. Call this without await + /// + /// + /// + public async Task start_pump(TimeSpan interval) + { + while (true) + { + MDRequest req = new MDRequest(); + req.Channels.AddRange(_replies.Values.Select(x => x.Value.Channel)); + var reply = await _md.Value.requestmd_async(req); + if (reply.success) + { + foreach (var channel in reply.value.Channels) + { + BehaviorSubject rep; + if (_replies.TryGetValue(Tuple.Create(channel.Channel.Exchange, channel.Channel.Type, channel.Channel.Symbol), out rep)) + { + rep.OnNext(channel); + foreach (var update in channel.Updates) + _data[update.Key] = update; + } + } + } + await Task.Delay(interval, _cts.Token); + } + } + + public void Dispose() + { + _cts.Cancel(); + _cts.Dispose(); + _disps.ForEach(x => x.Dispose()); + if(_md.IsValueCreated) + _md.Value.Dispose(); + } + } +} diff --git a/src/client/spark_sdk/samples/MarketDataSample.cs b/src/client/spark_sdk/samples/MarketDataSample.cs new file mode 100644 index 000000000..1e3f2b0a4 --- /dev/null +++ b/src/client/spark_sdk/samples/MarketDataSample.cs @@ -0,0 +1,53 @@ +using System; +using System.Linq; +using System.Collections.Generic; +using System.Collections.Concurrent; +using System.Threading; +using System.Threading.Tasks; +using System.Reactive.Linq; +using System.Reactive.Concurrency; +using System.Reactive.Subjects; + +using bts.api; +using bts.api.core; +using bts.co2; + +namespace bts.sdk +{ + + public class MarketDataSample : IDisposable + { + readonly MarketDataClient _md; + public MarketDataSample(MarketDataClient client) + { + _md = client; + } + + void print_update(ChannelUpdate update) + { + Console.WriteLine(update.ToString()); + Console.WriteLine(); + } + + public void print_channel(string exch, string sectype, string symbol, IScheduler scheduler = null) + { + Venue ven; + if(!Enum.TryParse(exch.ToUpper(), true, out ven)) + ven = (Venue)Enum.Parse(typeof(Venue), "VENUE_" + exch.ToUpper()); + + SecurityType st; + if (!Enum.TryParse(sectype.ToUpper(), true, out st)) + st = (SecurityType)Enum.Parse(typeof(SecurityType), "SECURITY_TYPE" + sectype.ToUpper()); + _md.subscribe(ven, st, symbol.ToUpper(), scheduler).Subscribe(x => + { + foreach(var xx in x.Updates) + print_update(xx); + }); + } + + public void Dispose() + { + _md.Dispose(); + } + } +} diff --git a/src/client/spark_sdk/samples/UISample.cs b/src/client/spark_sdk/samples/UISample.cs new file mode 100644 index 000000000..e92df3336 --- /dev/null +++ b/src/client/spark_sdk/samples/UISample.cs @@ -0,0 +1,31 @@ +using System; +using System.Linq; + +namespace bts.sdk.ui +{ + public class UISample : IDisposable + { + readonly MarketDataClient _md; + public UISample(MarketDataClient client) + { + _md = client; + } + + public void simple_price_ui(string exch, string sectype, string symbol, string expiration) + { +#if NET471 + System.Windows.Forms.Application.EnableVisualStyles(); + System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false); + System.Windows.Forms.Application.Run(new SparkSDKUI()); +#endif + } + + public void Dispose() + { +#if NET471 + System.Windows.Forms.Application.Exit(); +#endif + } + } +} + diff --git a/src/client/spark_sdk/spark_sdk.csproj b/src/client/spark_sdk/spark_sdk.csproj new file mode 100644 index 000000000..1e633e21e --- /dev/null +++ b/src/client/spark_sdk/spark_sdk.csproj @@ -0,0 +1,56 @@ + + + + netstandard2.0;net471 + Exe + true + true + true + $(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage + + Blue Trading Systems + Blue Trading Systems + Spark + + true + x64 + AnyCPU + true + + 1.0.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/client/spark_sdk/uisamples/SparkSDKUI.Designer.cs b/src/client/spark_sdk/uisamples/SparkSDKUI.Designer.cs new file mode 100644 index 000000000..31a43842f --- /dev/null +++ b/src/client/spark_sdk/uisamples/SparkSDKUI.Designer.cs @@ -0,0 +1,45 @@ +#if NET471 + +namespace bts.sdk.ui +{ + partial class SparkSDKUI + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if(disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + +#region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Text = "SparkSDKUI"; + } + +#endregion + } +} + + + + +#endif \ No newline at end of file diff --git a/src/client/spark_sdk/uisamples/SparkSDKUI.cs b/src/client/spark_sdk/uisamples/SparkSDKUI.cs new file mode 100644 index 000000000..162e4ee7c --- /dev/null +++ b/src/client/spark_sdk/uisamples/SparkSDKUI.cs @@ -0,0 +1,27 @@ +#if NET471 + +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace bts.sdk.ui +{ + public partial class SparkSDKUI : Form + { + public SparkSDKUI() + { + InitializeComponent(); + } + } +} + + + + +#endif \ No newline at end of file diff --git a/src/client/sparkcmd/sparkcmd.csproj b/src/client/sparkcmd/sparkcmd.csproj index 56d713a66..ffab95cda 100644 --- a/src/client/sparkcmd/sparkcmd.csproj +++ b/src/client/sparkcmd/sparkcmd.csproj @@ -9,6 +9,7 @@ Spark x64 AnyCPU + 1.0.0