public void TestServiceConnection() { var issues = "T"; var identifierType = "MLPTicker"; var criteriaType = "Term"; var criteriaValue = string.Empty; var liveAsOfDate = DateTime.Today.AddDays(30); var moniker = new Moniker { Close = Moniker.sStatic, Source = Moniker.sOfficial, Date = liveAsOfDate == DateTime.FromOADate(0) ? null : (DateTime?)liveAsOfDate, Name = String.Format("{0}|{1}|{2}|{3}", issues.Trim(), identifierType.Trim(), string.IsNullOrWhiteSpace(criteriaType) ? String.Empty : criteriaType.Trim().ToLower(), string.IsNullOrWhiteSpace(criteriaValue) ? String.Empty : criteriaValue.Trim().ToLower()), Type = "bondlist" }; var symwcfClient = setupServiceClient(); var symObject = symwcfClient.GetSingleObject(moniker.ToString()); GenericTable result = symObject.Xml.DeserializeObject<GenericTable>(); ((IClientChannel)symwcfClient).Close(); }
public void ShouldGetSingleSecurityMetadata() { var instrument = "T 0.375 02/15/2016"; var liveAsOfDate = DateTime.Today.AddDays(30); var moniker = new Moniker { Close = Moniker.sStatic, Source = Moniker.sOfficial, Date = null, Name = instrument.Trim(), Type = "bondstatic" }; var symwcfClient = setupServiceClient(); var symObject = symwcfClient.GetSingleObject(moniker.ToString()); var result = symObject.Xml.DeserializeObject<BondStatic>(); ((IClientChannel)symwcfClient).Close(); }
//---------------------------------------------------------------------------------------- public static BondStatic GetBondStatic(string bondID) //---------------------------------------------------------------------------------------- { Log_.InfoFormat("Getting bond static for {0}", bondID); if (bondStaticCache.ContainsKey(bondID)) return bondStaticCache[bondID]; BondStatic instrumentStatic = new BondStatic(); int MAX_RETRIES = 5; int retries = 0; for (retries = 0; retries < MAX_RETRIES; ++retries) { try { var moniker = new Moniker { Close = Moniker.sStatic, Source = Moniker.sOfficial, Date = null, Name = bondID.Trim(), Type = "bondstatic" }; var symmetryServiceClient = GetSymmetryServiceClient(); var resultObj = symmetryServiceClient.GetSingleObject(moniker.ToString()); instrumentStatic = resultObj.Xml.DeserializeObject<BondStatic>(); break; } catch (Exception e) { Log_.WarnFormat("Attempt" + retries.ToString() + " - Error in setting static for " +bondID + ": " + e.Message); Thread.Sleep(200); // Wait for 2 seconds first before trying again } } if (retries == MAX_RETRIES) { throw new TimeoutException("Max retries reach " + MAX_RETRIES + ". Giving up on pulling bond static"); } // Set cache bondStaticCache[bondID] = instrumentStatic; return instrumentStatic; }
//---------------------------------------------------------------------------------------- public static List<string> GetAllSecurities(string issues, string criteriaType, DateTime asOfDate) //---------------------------------------------------------------------------------------- { try { //var issues = "T"; var identifierType = "MLPTicker"; //var criteriaType = "Term"; var criteriaValue = string.Empty; var moniker = new Moniker { Close = Moniker.sStatic, Source = Moniker.sOfficial, Date = asOfDate == DateTime.FromOADate(0) ? null : (DateTime?) asOfDate, Name = String.Format("{0}|{1}|{2}|{3}", issues.Trim(), identifierType.Trim(), string.IsNullOrWhiteSpace(criteriaType) ? String.Empty : criteriaType.Trim().ToLower(), string.IsNullOrWhiteSpace(criteriaValue) ? String.Empty : criteriaValue.Trim().ToLower()), Type = "bondlist" }; // go to symmetry service //var symmetryServiceClient = new SymmetryServiceClient(); var resultObj = symmetryServiceClient.GetSingleObject(moniker.ToString()); GenericTable result = resultObj.Xml.DeserializeObject<GenericTable>(); var allBondMatrix = result.Table.AsStringArray(); List<string> bonds = new List<string>(); for (int i = 0; i < allBondMatrix.GetLength(0); i++) { bonds.Add( allBondMatrix[i, 0]); } return bonds; } catch (Exception e) { Log_.ErrorFormat("Error found in loading all issues : {0}", e.Message); throw e; } }
//---------------------------------------------------------------------------------------- public static GenericPrice GetHistoryPrice( string inst, DateTime asof, string closeSnap, string source ) //---------------------------------------------------------------------------------------- { try { var moniker = new Moniker { Type = "genericprice", Close = closeSnap, Source = source, Date = asof, Name = inst.ToLower().Trim() }; // go to symmetry service //var symmetryServiceClient = new SymmetryServiceClient(); var resultObj = symmetryServiceClient.GetSingleObject(moniker.ToString()); GenericPrice result = null; if (!string.IsNullOrEmpty(resultObj.Xml)) result = resultObj.Xml.DeserializeObject<GenericPrice>(); return result; } catch (Exception) { Log_.ErrorFormat("Can't find {0}, for {1} {2} at {3}", inst, source, closeSnap, asof.ToString() ); } return null; }