Skip to content

Instantly share code, notes, and snippets.

using System.Net;
class Program {
static async Task Main(string[] args)
{
// Example 1. await-foreach
static async IAsyncEnumerable<int> YieldReturnNumbers(List<int> numbers)
{
foreach (int number in numbers)
{
await Task.Delay(1000);
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
public delegate void MessageArrivedHandler(string message);
class Publisher
{
private event MessageArrivedHandler _messageArrived = delegate {};
using System;
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json; // dotnet add package Newtonsoft.Json
class Program
{
static void Main(string[] args)
{
// Read JSON order book from file
@normanlmfung
normanlmfung / json
Created March 28, 2024 05:03
csharp_json_orderbook_data
{
"Pairs": {
"BTCUSD": {
"Bids": [45000.0, 44990.0, 44980.0, 44970.0, 44960.0, 44950.0, 44940.0, 44930.0, 44920.0, 44910.0, 44900.0, 44890.0, 44880.0, 44870.0, 44860.0, 44850.0, 44840.0, 44830.0, 44820.0, 44810.0, 44800.0, 44790.0, 44780.0, 44770.0, 44760.0, 44750.0, 44740.0, 44730.0, 44720.0, 44710.0, 44700.0, 44690.0, 44680.0, 44670.0, 44660.0, 44650.0, 44640.0, 44630.0, 44620.0, 44610.0, 44600.0, 44590.0, 44580.0, 44570.0, 44560.0, 44550.0, 44540.0, 44530.0, 44520.0, 44510.0],
"Asks": [45100.0, 45110.0, 45120.0, 45130.0, 45140.0, 45150.0, 45160.0, 45170.0, 45180.0, 45190.0, 45200.0, 45210.0, 45220.0, 45230.0, 45240.0, 45250.0, 45260.0, 45270.0, 45280.0, 45290.0, 45300.0, 45310.0, 45320.0, 45330.0, 45340.0, 45350.0, 45360.0, 45370.0, 45380.0, 45390.0, 45400.0, 45410.0, 45420.0, 45430.0, 45440.0, 45450.0, 45460.0, 45470.0, 45480.0, 45490.0, 45500.0, 45510.0, 45520.0, 45530.0, 45540.0, 45550.0, 45560.0, 45570.0, 45580.0, 45590.0, 45600.0]
},
"ETHUSD": {
"Bids": [3
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
public class Book
{
public string Region { get; set; }
public double AUM { get; set; }
}
using System;
using System.Text.RegularExpressions;
class Program
{
static void Main()
{
// https://www.mikesdotnetting.com/article/46/c-regular-expressions-cheat-sheet
string emailAddress = "[email protected]";
using System;
using System.Net.Http;
using System.Threading.Tasks;
/*
OKX API
OKX REST API addresses:
REST: https://www.okx.com/
using System;
using System.Security.Cryptography;
using System.Text;
public class AsymmetricEncryptionExample
{
public static void Main(string[] args)
{
try
{
using System;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;
class Program
{
static void Main(string[] args)
{
// Create a concurrent queue to store lambda expressions
using System.Threading;
using System.Threading.Tasks;
using System.Net.Http;
/*
Processor Afffinity https://stackoverflow.com/questions/2510593/how-can-i-set-processor-affinity-to-a-thread-or-a-task-in-net
ConfigureAwait - When an asynchronous method awaits a Task directly, continuation usually occurs in the same thread that created the task, depending on the async context. This behavior can be costly in terms of performance and can result in a deadlock on the UI thread. To avoid these problems, call Task.ConfigureAwait(false).
https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task.configureawait?view=net-8.0
What's SynchronizationContext?