Added BBO to fake securities
This commit is contained in:
1 parent
0d49c4c0fe
commit
73183aa007
2 files changed
+68
-11
No files matched your search
@@ -16,9 +16,11 @@ using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using SecurityKey = System.UInt32;
|
||||
using MDHandle = mbts.co2.FakeMDConsumerHandle;
|
||||
|
||||
namespace bts {
|
||||
[Export(typeof(IShellDaemon))]
|
||||
// publishes a fixed set of hard coded securities to the bus
|
||||
internal class FakeMDDaemon : IShellDaemon, IDisposable {
|
||||
private readonly IBus _bus;
|
||||
private IDisposable _dispose;
|
||||
@@ -33,22 +35,30 @@ namespace bts {
|
||||
k.ToString(), cp == PutOrCall.Call ? "C" : "P");
|
||||
rv.Add(id, new SecurityMD(
|
||||
get_glbx_option("ew3", id, exp, k, cp, exchange_id, desc),
|
||||
new FakeSecurityMDConsumerHandle(id, exchange_id)));
|
||||
new MDHandle(id, exchange_id,
|
||||
new MDHandle.PriceLevel[] { new MDHandle.PriceLevel(1000, 100) },
|
||||
new MDHandle.PriceLevel[] { new MDHandle.PriceLevel(1001, 101) }
|
||||
)));
|
||||
};
|
||||
// add a future
|
||||
UInt32 id = 0;
|
||||
UInt64 exchange_id = 0;
|
||||
MDHandle fut_ch =
|
||||
new MDHandle(id, exchange_id,
|
||||
new MDHandle.PriceLevel[] { new MDHandle.PriceLevel(4000, 100) },
|
||||
new MDHandle.PriceLevel[] { new MDHandle.PriceLevel(4001.25, 101) });
|
||||
rv.Add(id, new SecurityMD(
|
||||
get_glbx_future("ES", id, new DateTime(2022, 3, 18), exchange_id, "ESZ1"),
|
||||
new FakeSecurityMDConsumerHandle(id, exchange_id)));
|
||||
fut_ch));
|
||||
// add 2 options exps
|
||||
id++; exchange_id++;
|
||||
DateTime exp = new DateTime(2022, 3, 18);
|
||||
for (double k = 2000; k <= 5000; k += 10) {
|
||||
for (double k = 2000; k <= 6000; k += 10) {
|
||||
add_strike(exp, k, PutOrCall.Call, id++, exchange_id++);
|
||||
add_strike(exp, k, PutOrCall.Put, id++, exchange_id++);
|
||||
}
|
||||
exp = new DateTime(2022, 6, 17);
|
||||
for (double k = 2000; k <= 5000; k += 10) {
|
||||
for (double k = 2000; k <= 6000; k += 10) {
|
||||
add_strike(exp, k, PutOrCall.Call, id++, exchange_id++);
|
||||
add_strike(exp, k, PutOrCall.Put, id++, exchange_id++);
|
||||
}
|
||||
@@ -65,7 +75,7 @@ namespace bts {
|
||||
|
||||
private void _on_timer(TimeSpan ts_from_start) {
|
||||
if (!_published) {
|
||||
if (ts_from_start.TotalSeconds >= 10) {
|
||||
if (ts_from_start.TotalSeconds >= 5) {
|
||||
_published = true;
|
||||
bts.Log.Gen.info("FakeMDDaemon publishing md");
|
||||
_bus.post(SparkTags.FakeSecuritiesTag, _sec_map);
|
||||
|
||||
@@ -6,6 +6,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
@@ -14,12 +15,36 @@ using System.Threading.Tasks;
|
||||
using security_key = System.UInt32;
|
||||
|
||||
namespace mbts.co2 {
|
||||
public class FakeSecurityMDConsumerHandle : IMDConsumerHandle {
|
||||
public class FakeMDConsumerHandle : IMDConsumerHandle {
|
||||
public class PriceLevel {
|
||||
public static PriceLevel empty = new PriceLevel(Double.NaN, 0);
|
||||
public static IntPrice intprice_from_double(double d) {
|
||||
if (double.IsNaN(d)) {
|
||||
return IntPrice.NaN;
|
||||
}
|
||||
return new IntPrice((long)d, 0);
|
||||
}
|
||||
public double price;
|
||||
public uint qty;
|
||||
public PriceLevel(double price_arg, uint qty_arg) {
|
||||
price = price_arg;
|
||||
qty = qty_arg;
|
||||
}
|
||||
public NativePriceSize get_native_ps() {
|
||||
return new NativePriceSize(intprice_from_double(price), qty);
|
||||
}
|
||||
}
|
||||
|
||||
private security_key _key;
|
||||
private ulong _numeric_key;
|
||||
public FakeSecurityMDConsumerHandle(security_key key, ulong numeric_key) {
|
||||
public readonly IEnumerable<PriceLevel> bid_book, ask_book;
|
||||
public FakeMDConsumerHandle(security_key key, ulong numeric_key,
|
||||
IEnumerable<PriceLevel> bid_book_arg,
|
||||
IEnumerable<PriceLevel> ask_book_arg) {
|
||||
_key = key;
|
||||
_numeric_key = numeric_key;
|
||||
bid_book = bid_book_arg;
|
||||
ask_book = ask_book_arg;
|
||||
}
|
||||
// Once is_initialized goes true it never goes false
|
||||
public bool is_heart_beating { get { return true; } }
|
||||
@@ -35,13 +60,31 @@ namespace mbts.co2 {
|
||||
public ulong market_timestamp { get { return 0; } }
|
||||
|
||||
public bool get_bbo(ref ulong time, out NativePriceSize bid, out NativePriceSize ask) {
|
||||
bid = new NativePriceSize();
|
||||
ask = new NativePriceSize();
|
||||
return false;
|
||||
bool rv = false;
|
||||
bid = PriceLevel.empty.get_native_ps();
|
||||
ask = PriceLevel.empty.get_native_ps();
|
||||
if (bid_book != null && bid_book.Count() > 0) {
|
||||
bid = bid_book.ElementAt(0).get_native_ps();
|
||||
rv = true;
|
||||
}
|
||||
if (ask_book != null && ask_book.Count() > 0) {
|
||||
ask = ask_book.ElementAt(0).get_native_ps();
|
||||
rv = true;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
public bool get_depth(ref ulong time, ref NativePriceSize[] bids, ref NativePriceSize[] asks, uint depth) {
|
||||
return false;
|
||||
if (bid_book == null || ask_book == null) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < Math.Min(bid_book.Count(), depth); i++) {
|
||||
bids[i] = bid_book.ElementAt(i).get_native_ps();
|
||||
}
|
||||
for (int i = 0; i < Math.Min(ask_book.Count(), depth); i++) {
|
||||
asks[i] = ask_book.ElementAt(i).get_native_ps();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool get_last_trade(ref ulong time, out NativePriceSize ps, out DateTime timestamp, out ulong total_volume) {
|
||||
@@ -77,5 +120,9 @@ namespace mbts.co2 {
|
||||
public double session_high { get { return 1000; } }
|
||||
public double session_low { get { return 500; } }
|
||||
public double fixing_price { get { return 20; } }
|
||||
|
||||
#region mutators
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user