예제 #1
0
 public PGenEntry(ShareEntry shareentry,
                  string buyprice,
                  string numbersharestobuy,
                  string sellprice,
                  string numbersharestosell,
                  string sectype,
                  string exchange,
                  string primaryexchange,
                  string currency,
                  string localsymbol,
                  string secidtype,
                  string secid,
                  string genericticks)
 {
     _shareentry         = shareentry;
     _buyprice           = buyprice;
     _numbersharestobuy  = numbersharestobuy;
     _sellprice          = sellprice;
     _numbersharestosell = numbersharestosell;
     _sectype            = sectype;
     _exchange           = exchange;
     _primaryexchange    = primaryexchange;
     _currency           = currency;
     _localsymbol        = localsymbol;
     _secidtype          = secidtype;
     _secid        = secid;
     _genericticks = genericticks;
 }
예제 #2
0
            public bool AddShareEntry(ShareEntry entry, bool assigntickerid)
            {
                if (_shareentries_byticker.ContainsKey(entry._ticker))
                {
                    entry._tickerid = _shareentries_byticker [entry._ticker]._tickerid;
                    return(true);
                }
                string tickerid;

                if (assigntickerid)
                {
                    tickerid        = _currenttickerid.ToString();
                    entry._tickerid = tickerid;
                    _currenttickerid++;
                }
                else
                {
                    tickerid         = entry._tickerid;
                    _currenttickerid = long.Parse(entry._tickerid) + 1;
                }

                _shareentries [tickerid] = entry;
                _shareentries_byticker [entry._ticker] = entry;
                _linearshareentries.Add(entry);
                if (assigntickerid)
                {
                    _newshareentries.Add(entry);
                }
                return(false);
            }
예제 #3
0
        public double GetSpeed()
        {
            long   time5m = DateTime.Now.ToFileTimeUtc() - (10L * 1000L * 1000L * MEASURE_TIME_SECONDS);
            double total  = 0;

            lock (locker)
            {
                while (past.Count > 0)
                {
                    ShareEntry se = past.Peek();
                    if (se.time < time5m)
                    {
                        past.Dequeue();
                    }
                    else
                    {
                        break;
                    }
                }

                foreach (ShareEntry se in past)
                {
                    total += se.diff;
                }
            }

            total *= Math.Pow(2, 32);              // get total hashes
            total /= 1000000.0;                    // get MH
            total /= (double)MEASURE_TIME_SECONDS; // in past X minutes, get MH/s

            return(total);
        }
예제 #4
0
        void CreatePGen(pcmdsupport.ParseAccountsCMDLine account, ShareEntry shareentry,
                        string filename,
                        params PGenEntry [] pgens)
        {
            string username = account.UserName;

            Utility.CreateDirectory(Path.GetDirectoryName(filename));

            FileStream   filestream = null;
            StreamWriter writer     = null;

            try
            {
                filestream = new FileStream(filename, FileMode.Create);
                writer     = new StreamWriter(filestream);

                writer.WriteLine("<orders>");

                foreach (PGenEntry pgenentry in pgens)
                {
                    pgenentry._shareentry._pgenfilename = filename;

                    writer.Write(" <order ");

                    WritePGenAttr(writer, "ticker", pgenentry._shareentry._ticker);
                    WritePGenAttr(writer, "tickerid", pgenentry._shareentry._tickerid);
                    WritePGenAttr(writer, "buyprice", pgenentry._buyprice);
                    WritePGenAttr(writer, "numberbuyshares", pgenentry._numbersharestobuy);
                    WritePGenAttr(writer, "sellprice", pgenentry._sellprice);
                    WritePGenAttr(writer, "numbersellshares", pgenentry._numbersharestosell);
                    WritePGenAttr(writer, "sectype", pgenentry._sectype);
                    WritePGenAttr(writer, "exchange", pgenentry._exchange);
                    WritePGenAttr(writer, "primaryexchange", pgenentry._primaryexchange);
                    WritePGenAttr(writer, "currency", pgenentry._currency);
                    WritePGenAttr(writer, "localsymbol", pgenentry._shareentry._ticker);
                    WritePGenAttr(writer, "secidtype", pgenentry._secidtype);
                    WritePGenAttr(writer, "secid", pgenentry._secid);
                    WritePGenAttr(writer, "genericticks", pgenentry._genericticks);
                    WritePGenAttr(writer, "displayname", pgenentry._shareentry._displayname);

                    writer.WriteLine("></order>");
                }

                writer.WriteLine("</orders>");
            }
            finally
            {
                if (writer != null)
                {
                    writer.Close();
                }
                if (filestream != null)
                {
                    filestream.Close();
                }
            }
        }
