{"id":18743058,"url":"https://github.com/kxsystems/csharpkdb","last_synced_at":"2025-04-12T21:23:14.771Z","repository":{"id":47584079,"uuid":"311345540","full_name":"KxSystems/csharpkdb","owner":"KxSystems","description":"Using C# with KDB+","archived":false,"fork":false,"pushed_at":"2025-03-25T13:53:43.000Z","size":323,"stargazers_count":12,"open_issues_count":4,"forks_count":13,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-12T03:14:12.525Z","etag":null,"topics":["csharp","dotnet","kdb"],"latest_commit_sha":null,"homepage":"https://code.kx.com/q","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KxSystems.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-09T13:22:22.000Z","updated_at":"2025-03-25T13:53:47.000Z","dependencies_parsed_at":"2024-12-03T14:35:18.976Z","dependency_job_id":"2bafae88-24cb-47d4-8ccf-83292c8c7773","html_url":"https://github.com/KxSystems/csharpkdb","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KxSystems%2Fcsharpkdb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KxSystems%2Fcsharpkdb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KxSystems%2Fcsharpkdb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KxSystems%2Fcsharpkdb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KxSystems","download_url":"https://codeload.github.com/KxSystems/csharpkdb/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248632879,"owners_count":21136770,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","dotnet","kdb"],"created_at":"2024-11-07T16:09:54.393Z","updated_at":"2025-04-12T21:23:14.761Z","avatar_url":"https://github.com/KxSystems.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# C# KDB\n\n[![Travis](https://img.shields.io/travis/com/kxsystems/csharpkdb/main)](https://travis-ci.com/github/KxSystems/csharpkdb) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=KxSystems_csharpkdb\u0026metric=coverage)](https://sonarcloud.io/dashboard?id=KxSystems_csharpkdb) \u003ca href=\"https://sonarcloud.io/dashboard?id=KxSystems_csharpkdb\"\u003e\u003cimg src=\"https://sonarcloud.io/images/project_badges/sonarcloud-white.svg\" width=\"125\"\u003e\u003c/a\u003e\n\n\n\n*The C# KDB library provides functionality for .NET applications to interface with a kdb+ process.*\n\nThe library is compiled on .NET Standard 2.0 and supports running applications on\n\n- .NET Core         2.0 - 3.1\n- .NET Framework    4.6.1 - 4.8\n\nSee https://dotnet.microsoft.com/platform/dotnet-standard for further details\n\n**Documentation** in :open_file_folder: [`docs`](docs)\n\n## Client integration\n\n### NuGet releases\n\nLatest release version can be downloaded from [NuGet](https://www.nuget.org/packages/CSharpKDB/).\n\nClient-applications can search and install \"CSharpKDB\" package either via \n\n- [Visual Studio](https://docs.microsoft.com/en-us/nuget/consume-packages/install-use-packages-visual-studio) \n\n- [Package Manager Console](https://docs.microsoft.com/en-us/nuget/consume-packages/install-use-packages-powershell)\n\nExample\n```powershell\n\nPM\u003e Find-Package CSharpKDB\n\nId                                  Versions                                 Description                                                                                  \n--                                  --------                                 -----------                                                                                  \nCSharpKDB                                                                    \"Provides functionality for .NET applications to interface with a kdb+ process.               \"\nTime Elapsed: 00:00:00.8274076\n\nPM\u003e Install-Package CSharpKDB\nRestoring packages for ...\nInstalling NuGet package CSharpKDB ....\n```\n\n\n\n## `c.cs`\n\nThe main entry point for client applications is the `kx.c.cs` class.\n\nExample:\n```csharp\n  public static void Main(string[]args)\n  {\n    //establish connection\n    c connection = null;    \n    try\n    {\n      connection = new c(\"localhost\", 5001);\n      connection.ReceiveTimeout = 1000;\n      connection.e = System.Text.Encoding.UTF8;\n\n      Console.WriteLine(\"Unicode \" + connection.k(\"`$\\\"c\\\"$0x52616e627920426ac3b6726b6c756e64204142\"));\n      \n      //insert some data-rows\n      object [] x = new object[]\n      { \n        DateTime.Now.TimeOfDay,\n        \"xx\",\n        (double)93.5,\n        300,\n      };\n\n      for (int i = 0; i \u003c 1000; ++i)\n      {\n        connection.k(\"insert\", \"trade\", x);\n      }\n\n      //read data\n      Flip result = c.td(connection.k(\"select sum price by sym from trade\"));\n      \n      Console.WriteLine(\"cols: \" + c.n(result.x));\n      Console.WriteLine(\"rows: \"+ c.n(result.y[0]));\n    }\n    finally\n    {\n      //finally close connection\n      connection.Close();\n    }\n  }\n\n```\n\n## Examples\n\nSupplied with the code is a series of code examples. The following describes each with an example of how to run from command prompt. Note minimum [.NET Core SDK and Runtime](https://dotnet.microsoft.com/download) should be installed.\n\n### QueryResponse demo\n\nInstructs the remote kdb+ process to execute q code (kdb+ native language) and receives the result. \nThe same principle can be used to execute q functions. Example of a sync request:\n\n#### Prerequisite\n\nA kdb+ server running on port 5001 on your machine i.e. `q -p 5001`\n\n#### Run commands\n``` bat\nREM Need to ensure nuget dependencies have been loaded\ndotnet restore .\\CSharpKdb.sln \n\nREM Build Release version of Demo application\ndotnet msbuild Demos\\QueryResponseDemo\\QueryResponseDemo.csproj /p:Configuration=\"Release\"\n\nREM Run demo application\ndotnet .\\Demos\\QueryResponseDemo\\bin\\Release\\netcoreapp3.1\\QueryResponseDemo.dll \n```\n\n### Serialization demo\n\nExample of code that can be used to serialize/dezerialize a C# type (array of ints) to kdb+ format. \n\n#### Prerequisite\n\nA kdb+ server running on port 5001 on your machine i.e. `q -p 5001`\n\n#### Run commands\n``` bat\nREM Need to ensure nuget dependencies have been loaded\ndotnet restore .\\CSharpKdb.sln \n\nREM Build Release version of Demo application\ndotnet msbuild Demos\\SerializationDemo\\SerializationDemo.csproj /p:Configuration=\"Release\"\n\nREM Run demo application\ndotnet .\\Demos\\SerializationDemo\\bin\\Release\\netcoreapp3.1\\SerializationDemo.dll \n```\n\n### Feed demo\n\nExample of creating an update function remotely (to capture table inserts), along with table creation and population of the table.\nTable population has an example of single row inserts (lower latency) and bulk inserts (better throughput and resource utilization).\n\n#### Prerequisite\n\nA kdb+ server running on port 5001 on your machine i.e. `q -p 5001`. \n\nThis example depends on a `.u.upd` function being defined and a table named `mytable` pre-existing, you may wish to run the following within the kdb+ server (in normal environments, these table and function definitions should be pre-created by your kdb+ admin). \n\n```q\nq).u.upd:{[tbl;row] insert[tbl](row)}\nq)mytable:([]time:`timespan$();sym:`symbol$();price:`float$();size:`long$())\n```\n\n#### Run commands\n``` bat\nREM Need to ensure nuget dependencies have been loaded\ndotnet restore .\\CSharpKdb.sln \n\nREM Build Release version of Demo application\ndotnet msbuild Demos\\FeedDemo\\FeedDemo.csproj /p:Configuration=\"Release\"\n\nREM Run demo application\ndotnet .\\Demos\\FeedDemo\\bin\\Release\\netcoreapp3.1\\FeedDemo.dll \n```\n\n### Subscriber demo\nExample app that subscribes to real-time updates from a table that is maintained in kdb+. \n\n#### Prerequisite\n\nA kdb+ server running on port 5001 on your machine. The instance must have the `.u.sub` function defined. An example of `.u.sub` can be found in [KxSystems/kdb-tick](https://github.com/KxSystems/kdb-tick), an example tickerplant. \n\nThis example will subscribe to updates to a table called 'mytable', filtering on the sym column for any updates using the symbol 'MSFT'.\n\nOnce the kdb-tick example is downloaded, create a file called `sym.q` in the `tick` folder with the following contents\n```\nmytable:([]time:`timespan$(); sym:`g#`symbol$(); price:`float$(); size:`int$(); side:`char$())\n```\n\n#### Run command\n\nCreate a kdb+ process which operates as a tickerplant by running `q tick.q -p 5001 -t 0` (listening on port 5001, with real-time updates).\n\nRun the C# subscriber example:\n\n``` bat\nREM Need to ensure nuget dependencies have been loaded\ndotnet restore .\\CSharpKdb.sln \n\nREM Build Release version of Demo application\ndotnet msbuild Demos\\SubscriberDemo\\SubscriberDemo.csproj /p:Configuration=\"Release\"\n\nREM Run demo application\ndotnet .\\Demos\\SubscriberDemo\\bin\\Release\\netcoreapp3.1\\SubscriberDemo.dll \n```\n\nOnce the subscriber has connected to the tickerplant, the following can be run in the tickerplant to see that a client has connected and subscribing to the relevant data\n```q\nq).u.w\nmytable| 8i `MSFT\n```\n\nRun the following in the tickerplant to emulate an application publishing data to the tickerplant, via its in-build .u.upd function. \n```q\nq).u.upd[`mytable;(.z.n;`MSFT;35.65;100;`B)]\n```\nAs this is data for the table 'mytable', subscribed clients matching the criteria will be informed in real-time. The C# client will therefore be notified of the data for processing or enrichment. \n\n## Change record\n\n- 2020-11-16 : Issue 2# : Reformat code\n- 2017-05-23 : Identify string[] as type 11\n- 2017-04-18 : Added ssl/tls support\n- 2014-01-29 : Make method n public\n- 2013-12-19 : qn did not detect null guid\n- 2013-12-10 : Remove retry logic on authentication fail. For kdb+2.5 and prior, \n\nUse \n```csharp\nB = new byte[1+u.Length];\nConnect(h,p);\ns=this.GetStream();\nJ=0;w(u);\ns.Write(B,0,J);\nif(1!=s.Read(B,0,1))...\n```\n\n- 2013.09.16 : za represents -0Wd, not 0Nd\n- 2013.08.20 : null val for TimeStamp -\u003e nj\n- 2012.06.07 : Fixed scoping of GUID \n- 2012.05.29 : For use with kdb+v3.0, changed handshake and added Guid. boolean v6-\u003evt tracks type capability.\n- 2012.01.26 : Refactored clamp into clampDT, for Date.DateTime()\n- 2012.01.25 : rz() clamp datetime to valid range\n- 2010.11.17 : Block sending new timetypes to version of kdb+ prior to v2.6 (use prior release of c.cs for older kdb+ versions)\n\nMax buffer size (default 64kB) used for reading is now a parameter to the c constructor Date, Month, Minute, Second, KTimeSpan are now serializable, implement IComparable and have default constructors for xml serialization.\n\nAdded NULL(Type t)\n\n- 2010/08.05 : Added KException for exceptions due to server error, authentication fail and func decode\n- 2010/01.14 : Exposed static var e (Encoding) as public\n- 2010/01.12 : Added support for unicode encoding, defaults to ASCII \n- 2010/01.11 : Added null checks for qn for UDTs Date,Month,Minute,Second,KTimespan\n- 2010/01.04 : Added new time types (timespan-\u003eKTimespan,timestamp-\u003eDateTime), drop writing kdb+ datetime\n- 2009/10.19 : Limit reads to blocks of 64kB to reduce load on kernel memory\n- 2007/09.26 : 0Wz to MaxValue\n- 2006/10.05 : Truncate string at null\n- 2006/09.29 : NULL  c.Date class(sync with c.java)\n\nSSL/TLS: To use self-signed certificates add them to the Local Computer Trusted Root Certification Authorities\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkxsystems%2Fcsharpkdb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkxsystems%2Fcsharpkdb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkxsystems%2Fcsharpkdb/lists"}