Adding MongoDB astream integration

This commit is contained in:
Taha Afzal committed 2024-01-02 00:44:52 -05:00
1 parent 3e25b4918f
commit 5b4b41d4eb
10 files changed
+151 -70

No files matched your search

@@ -14,4 +14,9 @@
<ProjectReference Include="..\..\client\spark_core\spark_core.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="MongoDB.Bson" Version="2.23.1" />
<PackageReference Include="MongoDB.Driver" Version="2.23.1" />
</ItemGroup>
</Project>
@@ -3,11 +3,9 @@
// using System.Collections;
// using BCG.Utilities;
// using BCG.Utilities.General;
// namespace BCG
// {
// namespace BCG {
// public class AddColumnsStream : MapStream
// {
// public AddColumnsStream(ViewStream vs, string columnDef) : base (vs, new ColumnAdder (columnDef)) {}
// }
// public class AddColumnsStream : MapStream {
// public AddColumnsStream(ViewStream vs, string columnDef) : base(vs, new ColumnAdder(columnDef)) { }
// }
// }
@@ -3,71 +3,61 @@
// using BCG.Utilities;
// using BCG.Evaluator.AddColumnsExpression;
// namespace BCG
// {
// /// <summary>
// /// Provides methods to add columns to the schema
// /// </summary>
// public class ColumnAdder : IStreamMapper
// {
// protected IDictionary myNewColumns;
// protected IBlueTableSchema mySchema;
// namespace BCG {
// /// <summary>
// /// Provides methods to add columns to the schema
// /// </summary>
// public class ColumnAdder : IStreamMapper {
// protected IDictionary myNewColumns;
// protected IBlueTableSchema mySchema;
// static syntax myParser =
// new syntax();
// static syntax myParser =
// new syntax();
// /// <summary>
// /// string represting the columns to be added to the output table.
// /// </summary>
// /// <param name="colAddExpression"></param>
// public ColumnAdder (string columnDef)
// {
// AddColumnsExpression ace;
// /// <summary>
// /// string represting the columns to be added to the output table.
// /// </summary>
// /// <param name="colAddExpression"></param>
// public ColumnAdder(string columnDef) {
// AddColumnsExpression ace;
// if (DataStreamLoadFileConfig.instance.useStaticParser)
// {
// lock (myParser)
// {
// ace =
// (AddColumnsExpression)myParser.Parse(columnDef);
// if (DataStreamLoadFileConfig.instance.useStaticParser) {
// lock (myParser) {
// ace =
// (AddColumnsExpression)myParser.Parse(columnDef);
// }
// } else {
// syntax parser = new syntax();
// ace =
// (AddColumnsExpression)parser.Parse(columnDef);
// }
// }
// else
// {
// syntax parser = new syntax();
// ace =
// (AddColumnsExpression)parser.Parse(columnDef);
// }
// if (ace == null)
// throw new Exception ("Invalid columnn expression: " + columnDef);
// myNewColumns = ace.columns;
// }
// public virtual IBlueRow map (IBlueRow row)
// {
// if (mySchema == null)
// myConstructSchema (row.schema);
// return new AddColumnsRow (mySchema, row);
// }
// if (ace == null)
// throw new Exception("Invalid columnn expression: " + columnDef);
// myNewColumns = ace.columns;
// }
// public IBlueTableSchema getOutputSchema (IBlueTableSchema inputSchema)
// {
// myConstructSchema (inputSchema);
// return mySchema;
// }
// public virtual IBlueRow map(IBlueRow row) {
// if (mySchema == null)
// myConstructSchema(row.schema);
// return new AddColumnsRow(mySchema, row);
// }
// private void myConstructSchema (IBlueTableSchema schema)
// {
// ColumnInfo[] cis = new ColumnInfo[schema.columnNames.Length + myNewColumns.Count];
// int ciIndex = 0;
// foreach (ColumnInfo ci in schema.columnInfo)
// cis[ciIndex++] = ci;
// foreach (DictionaryEntry de in myNewColumns)
// cis[ciIndex] = new ColumnInfo ((string)de.Key, ciIndex ++,
// ((AddColumnsExpression.ConstantInfo)de.Value).t, ((AddColumnsExpression.ConstantInfo)de.Value).v);
// mySchema = new BlueTableSchema (cis, schema.tableName);
// }
// public IBlueTableSchema getOutputSchema(IBlueTableSchema inputSchema) {
// myConstructSchema(inputSchema);
// return mySchema;
// }
// }
// private void myConstructSchema(IBlueTableSchema schema) {
// ColumnInfo[] cis = new ColumnInfo[schema.columnNames.Length + myNewColumns.Count];
// int ciIndex = 0;
// foreach (ColumnInfo ci in schema.columnInfo)
// cis[ciIndex++] = ci;
// foreach (DictionaryEntry de in myNewColumns)
// cis[ciIndex] = new ColumnInfo((string)de.Key, ciIndex++,
// ((AddColumnsExpression.ConstantInfo)de.Value).t, ((AddColumnsExpression.ConstantInfo)de.Value).v);
// mySchema = new BlueTableSchema(cis, schema.tableName);
// }
// }
// }
@@ -0,0 +1,37 @@
using System;
using MongoDB.Driver;
using MongoDB.Bson;
class Program {
static void Main() {
// Set the connection string and database name
string connectionString = "mongodb://localhost:27017";
string databaseName = "your_database_name";
string collectionName = "your_collection_name";
// Create a MongoClient
MongoClient client = new MongoClient(connectionString);
// Access the database
IMongoDatabase database = client.GetDatabase(databaseName);
// Access the collection
IMongoCollection<BsonDocument> collection = database.GetCollection<BsonDocument>(collectionName);
// Fetch all documents from the collection
var documents = collection.Find(Builders<BsonDocument>.Filter.Empty).ToCursor();
// Iterate through the documents and print values
foreach (var document in documents.ToEnumerable()) {
// Assuming your document structure has fields named "Field1", "Field2", etc.
Console.WriteLine("Field1: " + document["Field1"]);
Console.WriteLine("Field2: " + document["Field2"]);
// Add more fields as needed
// Print a separator between documents
Console.WriteLine(new string('-', 20));
}
}
}
@@ -11,7 +11,7 @@ using System.Threading;
bts.Log.Gen.info($"Starting DSPublisher");
Console.WriteLine("Starting DSPublisher...");
bool run_echo_tcp_client_only = true;
bool run_echo_tcp_client_only = false;
static void init(string[] args) {
Func<string, string, Task> login = async (l, p) => {
var login = l;
@@ -154,7 +154,9 @@ namespace BCG {
size_completed_event.WaitOne(); // Wait for the size receive operation to complete
int message_size = BitConverter.ToInt32(size_buffer, 0);
Log.assert_d(message_size > 0, $"message_size: {message_size}");
//Log.assert_d(message_size > 0, $"message_size: {message_size}");
if (message_size <= 0)
throw new ApplicationException($"msg_size: {message_size} not allowed");
Log.Gen.info($"ReceiveSizePrefixedMessageAsync message_size: {message_size}");
// at this ppint message sz has been read, now read the data
+1 -1
View File
@@ -15,7 +15,7 @@ namespace BCG {
/// </summary>
[STAThread]
public static async Task Main(string[] args) {
bool run_echo_tcp_server_only = true;
bool run_echo_tcp_server_only = false;
bts.utils.BTSNativeMethods.provide_command_line(new string[] { }, 0);
mbts.config.Configuration.initialize();
if (run_echo_tcp_server_only) {
@@ -16,7 +16,7 @@ namespace BCG {
private EMACalculator _calc;
private readonly IBlueTableSchema _schema = BlueDataUtility.form_schema(
"SMA", Tuple.Create("id", TypeCode.Int32),
Tuple.Create("sma", TypeCode.Double));
Tuple.Create("ema", TypeCode.Double));
public EMAStream(ViewStream stream, string col_name, double smoothing_factor) {
_col_name = col_name;
@@ -0,0 +1,49 @@
using System;
namespace BCG {
/*
----------------------------------------------------------------------
*Expression*
----------------------------------------------------------------------
r=filter(bbo(),"sec='BTC-PERPETUAL'")
r=math(r,"wt_mid_price = (bid_price*bid_sz + ask_price*ask_sz)/(bid_sz+ask_sz)")
r=timeSeries(r)
r=math(r,"sz = (bid_sz + ask_sz) * 1.0")
r=filter(r,"sz > 0")
r=renko(r,"wt_mid_price", 2.0)
----------------------------------------------------------------------
*Schema*
----------------------------------------------------------------------
id System.Int32
entry_price System.Double
current_price System.Double
brick_low System.Double
brick_high System.Double
brick_transition System.String
n_updates_within System.Int32
*/
public class SecurityRenkoStream : ViewStream {
public SecurityRenkoStream(int sec_key, double brick_sz) {
ViewStream r;
r = new FilterStream(new BBOStream(),
$"sec_key={sec_key}");
r = new MathStream(r,
"wt_mid_price = (bid_price*bid_sz + ask_price*ask_sz)/(bid_sz+ask_sz)");
r = new TimeSeriesStream(r);
r = new MathStream(r,
"sz = (bid_sz + ask_sz) * 1.0");
r = new FilterStream(r,
"sz > 0");
r = new RenkoStream(r,
"wt_mid_price",
brick_sz);
mySetRealSource(r);
}
}
}
+1 -1
View File
@@ -10,7 +10,7 @@ OrdersSoftCleanup {
}
}
PlacementInQueue {
vlaue{
value{
enabled: true;
}
}