Skip to content

Instantly share code, notes, and snippets.

View Swoorup's full-sized avatar

Swoorup Joshi Swoorup

View GitHub Profile
Swoorup /
Created January 29, 2024 08:39
use std::ops::Range;
use log::warn;
use wgpu::naga::{FastIndexMap, FastIndexSet};
#[derive(Debug, PartialOrd, Hash, PartialEq, Eq, Clone)]
pub struct DirtyIndexRange {
start: usize,
until: usize,
Swoorup / TaskValidation.fs
Created June 15, 2023 05:31
Task Validation CE with FsToolkit.ErrorHandling
open System.Threading.Tasks
open FsToolkit.ErrorHandling
open FsToolkit.ErrorHandling.Operator.Validation
type TaskValidation<'a, 'err> = Task<Validation<'a, 'err>>
module TaskValidation =
let inline map f (tv: TaskValidation<'a, 'err>) : TaskValidation<'b, 'err> = f tv
let inline bind (f: 'a -> TaskValidation<'b, 'err>) (tv: TaskValidation<'a, 'err>) : TaskValidation<'b, 'err> = TaskResult.bind f tv
Swoorup / ViperAppDemo.tsx
Last active March 1, 2023 16:27
Viper charts demo
import { useEffect, useRef } from 'react';
import './App.css';
import { DataUpdates, HistoricalDataRequest, Price, UTCTimestamp, Viper as ViperCharts } from "@viper-charts/viper-charts";
// import "@viper-charts/viper-charts/dist/style.css";
import { ViperDatabase } from "./ViperDatabase";
const db = createDB();
function onSaveViperSettings(settings: any) {
Swoorup / Makefile.toml
Created December 19, 2022 09:49
duckdb shared library helper for cargo-make
# skip_core_tasks = true
# skip_git_env_info = true
# skip_crate_env_info = true
# skip_rust_env_info = true
LIBRARY_EXTENSION = { source = "${CARGO_MAKE_RUST_TARGET_OS}", default_value = "unknown", mapping = {"linux" = "so", "macos" = "dylib" } }
Swoorup /
Created October 2, 2022 16:28
Restartable stream on complete or error using a connect function
use std::task::Poll;
use futures::{Future, FutureExt, Stream};
use pin_project::pin_project;
use tracing::debug;
#[pin_project(project = StreamStateProj)]
#[derive(Debug, Clone)]
enum StreamState<F, S>
Swoorup / StreamCache.scala
Created July 17, 2022 16:12
Cache for redis streams with offsets
package lib.cache
import cats.effect.std.{UUIDGen, Supervisor}
import cats.effect.syntax.all.*
import cats.effect.{Async, Clock, Fiber, Outcome, Ref, Resource}
import cats.syntax.all.*
import fs2.Stream
import io.chrisdavenport.mapref.MapRef
import io.chrisdavenport.rediculous.RedisCommands
import io.chrisdavenport.rediculous.RedisConnection

The response to my first few posts has been much larger than I’d imagined and I’d like to thank everyone for the encouragement.

If you’re interested in building a trading system I recommend first reading my previous post on general ideas to keep in mind.

My first really technical post will be on how to build a limit order book, probably the single most important component of a trading system. Because the data structure chosen to represent the limit order book will be the primary source of market information for trading models, it is important to make it both absolutely correct and extremely fast.

To give some idea of the data volumes, the Nasdaq TotalView ITCH feed, which is every event in every instrument traded on the Nasdaq, can have data rates of 20+ gigabytes/day with spikes of 3 megabytes/second or more. The individual messages average about 20 bytes each so this means handling

Swoorup / ActorK.scala
Last active July 17, 2023 19:54
Typed Actors using Cats Effect, FS2 and Deferred Magic
import cats.effect.syntax.all.*
import cats.syntax.all.*
import cats.effect.*
import fs2.Stream
import cats.effect.std.Queue
import scala.concurrent.duration.*
import lib.FSM
import{Actor, AskMsg}
Swoorup / Demo.scala
Created June 28, 2022 07:51
Typed Akka like actors using fs2 and cats
import cats.effect.syntax.all.*
import cats.syntax.all.*
import cats.effect.*
import fs2.Stream
import cats.effect.std.Queue
import scala.concurrent.duration.*
case class FSM[F[_], S, I, O](run: (S, I) => F[(S, O)])
case class Ping[F[_]](replyTo: Deferred[F, String])
Swoorup / Stream.ts
Created May 23, 2022 17:09
Fetch ndjson stream idea...
import * as S from '@typed/fp/Stream';
import * as E from 'fp-ts/Either';
import { pipe } from 'fp-ts/function';
import * as TE from 'fp-ts/TaskEither';
export function streamFromTaskEither<A>(taskEither: TE.TaskEither<Error, A>): S.Stream<A> {
return pipe(
S.chain(E.match(S.throwError, S.of)),