Пример #1
0
 void esig_OnQuoteChanged(string sSymbol)
 {
     try
     {
         // get tick info
         BasicQuote q = esig.get_GetBasicQuote(sSymbol);
         // get our struct
         Tick k = new TickImpl(sSymbol);
         // convert it
         k.ask   = (decimal)q.dAsk;
         k.bid   = (decimal)q.dBid;
         k.trade = (decimal)q.dLast;
         k.bs    = q.lBidSize;
         k.os    = q.lAskSize;
         k.size  = q.lLastSize;
         DateTime now = esig.GetAppTime;
         k.time = Util.ToTLTime(now);
         k.date = Util.ToTLDate(now);
         if (isPaperTradeEnabled)
         {
             ptt.newTick(k);
         }
         // send it
         tl.newTick(k);
     }
     catch (Exception ex)
     {
         if (GotDebug != null)
         {
             GotDebug(DebugImpl.Create(ex.Message + ex.StackTrace, DebugLevel.Debug));
         }
     }
 }
Пример #2
0
        public static bool Delete(string space, string user, string password, string documentid)
        {
            string         url = GetDocumentsUrl(space) + documentid;
            HttpWebRequest hr  = WebRequest.Create(url) as HttpWebRequest;

            hr.Credentials = new System.Net.NetworkCredential(user, password);
            hr.Method      = "DELETE";
            hr.ContentType = "application/xml";
            try
            {
                // write it
                //System.IO.Stream post = hr.GetRequestStream();
                //post.Write(bytes, 0, 0);
                // get response
                System.IO.StreamReader response = new System.IO.StreamReader(hr.GetResponse().GetResponseStream());
                // display it
                if (SendDebug != null)
                {
                    SendDebug(DebugImpl.Create(response.ReadToEnd()));
                }
            }
            catch (Exception ex)
            {
                if (SendDebug != null)
                {
                    SendDebug(DebugImpl.Create("exception: " + ex.Message + ex.StackTrace));
                }
                return(false);
            }
            return(true);
        }
Пример #3
0
        /// <summary>
        /// stop the server
        /// </summary>
        public void Stop()
        {
            // request thread be stopped
            _go = false;
            if (tl != null)
            {
                tl.Stop();
            }
            if (!_valid)
            {
                return;
            }

            try
            {
                // stop thread
                bw.CancelAsync();
                // release symbols
                foreach (Security sec in _mb)
                {
                    esig.ReleaseSymbol(sec.Symbol);
                }
            }
            catch (Exception ex)
            {
                if (GotDebug != null)
                {
                    GotDebug(DebugImpl.Create(ex.Message + ex.StackTrace, DebugLevel.Debug));
                }
            }
            // garbage collect esignal object
            esig = null;
        }
Пример #4
0
 void debug(string msg)
 {
     if (GotDebug != null)
     {
         GotDebug(DebugImpl.Create(msg));
     }
 }
Пример #5
0
 void debug(string msg)
 {
     if (SendDebug != null)
     {
         SendDebug(DebugImpl.Create(msg));
     }
 }
 void status(string msg)
 {
     if (SendDebug != null)
     {
         SendDebug(DebugImpl.Create(msg, DebugLevel.Status));
     }
 }
Пример #7
0
        public static bool Create(string space, string user, string password, string filename, int ticketid, bool prependdatetime)
        {
            string url = GetDocumentsUrl(space);

            try
            {
                FileStream fs   = new FileStream(filename, FileMode.Open, FileAccess.Read);
                byte[]     data = new byte[fs.Length];
                fs.Read(data, 0, data.Length);
                fs.Close();

                // Generate post objects
                Dictionary <string, object> postParameters = new Dictionary <string, object>();
                string unique = prependdatetime ? Util.ToTLDate(DateTime.Now).ToString() + Util.DT2FT(DateTime.Now) + Path.GetFileName(filename) : Path.GetFileName(filename);
                postParameters.Add("document[name]", unique);
                postParameters.Add("document[file]", data);
                if (ticketid != 0)
                {
                    postParameters.Add("document[ticket_id]", ticketid);
                }

                // Create request and receive response
                string postURL = url;
                try
                {
                    HttpWebResponse webResponse = WebHelpers.MultipartFormDataPost(postURL, user, password, postParameters, contenttype(filename), filename);


                    // Process response
                    StreamReader responseReader = new StreamReader(webResponse.GetResponseStream());
                    string       fullResponse   = responseReader.ReadToEnd();
                    webResponse.Close();
                }
                catch (WebException ex)
                {
                    // workaround for http://www.assembla.com/spaces/AssemblaSupport/support/tickets/122--500-internal-server-error--received-when-trying-to-create-documents
                    if (ex.Message.Contains("500"))
                    {
                        return(true);
                    }
                    return(false);
                }

                return(true);
            }
            catch (Exception ex)
            {
                if (SendDebug != null)
                {
                    SendDebug(DebugImpl.Create("exception: " + ex.Message + ex.StackTrace));
                }

                return(false);
            }
        }
