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(); } }
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); const string GENERICTICKS = "100,101,104,105,106,107,165,221,225,233,236,258"; _usdmarket_isl = new IBSpecifics("STK", "SMART", EXCHANGE_ISLAND, "USD", "", "", "", GENERICTICKS); _usdmarket_arca = new IBSpecifics("STK", "SMART", EXCHANGE_ARCA, "USD", "", "", "", GENERICTICKS); _usdmarket_nyse = new IBSpecifics("STK", "SMART", EXCHANGE_NYSE, "USD", "", "", "", GENERICTICKS); _cadmarket_tsx = new IBSpecifics("STK", "SMART", EXCHANGE_TSE, "CAD", "", "", "", GENERICTICKS); _cadmarket_ven = new IBSpecifics("STK", "SMART", EXCHANGE_VENTURE, "CAD", "", "", "", GENERICTICKS); _gbpmarket = new IBSpecifics("STK", "SMART", EXCHANGE_LONDON, "GBP", "", "", "", GENERICTICKS); _usdmarket_nasdaq = new IBSpecifics("STK", "SMART", EXCHANGE_NASDAQ, "USD", "", "", "", GENERICTICKS); Dictionary <string, bool> _donetickers = new Dictionary <string, bool> (); List <string> fields = Fields.CollateFields(startindex, true, args); if (fields == null || fields.Count == 0) { return; } // format is [tickerid,sharestartprice,shareendprice,gap,selloffset,numberbuyshares,pgenfilename] or [delete] bool deletepgenfields = false; foreach (string input in fields) { string [] splits = input.Split(','); if (splits.Length == 7) { #region "pgen" string tickerid = splits [0]; if (!_donetickers.ContainsKey(tickerid)) { List <string> allfields = new List <string> (); _donetickers [tickerid] = true; for (int i = 0; i < fields.Count; i++) { splits = fields [i].Split(','); if (splits.Length == 7) { if (splits [0] == tickerid) { allfields.Add(fields [i]); } } } ShareEntry shareentry; if (_shareentries._shareentries.TryGetValue(tickerid, out shareentry)) { string xmlfile = null; List <PGenEntry []> pgenentries = new List <PGenEntry []> (); foreach (string allfield in allfields) { try { splits = allfield.Split(','); IBSpecifics ibspecs = null; if (String.Compare(shareentry._primaryexchange, EXCHANGE_ISLAND, true) == 0) { ibspecs = _usdmarket_isl; } else if (String.Compare(shareentry._primaryexchange, EXCHANGE_ARCA, true) == 0) { ibspecs = _usdmarket_arca; } else if (String.Compare(shareentry._primaryexchange, EXCHANGE_NYSE, true) == 0) { ibspecs = _usdmarket_nyse; } else if (String.Compare(shareentry._primaryexchange, EXCHANGE_TSE, true) == 0) { ibspecs = _cadmarket_tsx; } else if (String.Compare(shareentry._primaryexchange, EXCHANGE_VENTURE, true) == 0) { ibspecs = _cadmarket_ven; } else if (String.Compare(shareentry._primaryexchange, EXCHANGE_LONDON, true) == 0) { ibspecs = _gbpmarket; } else if (String.Compare(shareentry._primaryexchange, EXCHANGE_NASDAQ, true) == 0) { ibspecs = _usdmarket_nasdaq; } if (ibspecs != null) { decimal lower = decimal.Parse(splits [1]); decimal upper = decimal.Parse(splits [2]); decimal gap = decimal.Parse(splits [3]); decimal offset = decimal.Parse(splits [4]); int numbershares = int.Parse(splits [5]); PGenEntry [] pgenentry = CreatePGenSetRange(shareentry, lower, upper, gap, offset, numbershares, numbershares, ibspecs); if (pgenentry != null) { pgenentries.Add(pgenentry); if (xmlfile == null) { xmlfile = splits [6]; } } } } catch (Exception) { } } if (xmlfile != null) { shareentry._pgenfilename = xmlfile; CreatePGen(accountscmdline, shareentry, xmlfile, MergePGenSets(pgenentries.ToArray()) ); } } } #endregion } else if (splits.Length == 1) { #region "delete flag?" if (string.Compare(splits [0], "delete", true) == 0) { deletepgenfields = true; } #endregion } } UpdateDatabase_pgens(accountscmdline, deletepgenfields); } finally { dbmanager.CloseConnections(); } }
bool Go(pcmdsupport.ParseDBCMDLine dbcmdline, pcmdsupport.ParseAccountsCMDLine accountscmdline, string tickeridstr) { try { int tickerid; if (!int.TryParse(tickeridstr, out tickerid)) { return(true); } _mysqlconnection = dbmanager.GetDBConnection(dbcmdline.UserName, dbcmdline.Pwd, dbcmdline.Schema, dbcmdline.Hostname); /* * ibrokers.deals (Table) * ======================= * iddeals int(10) unsigned PK * tickerid int(11) * ticker text * oi int(11) * maxoi int(11) * buyprice double * numberbuyshares int(11) * sellprice double * numbersellshares int(11) * sectype text * exchange text * primaryexchange text * currency text * localsymbol text * secidtype text * secid text * genericticks text * displayname text * username text * accountnumber text * hitcount int(11) * lastavgfillbuyprice double * lastbuycommission double * lastbuydate datetime * updatetimestamp timestamp */ string username = accountscmdline.UserName; string accountnumber = accountscmdline.AccountNumber; StringBuilder sb = new StringBuilder("select iddeals,tickerid,ticker,oi from deals where tickerid = "); sb.Append(tickerid.ToString()); sb.Append(" and username = '******' and accountnumber = '"); sb.Append(accountnumber); sb.Append("'"); MySqlCommand mysqlcommand = new MySqlCommand(sb.ToString(), _mysqlconnection); mysqlcommand.CommandTimeout = dbconnection.DBConnectionManager.DATABASE_TIMEOUT; MySqlDataReader mysqlreader = mysqlcommand.ExecuteReader(); int numberofrows = 0; List <ulong> rowswith_open_oi = new List <ulong> (); string assumed_ticker = null; while (mysqlreader.Read()) { ulong iddeals = mysqlreader.GetUInt64(0); int rowtickerid = mysqlreader.GetInt32(1); string rowticker = mysqlreader.GetString(2); int rowoi = mysqlreader.GetInt32(3); if (rowoi > 0) { rowswith_open_oi.Add(iddeals); } if (numberofrows == 0) { assumed_ticker = rowticker; } numberofrows++; } mysqlreader.Close(); if (rowswith_open_oi.Count > 0) { Console.WriteLine(assumed_ticker + " has " + rowswith_open_oi.Count.ToString() + " rows with Open Interest"); } Console.WriteLine("Do you want to delete ticker " + assumed_ticker + "?"); string reply = Console.ReadLine(); if (reply == "y" || reply == "Y") { Console.WriteLine("Answer is Yes, deleting..."); MySqlTransaction mysqltransaction = null; mysqlcommand = null; try { mysqltransaction = _mysqlconnection.TheDBConnection.BeginTransaction(); mysqlcommand = _mysqlconnection.TheDBConnection.CreateCommand(); mysqlcommand.Connection = _mysqlconnection.TheDBConnection; mysqlcommand.Transaction = mysqltransaction; sb = new StringBuilder("delete from deals where tickerid = "); sb.Append(tickerid.ToString()); sb.Append(" and username = '******' and accountnumber = '"); sb.Append(accountnumber); sb.Append("'"); mysqlcommand.CommandText = sb.ToString(); mysqlcommand.Parameters.Clear(); mysqlcommand.ExecuteNonQuery(); mysqltransaction.Commit(); } catch (Exception e) { Console.WriteLine("Delete failed with " + e.Message); try { if (mysqltransaction != null) { mysqltransaction.Rollback(); } } catch { } if (e is System.Threading.ThreadAbortException) { throw; } } Console.WriteLine("Deleted"); } else { Console.WriteLine("Answer is NO"); } } finally { dbmanager.CloseConnections(); } return(false); }