Files
John Colvin 5163ca4cae refactor: Organize libspark proj w/ stuttering include
This new structure provides several benefits:

* Allows us to install multiple CMake projects in the same destination
  dir (without include path conflicts).
  - This makes shipping the trading algo sdk a trivial excercise. Simply
    copy the lib and include dirs from the install dest. That's it!
* Puts us in a position to break up the monolithic libspark into smaller
  modules, which are easier to manage.

Windows specific notes:

* Get rid of unnecessary script vs_filters.cmake
* Define WebsocketConnectionGateway directly in cs (instead of proto)
  - The proto would no longer be in the include path passed to protoc.
    Moving it to c# because there wasn't a compelling reason for it to
    be a proto in the first place.
* Set spark output prefix to "lib" on windows
  - So we get "libspark.dll" instead of "spark.dll", which conflicts
    with the csharp lib, "Spark.dll".
* Copy libspark.dll to net8.0 & net8.0-windows in a single cmake build
  target

fix build: Copy libspark to both dirs net8.0, net8.0-windows
2025-06-16 11:08:53 -04:00

1.3 KiB

+++ title = "Market Data" +++

Use the MarketDataService to subscribe enumerate all available securities.

using System;
using System.Threading;
using bts.api;
using bts.api.core;

namespace sample {
   class Program {
      static void Main(string[] args) {
         using var context = new ServiceContext();
         var md = context.locate<MarketDataService>();
         using var sub = md.subscribe_securities().Subscribe(update => {
            foreach (var security in update.added) {
               Console.WriteLine($"Added security {security.Id}: {security.Symbol}");
            }
         });

         Thread.Sleep(TimeSpan.FromMinutes(5));
      }
   }
}
#include "spark/api/public/ServiceContext.h"
#include "spark/domain_model/Security.h"
#include "spark/api/services/MarketDataService.client.pb.h"
#include <thread>

using namespace bts::api;

int main(int argc, char** argv) {
   ServiceContext ctx;
   auto md_service = ctx.locate<bts::api::MarketDataService>();
   auto sub = md_service.subscribe_securities().subscribe([](const auto& update) {
      for (const auto& s : update.added()) {
         std::cout << "Added security: " << s->id() << ": " << s->symbol() << std::endl;
      }
   });

   std::this_thread::sleep_for(std::chrono::minutes(5));
   return 0;
}