Пример #8
0
        public static bool Create(string space, string user, string password, string filename, int ticketid)
        {
            string url = GetDocumentsUrl(space);

            try
            {
                FileStream fs   = new FileStream(filename, FileMode.Open, FileAccess.Read);
                byte[]     data = new byte[fs.Length];
                fs.Read(data, 0, data.Length);
                fs.Close();

                // Generate post objects
                Dictionary <string, object> postParameters = new Dictionary <string, object>();
                string unique = Util.ToTLDate(DateTime.Now).ToString() + Util.ToTLTime(DateTime.Now) + Path.GetFileName(filename);
                postParameters.Add("document[name]", unique);
                postParameters.Add("document[file]", data);
                if (ticketid != 0)
                {
                    postParameters.Add("document[ticket_id]", ticketid);
                }

                // Create request and receive response
                string          postURL     = url;
                HttpWebResponse webResponse = WebHelpers.MultipartFormDataPost(postURL, user, password, postParameters, contenttype(filename));


                // Process response
                StreamReader responseReader = new StreamReader(webResponse.GetResponseStream());
                string       fullResponse   = responseReader.ReadToEnd();
                webResponse.Close();


                return(true);
            }
            catch (Exception ex)
            {
                if (SendDebug != null)
                {
                    SendDebug(DebugImpl.Create("exception: " + ex.Message + ex.StackTrace));
                }

                return(false);
            }
        }
Пример #9
0
        public bool Start(string username, string password, string type, int data2)
        {
            List <string> accts = new List <string>();

            try
            {
                _tradeDesk.Login(username, password, LOGINURL, type);
                TableAut tab = (TableAut)_tradeDesk.FindMainTable("accounts");
                _acct = new string[] { tab.CellValue(1, 1).ToString() };
            }
            catch (Exception ex)
            {
                if (SendDebug != null)
                {
                    SendDebug(DebugImpl.Create(ex.Message + ex.StackTrace));
                }
                return(false);
            }


            return(true);
        }
Пример #10
0
        public static bool Update(string space, string user, string password, int ticket, string xml)
        {
            string         url = "http://www.assembla.com/spaces/" + space + "/tickets/" + ticket.ToString();
            HttpWebRequest hr  = WebRequest.Create(url) as HttpWebRequest;

            hr.Credentials = new System.Net.NetworkCredential(user, password);
            hr.Method      = "PUT";
            hr.ContentType = "application/xml";
            StringBuilder data = new StringBuilder();

            data.AppendLine(System.Web.HttpUtility.HtmlEncode(xml));
            // encode
            byte[] bytes = UTF8Encoding.UTF8.GetBytes(data.ToString());
            hr.ContentLength = bytes.Length;
            try
            {
                // write it
                System.IO.Stream post = hr.GetRequestStream();
                post.Write(bytes, 0, bytes.Length);
                // get response
                System.IO.StreamReader response = new System.IO.StreamReader(hr.GetResponse().GetResponseStream());
                // display it
                if (SendDebug != null)
                {
                    SendDebug(DebugImpl.Create(response.ReadToEnd()));
                }
            }
            catch (Exception ex)
            {
                if (SendDebug != null)
                {
                    SendDebug(DebugImpl.Create("exception: " + ex.Message + ex.StackTrace));
                }
                return(false);
            }
            return(true);
        }
Пример #11
0
 public void GotDebug(string msg)
 {
     GotDebug(DebugImpl.Create(msg));
 }
