public FrmFillDownload() { var hourago = TT_Info.ToRestTimestamp(DateTime.UtcNow - new TimeSpan(1, 0, 0)); InitializeComponent(); InitializeColumnList(); clbColumns.Items.Clear(); foreach (FillColumn column in m_TradePaneColumns) { clbColumns.Items.Add(column, true); } this.FormClosing += FrmFillDownload_FormClosing; cbFileMode.DataSource = Enum.GetValues(typeof(FileMode)); LoadSettings(); this.DragOver += FrmFillDownload_DragOver; this.DragDrop += Debug_DragDrop; FDLog.LogMessage("Starting up C# Fill Downloader v0.0.1"); }
private void DownloadFills() { // Perform REST request/response to download fill data, specifying our cached minimum timestamp as a starting point. // On a successful response the timestamp will be updated so we run no risk of downloading duplicate fills. List <TT_Fill> fills = new List <TT_Fill>(); do { var min_param = new RestSharp.Parameter("minTimestamp", TT_Info.ToRestTimestamp(m_minTimeStamp).ToString(), RestSharp.ParameterType.QueryString); RestSharp.IRestResponse result = RestManager.GetRequest("ledger", "fills", min_param); if (result.StatusCode != System.Net.HttpStatusCode.OK) { throw new Exception("Request for fills unsuccessful. Status:" + result.StatusCode.ToString() + "Error Message: " + result.ErrorMessage); } JObject json_data = JObject.Parse(result.Content); foreach (var fill in json_data["fills"]) { fills.Add(new TT_Fill(fill)); } fills.Sort((f1, f2) => f1.UtcTimeStamp.CompareTo(f2.UtcTimeStamp)); RaiseFillDownloadEvent(fills); if (fills.Count > 0 && m_running) { m_minTimeStamp = new DateTime(fills[fills.Count - 1].UtcTimeStamp.Ticks + 1); } }while (fills.Count == TT_Info.MAX_RESPONSE_FILLS); }
private static DateTime FromRestTimestamp(string TT_TimeStamp) { long ticks = long.Parse(TT_TimeStamp); return(TT_Info.FromRestTimestamp(ticks)); }
private void DownloadFills() { // Perform REST request/response to download fill data, specifying our cached minimum timestamp as a starting point. // On a successful response the timestamp will be updated so we run no risk of downloading duplicate fills. bool should_continue = false; List <TT_Fill> fills = new List <TT_Fill>(); do { should_continue = false; var min_param = new RestSharp.Parameter("minTimestamp", TT_Info.ToRestTimestamp(m_minTimeStamp).ToString(), RestSharp.ParameterType.QueryString); RestSharp.IRestResponse result = RestManager.GetRequest("ledger", "fills", min_param); if (result.StatusCode == System.Net.HttpStatusCode.GatewayTimeout) { should_continue = true; DateTime max_time = DateTime.Now; int retry_count = 0; for (retry_count = 0; retry_count < max_retries; ++retry_count) { FDLog.LogMessage("Fill request timed out. Retrying...."); max_time = m_minTimeStamp + TimeSpan.FromTicks((max_time - m_minTimeStamp).Ticks / 2); var max_param = new RestSharp.Parameter("maxTimestamp", TT_Info.ToRestTimestamp(max_time).ToString(), RestSharp.ParameterType.QueryString); result = RestManager.GetRequest("ledger", "fills", min_param, max_param); if (result.StatusCode == System.Net.HttpStatusCode.OK) { m_minTimeStamp = max_time; break; } else if (result.StatusCode != System.Net.HttpStatusCode.GatewayTimeout) { throw new Exception(String.Format("Request for fills unsuccessful. (minTimestamp={0}) - Status: {1} - Error Message: {2}", min_param.Value.ToString(), result.StatusCode.ToString(), result.ErrorMessage)); } if (retry_count == max_retries) { throw new Exception("Request for fills unsuccessful. Max Retries exceeded."); } } } else if (result.StatusCode != System.Net.HttpStatusCode.OK) { throw new Exception(String.Format("Request for fills unsuccessful. (minTimestamp={0}) - Status: {1} - Error Message: {2}", min_param.Value.ToString(), result.StatusCode.ToString(), result.ErrorMessage)); } JObject json_data = JObject.Parse(result.Content); FDLog.LogMessage(String.Format("Downloaded {0} fills.", json_data["fills"].Count())); foreach (var fill in json_data["fills"]) { fills.Add(new TT_Fill(fill)); } fills.Sort((f1, f2) => f1.UtcTimeStamp.CompareTo(f2.UtcTimeStamp)); RaiseFillDownloadEvent(fills); if (fills.Count > 0) { m_minTimeStamp = new DateTime(fills[fills.Count - 1].UtcTimeStamp.Ticks + 1); } should_continue |= (fills.Count == TT_Info.MAX_RESPONSE_FILLS); should_continue &= m_running; }while (should_continue); }