// Class constructor internal Basket(Form1 Form, IBClient IBClient) { form = Form; isBasketExecuting = false; connectionString = "server=" + Settings.dbHost + ";user id=slinger;password=659111;database=tbr"; dbConn = new MySqlConnection(connectionString); iBClient = IBClient; }
public Form1() { InitializeComponent(); // listView1 setup listView1.View = View.Details; // Shows the header listView1.FullRowSelect = true; // !!!Lets to select the whole row in the table!!! // listView2 setup listView2.View = View.Details; listView2.GridLines = true; // Horizoltal lines listView2.Columns.Add("Time:"); listView2.Columns[0].Width = 60; listView2.Columns.Add("Source:", -2, HorizontalAlignment.Left); listView2.Columns.Add("Message:"); listView2.Columns[2].Width = 400; // DB log messages Log.InitializeDB(); // Connect to the database logThread = new Thread(new ThreadStart(LogThread)); // Make an instance of the thread and assign method name which will be executed in the thread // Basket thread executeBasketThread = new Thread(new ThreadStart(ExecuteBasketThread)); // IB API instances signal = new EReaderMonitorSignal(); ibClient = new IBClient(signal); apiManager = new ApiManager(ibClient, this); // Json search object class instance searchResponse = new SearchResponse(); quoteResponse = new QuoteResponse(); availableFundsResponse = new AvailableFundsResponse(); // Fleck socket server FleckLog.Level = LogLevel.Debug; allSockets = new List <IWebSocketConnection>(); var server = new WebSocketServer("ws://0.0.0.0:8181"); // Other basket = new Basket(this, ibClient); server.SupportedSubProtocols = new[] { "superchat", "chat" }; server.Start(socket => { socket.OnOpen = () => {; Log.Insert(DateTime.Now, "Form1.cs", string.Format("Websocket connection open!"), "white"); allSockets.Add(socket); }; socket.OnClose = () => { allSockets.Remove(socket); }; socket.OnMessage = message => { // Output message to system log Log.Insert(DateTime.Now, "Form1.cs", string.Format("socket.OnMessage. A message received from a client: {0}", message), "white"); //allSockets.ToList().ForEach(s => s.Send("Hello from websocket! Form1.cs line 95")); // Send a greeting message to all websocket clients // DETERMINE WHAT TYPE OF API REQUEST IS RECEVIED HERE // apiManager.Search // apiManager.GetQuote var jsonObject = Newtonsoft.Json.Linq.JObject.Parse(message); var requestBody = jsonObject["body"]; switch (jsonObject["requestType"].ToString()) { case "symbolSearch": apiManager.Search(requestBody["symbol"].ToString()); break; case "getQuote": apiManager.GetQuote(requestBody["symbol"].ToString(), (int)requestBody["basketNumber"], requestBody["currency"].ToString()); break; case "getAvailableFunds": ibClient.ClientSocket.reqAccountUpdates(true, "U2314623"); break; } }; }); // Events ibClient.CurrentTime += IbClient_CurrentTime; // Get exchnage current time // ibClient.MarketDataType += IbClient_MarketDataType; ibClient.Error += IbClient_Error; // Errors handling ibClient.TickPrice += IbClient_TickPrice; // reqMarketData. EWrapper Interface ibClient.OrderStatus += IbClient_OrderStatus; // Status of a placed order ibClient.NextValidId += IbClient_NextValidId; // Fires when api is connected. Connection status received here ibClient.ContractDetails += IbClient_ContractDetails; // Ticker search ibClient.ContractDetailsEnd += IbClient_ContractDetailsEnd; // Fires up when the the search response feed is finished. One search request can contain multiple contracts ibClient.UpdateAccountValue += IbClient_UpdateAccountValue; // Account info }
public ApiManager(IBClient IBClient, Form1 Form) // Constructor { iBClient = IBClient; form = Form; }