public void StartEventActions() { foreach (var ea in _EventActionsToStart) { switch (ea.EventActionType) { case EventActionType.MovingAverage: MovingAverageManager.InitEmaBySma(ea.EventActionId); ea.Action = MovingAverageManager.UpdateEma; break; case EventActionType.TradeSignal: var currencyPair = ea.TradeSignalEventAction.CurrencyPair; var tradeSignalConfiguration = ea.TradeSignalEventAction.TradeSignalConfiguration; TradeSignalManager.InitProcessEmaCrossOverSignal(currencyPair, tradeSignalConfiguration); ea.Action = TradeSignalManager.ProcessEmaCrossOverSignal; break; case EventActionType.ProcessTradeOrder: ea.Action = TradeOrderManager.ProcessTradeOrders; break; } var globalStateEvent = _globalStateManager.GetTaskLoop(ea.TaskId); var eventActions = globalStateEvent.Item3; ea.EventActionStatus = EventActionStatus.Started; using (var db = new PoloniexContext()) { db.Entry(ea).State = EntityState.Modified; db.SaveChanges(); } eventActions.Add(ea); Logger.Write($"Started {ea.EventActionType} with eventActionId: {ea.EventActionId}", Logger.LogType.ServiceLog); } }
public void StopTasks() { foreach (var taskLoop in _tasksToStop) { switch (taskLoop.Task.TaskType) { case "GatherTask": var tuple = _globalStateManager.RemoveTaskLoop(taskLoop.TaskId); tuple.Item2.Stop(); // stop timer (Item2 is timer) using (var db = new PoloniexContext()) { taskLoop.LoopStatus = LoopStatus.Stopped; db.Entry(taskLoop).State = EntityState.Modified; db.SaveChanges(); } var eventActions = tuple.Item3; foreach (var ea in eventActions) { ea.EventActionStatus = EventActionStatus.Stopped; using (var db = new PoloniexContext()) { db.Entry(ea).State = EntityState.Modified; db.SaveChanges(); } Logger.Write($"Stopped {ea.EventActionType} with eventActionId: {ea.EventActionId}", Logger.LogType.ServiceLog); } Logger.Write($"Stopped {taskLoop.Task.TaskType} with taskId: {taskLoop.TaskId}", Logger.LogType.ServiceLog); break; } } }
public void StartTasks() { foreach (var taskLoop in _tasksToStart) { switch (taskLoop.Task.TaskType) { case "GatherTask": System.Threading.Tasks.Task.Run(() => { try { GatherTaskManager.BackFillGatherTaskData(6, taskLoop.Task.GatherTask.CurrencyPair, null, DateTime.Parse("01/01/1970")); } catch (Exception exception) { Logger.WriteException(exception); } }); var eventActions = new List <EventAction>(); _globalStateManager.AddTaskLoop(taskLoop, GatherTaskManager.GetGatherTaskTimer(taskLoop.TaskId, eventActions), eventActions); using (var db = new PoloniexContext()) { taskLoop.LoopStatus = LoopStatus.Started; taskLoop.LoopStartedDateTime = DateTime.UtcNow; db.Entry(taskLoop).State = EntityState.Modified; db.SaveChanges(); } Logger.Write($"Started {taskLoop.Task.TaskType} with taskId: {taskLoop.TaskId}", Logger.LogType.ServiceLog); break; } } }
public static void ProcessTradeOrders(Guid eventActionId) { using (var db = new PoloniexContext()) { var currencyPair = db.EventActions.Single(x => x.EventActionId == eventActionId).TradeOrderEventAction.CurrencyPair; // get oldest uncompleted order var oldest = db.TradeSignalOrders .Where(x => x.CurrencyPair == currencyPair && !x.IsProcessed) .OrderBy(x => x.OrderRequestedDateTime) .FirstOrDefault(); if (oldest != null) { Logger.Write($"Processing TradeSignalOrderId: {oldest.TradeSignalOrderId} for eventActionId: {eventActionId}", Logger.LogType.TransactionLog); oldest.IsProcessed = true; oldest.InProgress = true; db.Entry(oldest).State = EntityState.Modified; db.SaveChanges(); if (oldest.TradeOrderType == TradeOrderType.Buy) { TradeManager.BuyCurrencyFromUsdt(currencyPair, ref oldest); } else { TradeManager.SellCurrencyToUsdt(currencyPair, ref oldest); } oldest.OrderCompletedDateTime = DateTime.UtcNow; oldest.InProgress = false; oldest.ProcessedByEventActionId = eventActionId; db.Entry(oldest).State = EntityState.Modified; db.SaveChanges(); } }; }
public void StopEventActions() { foreach (var ea in _EventActionsToStop) { var globalStateEvent = _globalStateManager.GetTaskLoop(ea.TaskId); var eventActions = globalStateEvent.Item3; for (int i = 0; i < eventActions.Count; i++) { if (eventActions[i].EventActionId == ea.EventActionId) { eventActions.RemoveAt(i); break; } } ea.EventActionStatus = EventActionStatus.Stopped; using (var db = new PoloniexContext()) { db.Entry(ea).State = EntityState.Modified; db.SaveChanges(); } Logger.Write($"Stopped {ea.EventActionType} with eventActionId: {ea.EventActionId}", Logger.LogType.ServiceLog); } }