예제 #5
0
 public PGenEntry(ShareEntry shareentry,
                  string buyprice,
                  string numbersharestobuy,
                  string sellprice,
                  string numbersharestosell,
                  IBSpecifics ibspecifics) : this(shareentry, buyprice, numbersharestobuy, sellprice, numbersharestosell,
                                                  ibspecifics._sectype, ibspecifics._exchange, ibspecifics._primaryexchange,
                                                  ibspecifics._currency, ibspecifics._localsymbol, ibspecifics._secidtype,
                                                  ibspecifics._secid, ibspecifics._genericticks)
 {
 }
예제 #6
0
        PGenEntry [] CreatePGenSet(ShareEntry entry, decimal start, decimal decrement, int number, decimal selloffset, int numbershares_buy, int numbershares_sell, IBSpecifics ibspecifics)
        {
            List <PGenEntry> pgens   = new List <PGenEntry> ();
            decimal          current = start;

            for (int i = 0; i < number; i++)
            {
                PGenEntry pgen = new PGenEntry(entry, current.DisplayMoney(), numbershares_buy.ToString(), (current + selloffset).DisplayMoney(), numbershares_sell.ToString(), ibspecifics);
                pgens.Add(pgen);
                current += decrement;
            }
            return(pgens.ToArray());
        }
예제 #7
0
        PGenEntry [] CreatePGenSetRange(ShareEntry entry, decimal lower, decimal upper, decimal gap, decimal selloffset,
                                        int numbershares_buy, int numbershares_sell, IBSpecifics ibspecifics)
        {
            List <PGenEntry> pgens   = new List <PGenEntry> ();
            decimal          current = lower;

            while (current <= upper)
            {
                PGenEntry pgen = new PGenEntry(entry, current.DisplayMoney(), numbershares_buy.ToString(), (current + selloffset).DisplayMoney(), numbershares_sell.ToString(), ibspecifics);
                pgens.Add(pgen);
                if (gap == 0)
                {
                    break;
                }
                current += gap;
            }
            return(pgens.ToArray());
        }
예제 #8
0
        void Go(pcmdsupport.ParseDBCMDLine dbcmdline, pcmdsupport.ParseAccountsCMDLine accountscmdline,
                int startindex, string [] args)
        {
            try
            {
                _mysqlconnection = dbmanager.GetDBConnection(dbcmdline.UserName, dbcmdline.Pwd, dbcmdline.Schema, dbcmdline.Hostname);
                _shareentries.Reset();
                ReadDatabase_shares(accountscmdline);

                List <string> fields = Fields.CollateFields(startindex, true, args);
                if (fields == null || fields.Count == 0)
                {
                    return;
                }

                // format is [ticker,displayname,exchange,maxoi,maxvalue]
                foreach (string input in fields)
                {
                    string    newinput = input;
                    string [] splits   = newinput.Split(',');
                    if (splits.Length == 5)
                    {
                        ShareEntry shareentry = new ShareEntry(splits [0], splits [1], splits [2], "STK", "0",
                                                               splits [3], splits [4], accountscmdline.UserName,
                                                               accountscmdline.AccountNumber);
                        bool alreadyadded = _shareentries.AddShareEntry(shareentry, true);
                        Console.WriteLine((alreadyadded ? "Existing Ticker " : "New Ticker ") + shareentry._ticker + " has a ticker id of " + shareentry._tickerid);
                    }
                }

                Console.WriteLine("Updating Database");
                UpdateDatabase_shares(accountscmdline);
            }
            finally
            {
                dbmanager.CloseConnections();
            }
        }