// Покупка 123 XRP по 0.00123 выставлена // Стоп-лосс 123 XRP по 0.0100 выставлен // Тейк-профит 60 XRP по 0.00140 выставлен // Завершено // Остановлено // Паник селл private string BuildStatusString(TradeTask tt, OrderTask job) { string action = "Остановлено"; switch (job.Kind) { case OrderKind.Buy: action = "Покупка"; break; case OrderKind.StopLoss: action = "Стоп лосс"; break; case OrderKind.TakeProfit: action = "Тейк профит"; break; case OrderKind.PanicSell: action = "Паник селл"; break; } var si = GetSymbolInformation(tt.Symbol); return($"{action} {job.Quantity} {si.BaseAsset} по {job.Price} {si.QuoteAsset} {OrderStatusToDisplayStringRus(job.ExchangeOrder.Status)}"); }
protected async Task <bool> PanicSell(TradeTask tt) { try { await tt.locker.WaitAsync(); // there could be BUY or SL orders running. cancell all them first. var result = await CancellAllOrders(tt); tt.Jobs.ForEach(x => tt.FinishedJobs.Enqueue(x)); tt.Jobs.Clear(); if (tt.Qty > 0) { var sellJob = new OrderTask() { Symbol = tt.Symbol, Type = OrderType.MARKET, Kind = OrderKind.PanicSell, Side = TradeSide.Sell, Quantity = tt.Qty }; tt.Jobs.Insert(0, sellJob); } TradeTaskViewModel.SerializeModel(tt); return(result); } finally { tt.locker.Release(); } }
private static bool IsActiveJob(OrderTask x) { if (x == null) { return(false); } return((x.ExchangeOrder?.Status == OrderStatus.Active || x.ExchangeOrder?.Status == OrderStatus.PartiallyFilled) || (x.OrderId != null && x.ExchangeOrder == null)); }
public TakeProfitViewModel(TradeTaskViewModel tt, OrderTask model, TakeProfitViewModel prev = null) : base(tt, model) { Previous = prev; if (Previous != null) { qtyPercentStart = Previous.QuantityPercentEnd; } qtyPercentEnd = qtyPercentStart + model.QuantityPercent; ConnectProperties(); }
public OrderTaskViewModel(TradeTaskViewModel tt) { Model = new OrderTask(); TradeTask = tt; // TODO: OBPH this.WhenAnyValue(x => x.Price, x => x.Quantity, (rate, qty) => rate * qty) .ToPropertyEx(this, vm => vm.Total); this.WhenAnyValue(x => x.Price) .Subscribe(x => Model.Price = x); this.WhenAnyValue(x => x.Quantity) .Subscribe(x => Model.Quantity = x); }
public OrderTaskViewModel(TradeTaskViewModel tt, OrderTask model) { Model = model; TradeTask = tt; Price = model.Price; Quantity = model.Quantity; this.WhenAnyValue(x => x.Price, x => x.Quantity, (rate, qty) => rate * qty) .ToPropertyEx(this, vm => vm.Total); this.WhenAnyValue(x => x.Price) .Subscribe(x => Model.Price = x); this.WhenAnyValue(x => x.Quantity) .Subscribe(x => Model.Quantity = x); }
protected override async Task <Order> ExecuteOrder(OrderTask job) { var result = await client.PlaceOrderAsync( job.Symbol, job.Side == TradeSide.Buy?Binance.TradeSide.BUY : Binance.TradeSide.SELL, Convert(job.Type), job.Quantity, job.Type == OrderType.LIMIT || job.Type == OrderType.STOP_LIMIT?job.Price : default(decimal?), job.Type == OrderType.STOP_LIMIT?job.Price : default(decimal?) ).ConfigureAwait(false); if (result.Success) { return(Convert(result.Data)); } else { throw new ApiException(result.Error); } }
protected async override Task <Order> GetOrder(OrderTask job) { // don't f**k the brain! if (job.ExchangeOrder?.Status == OrderStatus.Filled) { return(job.ExchangeOrder); } var apiResult = await client.QueryOrderAsync(job.Symbol, long.Parse(job.OrderId)).ConfigureAwait(false); if (apiResult.Success) { var result = Convert(apiResult.Data); if (job.ExchangeOrder == null || result.Updated > job.ExchangeOrder.Updated) { result.Fills.AddRange(await GetOrderTrades(result)); } return(result); } else { throw new ApiException(apiResult.Error); } }
protected virtual Task <Order> ExecuteOrder(OrderTask tt) { return(Task.FromResult <Order>(null)); }
protected virtual Task <bool> CancelOrder(OrderTask order) { return(Task.FromResult(false)); }
//protected virtual Task<Order> GetOrder(Order order) //{ // return Task.FromResult<Order>(null); //} protected virtual Task <Order> GetOrder(OrderTask job) { return(Task.FromResult <Order>(null)); }
protected async override Task <bool> CancelOrder(OrderTask task) { var result = await client.CancelOrderAsync(task.Symbol, long.Parse(task.ExchangeOrder.OrderId)); return(result.Success); }