Skip to content

Instantly share code, notes, and snippets.

@Kikimora
Created November 5, 2020 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kikimora/e0a583d1fd26ae2535055bf8653efcc3 to your computer and use it in GitHub Desktop.
Save Kikimora/e0a583d1fd26ae2535055bf8653efcc3 to your computer and use it in GitHub Desktop.
namespace Qoden.WebSockets
{
//marketdata/info URL is a SignalR endpoint which support several 'channels'
//Book(String symbol) channel returns order book updates. Upon connecting you'll get order book snapahot and then stream of
//increments and snapshots. Snapshot is indicated by 'snapashot' flag.
//Ex: hubConnection.stream(OrderBookInfo.class, "Book", "btc_usd")
//In java version I mapped 'decimal' to String since I don't know what class in Java does same as decimal in .NET
//Trades(String symbol) channel returns recent trades. Upon connection you'll receive latest 100 trades and then you'll get updates
//as they come.
//Ex: hubConnection.stream(TradeInfo[].class, "Trades", "btc_usd")
//MiniTicker() channel returns market overview, some basic information about all instruments. Upon connecting you'll get snapshot
//followed by updates.
//Ex: hubConnection.stream(QuoteInfo[].class, "MiniTicker")
[DataContract]
public sealed class OrderBookInfo
{
[DataMember]
public string Instrument { get; set; }
[DataMember]
public OrderBookLevelInfo[] Bids { get; set; }
[DataMember]
public OrderBookLevelInfo[] Asks { get; set; }
[DataMember]
public long Version { get; set; }
[DataMember]
public decimal AskTotalAmount { get; set; }
[DataMember]
public decimal BidTotalAmount { get; set; }
[DataMember]
public bool Snapshot { get; set; }
public static OrderBookInfo Empty(string instrument) => new OrderBookInfo
{
Instrument = instrument,
Asks = Array.Empty<OrderBookLevelInfo>(),
Bids = Array.Empty<OrderBookLevelInfo>(),
Snapshot = true
};
}
[DataContract]
public struct OrderBookLevelInfo
{
[DataMember]
public decimal Amount { get; }
[DataMember]
public decimal Price { get; }
public OrderBookLevelInfo(decimal amount, decimal price)
{
Amount = amount;
Price = price;
}
}
public sealed class QuoteInfo
{
[DataMember]
public string Instrument { get; set; }
/// <summary>
/// Start date and time of quote.
/// </summary>
[DataMember]
public DateTime Start { get; set; }
DateTime IMarketUpdate.Timestamp => Start;
/// <summary>
/// End date and time of quote
/// </summary>
[DataMember]
public DateTime End { get; set; }
/// <summary>
/// Lowest price of quote in the timeframe.
/// </summary>
[DataMember]
public decimal Low { get; set; }
/// <summary>
/// Highest price of quote in the timeframe.
/// </summary>
[DataMember]
public decimal High { get; set; }
/// <summary>
/// Volume of trading
/// </summary>
[DataMember]
public decimal Volume { get; set; }
/// <summary>
/// Open price
/// </summary>
[DataMember]
public decimal Open { get; set; }
/// <summary>
/// Close price
/// </summary>
[DataMember]
public decimal Close { get; set; }
}
public class TradeInfo
{
[DataMember]
public long TradeId { get; set; }
[DataMember]
public DateTime TradeTime { get; set; }
[DataMember]
public decimal Amount { get; set; }
[DataMember]
public decimal ExecutionPrice { get; set; }
[DataMember]
public string Instrument { get; set; }
[DataMember]
public OrderSide Side { get; set; }
}
public enum OrderSide : byte
{
Buy = 0,
Sell = 1
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment