Exemplo n.º 1
0
        private void websocket_MessageReceived(object sender, MessageReceivedEventArgs msg)
        {
            //HelperClass.addLog(msg.Message);
            Console.WriteLine("[" + DateTime.Now.ToString("HH:mm:ss.fff") + "] " + msg.Message);

            var json = (JObject)JsonConvert.DeserializeObject(msg.Message);
            var e    = json["echo_req"];
            var b    = json["buy"];
            var p    = json["proposal"];
            var t    = json["tick"];

            if (json["authorize"] != null)
            {
                HelperClass.addLog("Authenticated! Delaying 15s");
                HelperClass.setBalance((double)json["authorize"]["balance"]);
                HelperClass.addDelay(15);
                return;
            }
            else if (json["balance"] != null)
            {
                HelperClass.setBalance((double)json["balance"]["balance"]);
            }
            else if (json["error"] != null)
            {
                HelperClass.addLog("Error retrieving data... Delaying 60s");
                HelperClass.addLog("Message:" + (string)json["error"]["message"]);
                HelperClass.addDelay(60);
                //active_trading = false;
                return;
            }
            else if (json["msg_type"] != null && json["buy"] != null)
            {
                int      placed_order = (int)JsonConvert.DeserializeObject(b["start_time"].ToString(), typeof(int));
                TimeSpan placed       = (new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)).AddSeconds(placed_order).ToLocalTime().TimeOfDay;

                HelperClass.addToGrid((string)e["price"], (string)e["buy"], (string)json["msg_type"], (string)b["balance_after"], (string)b["shortcode"], (string)b["contract_id"], placed.ToString(), (string)b["transaction_id"], placed.ToString(), (string)b["buy_price"], (string)b["payout"]);
            }

            if (lastEPOCH == null || lastQUOTE == null || lastID == null)
            {
                lastEPOCH = new int[2];
                lastQUOTE = new decimal[2];
                lastID    = new string[2];
            }

            if ((string)e["ticks"] == "frxEURUSD")
            {
                lastEPOCH[1]            = lastEPOCH[0];
                lastEPOCH[0]            = (int)t["epoch"];
                lastQUOTE[1]            = lastQUOTE[0];
                lastQUOTE[0]            = (decimal)t["quote"];
                lastID[1]               = lastID[0];
                lastID[0]               = (string)t["id"];
                lastTICK                = DateTime.Now;
                HelperClass.BINARY_TIME = DateTime.Now;
                HelperClass.BINARY_TICKS++;
            }
        }
Exemplo n.º 2
0
        public void MarketDataUpdate(OrderBookEvent orderBookEvent)
        {
            Invoke((MethodInvoker)(() => label18.Text = "$ " + HelperClass.balance.ToString()));

            if (bws.lastID != null && bws.lastEPOCH != null && bws.lastQUOTE != null && bws.lastQUOTE[0] > 0 && bws.active_trading)
            {
                decimal lmax_diff  = (orderBookEvent.ValuationAskPrice + orderBookEvent.ValuationBidPrice) / 2; // LMAX(ASK+BID)/2
                decimal binary     = bws.lastQUOTE[0];                                                          // 1.11111
                decimal diff_input = decimal.Parse(textBox3.Text);                                              // 0.00010
                decimal lmax_bin   = (lmax_diff - binary);                                                      //
                decimal bin_lmax   = (binary - lmax_diff);                                                      //

                Invoke((MethodInvoker)(() => label8.Text = lmax_diff.ToString()));
                Invoke((MethodInvoker)(() => label10.Text = binary.ToString()));
                Invoke((MethodInvoker)(() => label11.Text = lmax_bin.ToString()));

                if (DateTime.Now > HelperClass.delayTime)
                {
                    if (lmax_diff > diff_input) //
                    {
                        var buyOrder  = "{\"parameters\": { \"amount\": \"" + bws.PAYMENT_AMNT + "\", \"basis\": \"stake\", \"contract_type\": \"CALL\", \"currency\": \"USD\", \"duration\": \"5\", \"duration_unit\": \"t\", \"symbol\": \"frxEURUSD\" }, \"buy\":\"" + bws.lastID[0] + "\", \"price\":\"" + int.Parse(textBox5.Text).ToString(CultureInfo.CreateSpecificCulture("en-US")) + "\"}";
                        var sellOrder = "{\"parameters\": { \"amount\": \"" + bws.PAYMENT_AMNT + "\", \"basis\": \"stake\", \"contract_type\": \"PUT\", \"currency\": \"USD\", \"duration\": \"5\", \"duration_unit\": \"t\", \"symbol\": \"frxEURUSD\" }, \"buy\":\"" + bws.lastID[0] + "\", \"price\":\"" + int.Parse(textBox5.Text).ToString(CultureInfo.CreateSpecificCulture("en-US")) + "\"}";

                        if (lmax_bin > diff_input) // 0.00020 > 0.00010
                        {
                            bws.websocket.Send(buyOrder);
                            HelperClass.addDelay(60);
                            HelperClass.addLog("ATTEMPTING CALL ORDER @ " + bws.lastQUOTE[0] + ", Delaying 60s...");
                            Invoke((MethodInvoker)(() => dataGridView1.Rows.Add(lmax_diff, binary, lmax_bin, "CALL", "$" + bws.PAYMENT_AMNT, DateTime.Now, bws.lastID[0])));
                            Invoke((MethodInvoker)(() => dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.RowCount - 1));
                            Console.WriteLine("CALL @ LMAX: " + lmax_diff + " Binary: " + binary + " Diff: " + lmax_bin);
                        }
                        else if (bin_lmax > diff_input) // -0.00020 > 0.00010
                        {
                            bws.websocket.Send(sellOrder);
                            HelperClass.addDelay(60);
                            HelperClass.addLog("ATTEMPTING PUT ORDER @ " + bws.lastQUOTE[0] + ", Delaying 60s...");
                            Invoke((MethodInvoker)(() => dataGridView1.Rows.Add(lmax_diff, binary, lmax_bin, "PUT", "$" + bws.PAYMENT_AMNT, DateTime.Now, bws.lastID[0])));
                            Invoke((MethodInvoker)(() => dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.RowCount - 1));
                            Console.WriteLine("PUT @ LMAX: " + lmax_diff + " Binary: " + binary + " Diff: " + bin_lmax);
                        }
                    }
                }
            }

            Console.WriteLine("[" + DateTime.Now.ToString("HH:mm:ss.fff") + "] " + orderBookEvent);
            Invoke((MethodInvoker)(() => listBox1.Refresh()));
            Invoke((MethodInvoker)(() => listBox1.TopIndex = listBox1.Items.Count - 1));
        }