Пример #12
0
        public static int Create(string space, string user, string password, string summary, string description, AssemblaStatus status, AssemblaPriority priority)
        {
            int            stat = (int)status;
            int            pri  = (int)priority;
            string         url  = GetTicketsUrl(space);
            HttpWebRequest hr   = WebRequest.Create(url) as HttpWebRequest;

            hr.Credentials     = new System.Net.NetworkCredential(user, password);
            hr.PreAuthenticate = true;
            hr.Method          = "POST";
            hr.ContentType     = "application/xml";
            StringBuilder data = new StringBuilder();

            data.AppendLine("<ticket>");
            data.AppendLine("<status>" + stat.ToString() + "</status>");
            data.AppendLine("<priority>" + pri.ToString() + "</priority>");
            data.AppendLine("<summary>");
            data.AppendLine(System.Web.HttpUtility.HtmlEncode(summary));
            data.AppendLine("</summary>");
            data.AppendLine("<description>");
            data.AppendLine(System.Web.HttpUtility.HtmlEncode(description));
            data.AppendLine("</description>");
            data.AppendLine("</ticket>");
            // encode
            byte[] bytes = UTF8Encoding.UTF8.GetBytes(data.ToString());
            hr.ContentLength = bytes.Length;
            // prepare id
            int id = 0;

            try
            {
                // write it
                System.IO.Stream post = hr.GetRequestStream();
                post.Write(bytes, 0, bytes.Length);
                // get response
                System.IO.StreamReader response = new System.IO.StreamReader(hr.GetResponse().GetResponseStream());
                // get string version
                string rs = response.ReadToEnd();

                XmlDocument xd = new XmlDocument();
                xd.LoadXml(rs);
                XmlNodeList xnl = xd.GetElementsByTagName("id");
                string      val = xnl[0].InnerText;
                if ((val != null) && (val != string.Empty))
                {
                    id = Convert.ToInt32(val);
                }
                // display it
                if (SendDebug != null)
                {
                    SendDebug(DebugImpl.Create(rs));
                }
            }
            catch (Exception ex)
            {
                if (SendDebug != null)
                {
                    SendDebug(DebugImpl.Create("exception: " + ex.Message + ex.StackTrace));
                }
                return(0);
            }
            return(id);
        }
Пример #13
0
        void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            if (!_valid)
            {
                return;
            }
            while (_go)
            {
                try
                {
                    if (qc > qr)
                    {
                        // get requested symbols
                        string[] syms = _tmpregister.Split(',');
                        // go through each one
                        foreach (string sym in syms)
                        {
                            // if we don't have subscription already
                            if (!contains(sym))
                            {
                                // add it to list
                                _mb.Add(sym);
                                // request subscription
                                esig.RequestSymbol(sym, 1);
                            }
                        }
                        if (ReleaseDeadSymbols)
                        {
                            // clone requested basket
                            Basket newbasket = new BasketImpl(syms);
                            // clone existing basket as deadbasket
                            Basket deadbasket = new BasketImpl(_mb);
                            // existing - new = deadsymbols
                            deadbasket.Remove(newbasket);
                            // release dead symbols
                            string symsreleased = string.Empty;
                            foreach (Security dead in deadbasket)
                            {
                                try
                                {
                                    esig.ReleaseSymbol(dead.Symbol);
                                    symsreleased += dead.Symbol + " ";
                                }
                                catch { }
                            }
                            if (symsreleased != string.Empty)
                            {
                                verb("released unused symbols: " + symsreleased);
                            }
                        }
                        qr = qc;
                    }
                    while (_barrequests.hasItems)
                    {
                        BarRequest br = new BarRequest();
                        try
                        {
                            br = _barrequests.Read();
                            BarInterval bi       = (BarInterval)br.Interval;
                            string      interval = string.Empty;
                            int         barsback = DefaultBarsBack;
                            if (bi == BarInterval.CustomTicks)
                            {
                                interval = br.CustomInterval + "T";
                            }
                            else if (bi == BarInterval.CustomTime)
                            {
                                interval = br.CustomInterval + "S";
                            }
                            else if (bi == BarInterval.CustomVol)
                            {
                                interval = br.CustomInterval + "V";
                            }
                            else
                            {
                                if (br.Interval == (int)BarInterval.Day)
                                {
                                    interval = "D";
                                }
                                else
                                {
                                    interval = (br.Interval / 60).ToString();
                                }

                                barsback = BarImpl.BarsBackFromDate(bi, br.StartDateTime, br.EndDateTime);
                            }
                            int alldata = BarRequestsGetAllData ? -1 : 0;
                            int hnd     = esig.get_RequestHistory(br.Symbol, interval, (bi == BarInterval.Day) ? barType.btDAYS : barType.btBARS, barsback, alldata, alldata);
                            verb("requested bar data for " + br.Symbol + " on: " + br.Interval.ToString() + " " + br.CustomInterval.ToString() + " reqhandle: " + hnd);
                            // cache request
                            if (!_barhandle2barrequest.ContainsKey(hnd))
                            {
                                _barhandle2barrequest.Add(hnd, br);
                            }
                            else
                            {
                                verb("already had bar request: " + hnd + " " + _barhandle2barrequest[hnd].ToString());
                            }
                            if (esig.get_IsHistoryReady(hnd) != 0)
                            {
                                processhistory(hnd, br);
                            }
                        }
                        catch (Exception ex)
                        {
                            debug("error on historical bar request: " + br.ToString());
                            debug(ex.Message + ex.StackTrace);
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (GotDebug != null)
                    {
                        GotDebug(DebugImpl.Create(ex.Message + ex.StackTrace, DebugLevel.Debug));
                    }
                }
                if (e.Cancel || !_go)
                {
                    break;
                }
                System.Threading.Thread.Sleep(WaitBetweenEvents);
            }
        }