public bool AlternateProduct(OpenRatesBlotter ORBlotter, TimeFrame TFrame, int count, string product, ref int shift, ref int shiftAlternative, int maxShift, ref string alternative, ref string counterAlternative) { List <string> LSProd = ARCHIVE.GetProducts(); int iLCPCount = ARCHIVE.GetDATACount(TFrame, product); int iLastPoints = count; int iStartIdx = iLCPCount - iLastPoints; Rates RATE = ORBlotter.Get(product); int iDecimals = RATE.Decimals; double dBestCompare = double.MinValue; double dWorstCompare = double.MaxValue; alternative = counterAlternative = ""; foreach (string sP in LSProd) { if (sP == product) { continue; } Rates RATESecond = ORBlotter.Get(sP); int iDecimalsSecond = RATESecond.Decimals; int iLCPCountSecondary = ARCHIVE.GetDATACount(TFrame, sP); List <ChartPoint> LCPPrimary = ARCHIVE.GetDATA(TFrame, product, iStartIdx, iLastPoints); List <ChartPoint> LCPSecondary = ARCHIVE.GetDATA(TFrame, sP, iLCPCountSecondary - iLastPoints, iLastPoints); int iShift = 0; double dCompaison = this.CompareCharts(LCPPrimary, LCPSecondary, iDecimals, iDecimalsSecond, maxShift, ref iShift); if (dCompaison > dBestCompare) { dBestCompare = dCompaison; alternative = sP; shift = iShift; } if (dCompaison < dWorstCompare) { dWorstCompare = dCompaison; counterAlternative = sP; shiftAlternative = iShift; } } if (shift != 0 || alternative == "" || counterAlternative == "") { return(false); } else { return(true); } }
public double ConvertToUSD(string PRODUCT, bool BUY, double amount) { //Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB"); var SETTINGS = OSBlotter.Get(PRODUCT); string sPrimary = PRODUCT.Substring(0, 3); string sSecondary = PRODUCT.Substring(4, 3); string sContract = SETTINGS.ContractProduct; string sCounter = SETTINGS.CounterProduct; double dContractRate = 0; double dCost; if (sContract == sCounter && sSecondary == "USD") { return(Math.Round(amount, 2)); } Rates RATE_Counter = ORBlotter.Get(sCounter); if (RATE_Counter == null) { return(double.NaN); } if (BUY) { dContractRate = RATE_Counter.ASK; } else { dContractRate = RATE_Counter.BID; } dCost = amount / dContractRate; return(Math.Round(dCost, 2)); }
public List <string> GetLiquids(List <string> LSProducts, OpenRatesBlotter ORBlotter, double minPercentage, int deep, double spreadFactor, TimeFrame TFrame) { List <string> LSLiquidProducts = new List <string>(); foreach (string product in ARCHIVE.GetProducts()) { Rates RATE = ORBlotter.Get(product); int iMinutesFrame = ABBREVIATIONS.ToMinutes(TFrame); List <ChartPoint> LCPoints = ARCHIVE.GetDATA(TFrame, product); DateTime DTLast100 = ABBREVIATIONS.GreenwichMeanTime.AddMinutes(-deep * iMinutesFrame); List <ChartPoint> LCPLast100 = (from CP in LCPoints where CP.Time > DTLast100 select CP).ToList(); if (this.LiquidPercentage(LCPLast100, RATE, spreadFactor) > minPercentage) { LSLiquidProducts.Add(product); } } return(LSLiquidProducts); }
private bool Action(string PRODUCT, bool BUY) { if (!OSBlotter.IsLoaded) { return(false); } Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB"); var SETTINGS = OSBlotter.Get(PRODUCT); // CEDC_Configuration.GetProductSetting(TOKEN, PRODUCT); //Product settings - minimum lot etc //var b5 = CEDT_TreadingService.GetPositionBlotter(TOKEN); //Summary position for all currencies - all positions int OrderSize = int.Parse(SETTINGS.OrderSize); if (PRODUCT == "XAU/USD") { OrderSize *= 10; } DealResponse INFO; // double cost = this.ToUSD(PRODUCT, BUY, OrderSize); string Rate; string BuySell; if (BUY) { BuySell = "B"; } else { BuySell = "S"; } bool bDealSucced = true; int timeout; Rates RATE = ORBlotter.Get(PRODUCT); do { timeout = 0; if (BUY) { Rate = ABBREVIATIONS.ToString(RATE.ASK, RATE.Decimals); // BID.ToString(); } else { Rate = ABBREVIATIONS.ToString(RATE.BID, RATE.Decimals); //ASK.ToString(); } INFO = CEDT_TreadingService.InstantExecution(TOKEN, PRODUCT, BuySell, OrderSize.ToString(), Rate, ACCOUNT.OpeningHazard); // var INFO = CEDT_TreadingService.DealRequest(TOKEN, PRODUCT, BuySell, OrderSize.ToString(), Rate); //quick // CEDT_TreadingService.DealRequestAtBest(TOKEN, PRODUCT, BuySell, "100000"); //execute whatever but slow if (INFO.ErrorNo != "") { timeout = RATE.WaitForUpdate(2000); if (timeout < 0) { TsslInfo.Text = "Rate does not changed in 2s, Timeout Error !"; bDealSucced = false; break; } else { TsslInfo.Text = "Time needed for rate to update: " + timeout + " [ms]"; } } } while (timeout != 0); if (bDealSucced) { this.UpdateDeals(); Deals DEAL = ODBlotter.Get(INFO.dealId); if (DEAL != null) { double dPipValue = Math.Pow(10, -RATE.Decimals); DEAL.BID = RATE.BID; DEAL.ASK = RATE.ASK; ODBlotter.Add(DEAL); } this.UpdateAccount(); } return(bDealSucced); }
public bool Rates(List <string> SLDecodedData, ref OpenRatesBlotter ORBlotter) { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB"); bool ResponseRecived = false; int count = SLDecodedData.Count; int KEY = -1; bool BlockFound = false; bool UpdateFound = false; int position = -1; int i; for (i = 0; i < count; i++) { string PART = SLDecodedData[i]; int length = PART.Length; BlockFound = false; UpdateFound = false; if (PART.Contains("BUP") || PART.Contains("DEAL") || PART.Contains("ORD")) { } if ((position = PART.IndexOf("\r")) >= 0) { PART = PART.Substring(position + 1, length - (position + 1)); length = PART.Length; ResponseRecived = true; } if (length == 0) { continue; } if (!(PART.Contains("/") && length == 7) && (PART[0] == 'S' || PART[0] == '$' || PART[0] == 'R')) //Delimiters !PART.Contains("/") && { string SUB = PART.Substring(1, length - 1); int CCY_Token = int.Parse(SUB); if (PART.Contains("R")) { UpdateFound = true; } else { BlockFound = true; } KEY = CCY_Token; } if (BlockFound) { if (SLDecodedData.Count <= (i + 9)) { break; } Rates RATE = new AsmodatForexEngineAPI.Rates(); RATE.CCY_Token = KEY; RATE.CCY_Pair = SLDecodedData[i + 1]; RATE.BID = double.Parse(SLDecodedData[i + 2]); RATE.ASK = double.Parse(SLDecodedData[i + 3]); RATE.HIGH = double.Parse(SLDecodedData[i + 4]); RATE.LOW = double.Parse(SLDecodedData[i + 5]); RATE.Dealable = false; RATE.American = false; if (SLDecodedData[i + 6] == "D") { RATE.Dealable = true; } if (SLDecodedData[i + 7] == "A") { RATE.American = true; } RATE.Decimals = int.Parse(SLDecodedData[i + 8]); RATE.CLOSE = double.Parse(SLDecodedData[i + 9]); ORBlotter.Add(RATE); i += 9; } else if (UpdateFound) { if (SLDecodedData.Count <= (i + 4)) { break; } double BID = double.Parse(SLDecodedData[i + 1]); double ASK = double.Parse(SLDecodedData[i + 2]); bool Dealable = false; if (SLDecodedData[i + 3] == "D") { Dealable = true; } DateTime Time; try { Time = DateTime.ParseExact(SLDecodedData[i + 4], "MM/dd/yyyy HH:mm:ss", null);// "02/06/2014 11:39:01" } catch { try { Time = DateTime.ParseExact(SLDecodedData[i + 9], "MM/dd/yyyy HH:mm:ss", null);// "02/06/2014 11:39:01" } catch { i += 1; break; } } Rates RATE = ORBlotter.Get(KEY); RATE.BID = BID; RATE.ASK = ASK; RATE.Dealable = Dealable; RATE.Time = Time; ORBlotter.Add(RATE); i += 4; } } return(ResponseRecived); }