public async Task <Object> ReserveCar(CarReservationInfo info) { string userId = ""; User user = new User(); await Task.Run(() => { userId = User.Claims.First(c => c.Type == "UserID").Value; user = _dataBase.Users.Include(u => u.ReservedCars).ToList().Find(u => u.UserName == userId); }); if (user == null || user.Role != "ru") { return(Unauthorized()); } var vehicle = new Vehicle(); await Task.Run(() => { vehicle = _dataBase.Vehicles.Include(v => v.DatesTaken).Include(v => v.SpecialOfferDates).ToList().Find(v => v.Id == info.VehicleID); }); if (vehicle == null) { return(BadRequest("Vehicle doesn't exist")); } var listOfDates = new List <DateTime>(); for (var d = DateTime.Parse(info.StartDate); d <= DateTime.Parse(info.EndDate); d = d.AddDays(1)) { if (info.SpecialOffer ? Classes.DatesManipulator.ExistsInList(vehicle.SpecialOfferDates.ToList(), d) : Classes.DatesManipulator.ExistsInList(vehicle.DatesTaken.ToList(), d)) { return(BadRequest("Car is not avaible in selected dates")); } listOfDates.Add(d); } var reservation = new CarReservation() { User = user.UserName, Rated = false, EndDate = DateTime.Parse(info.EndDate), StartDate = DateTime.Parse(info.StartDate), SpecialOffer = info.SpecialOffer, PricePerDay = info.PricePerDay, TotalPrice = info.TotalPrice, VehicleID = info.VehicleID }; await Task.Run(() => { listOfDates.ForEach(d => vehicle.DatesTaken.Add(new Date() { DateTime = d })); user.ReservedCars.Add(reservation); vehicle.DatesTaken.ToList().Sort(new DateListSort()); _dataBase.SaveChanges(); var rent = _dataBase.Rentacars.Include(r => r.ProfitList).ToList().Find(r => r.Id == vehicle.RentacarID); var profit = new Profit() { RentacarID = rent.Id, EarnedMoney = reservation.TotalPrice, CarReservationID = reservation.Id, DateTransactionWasMade = DateTime.Now }; rent.ProfitList.Add(profit); _dataBase.SaveChanges(); }); return(Ok(reservation)); }
void Update() { distanceText.text = Distance.ToString() + "m"; profitText.text = "$" + Profit.ToString(); }
private void MinuteCandleByTicks() { // 설정값 var coinName = Coin.Ticker; var candleType = CandleType.Name; var candleCount = CandleCount; var feeRate = FeeRate; var tradeRate = TradeRate; var triggerRate = TriggerRate; // 해당 코인 보유금액이 있으면 매도 없으면 매수 var candles = ApiData.getCandle <List <Candle> >(coinName, candleType, candleCount); // 캔들 조회 var currCandle = candles.First(); // 현재 캔들 var currPrice = currCandle.Close; // 현재가 //var orderChance = GetOrderChance(ApiData, coinName, currPrice); // 주문 가능 정보 var orderChance = new Profit(ApiData, coinName, StartKRW); var coinPrice = orderChance.CoinVol; // 코인 보유금 var krwBalance = orderChance.KRWBalance; // 보유 현금 var coinVol = orderChance.CoinVol; // 보유 코인 수량 var avgPrice = orderChance.AvgBuyPrice; // 매수 평단가 var minTradeKRW = Settings.Default.minTradeKRW; // 최소 거래 금액 // 분봉 N개를 기준으로 직전 시가 에서 현재 금액 등낙률을 가져온다. var prevCandle = candles[1]; // 직전 캔들 var lastCandle = candles.Last(); // 마지막 캔들 var prevPrice = prevCandle.Close; // 직전종가 prevPrice = prevCandle.Low; // 직전 저가 대입 var startPrice = lastCandle.Open; // 마지막 캔들 시작가 var highPrice = candles.GetRange(1, candles.Count - 1).Max(x => x.High); // 최고가 startPrice = Math.Max(startPrice, highPrice); // 캔들 최고가 대입 var change = (currPrice - prevPrice); // 변동가 var currentRate = (change / currPrice) * 100; // 등락율 var candlesChange = (currPrice - startPrice); // 캔들 변동가 var candlesRate = (candlesChange / startPrice) * 100; // 캔들 등락율 var profit = (avgPrice == 0) ? 0D : (currPrice - avgPrice); // 수익 var tradeProfitRate = (avgPrice == 0) ? 0D : (profit / avgPrice) * 100; // 수익율 var result = null as JObject; var args = new object[] { coinName, currPrice, prevPrice, startPrice, currentRate, candlesRate, avgPrice, tradeProfitRate }; var buyTs = DateTime.Now - LastBuyDate; var sellTs = DateTime.Now - LastSellDate; var minutes = sellTs.TotalMinutes; WriteLog("{0} : 현재가 {1:N0}, 직전가 {2:N0}, 시작가 {3:N0}, 직전등락폭 {4:F6}, 등락폭 {5:F6}, 평단가 {6:N0}, 수익율 {7:F6}", args); if (StartKRW < minTradeKRW && krwBalance > minTradeKRW && coinPrice < minTradeKRW) { // 거래 시작 금액 StartKRW = krwBalance; } try { if (coinPrice <= minTradeKRW && krwBalance <= minTradeKRW) { // 보유현금과 보유 코인이 최소 거래금액 보다 적으면 거래 없음 WriteLog("#### 거래 불가 : 보유현금 {0}, 코인보유금 {1}, 최소 거래 금액 {2},", krwBalance, coinPrice, minTradeKRW); } else if (krwBalance > minTradeKRW && sellTs.TotalSeconds >= CandleType.Minute * 60 / 2 && candlesRate <= -(triggerRate + (feeRate * 2)) && currentRate >= (feeRate * 2)) { // BUY // 보유현금이 최소 거래금액 보다 많음 // 수익율 초과하여 떨어지다 수수료율 2배 이상 상승 했을때 거래비율 만큼 산다. var total = ToOrderPrice(krwBalance); result = React.executeDeal(true, false, coinName, 0, 0, total); LastBuyDate = DateTime.Now; WriteLog("#### {0} BUY : 금액 {1:N0}, 수량 {2:F6}", coinName, total, total / currPrice); } else if (coinPrice > minTradeKRW && (buyTs.TotalSeconds >= CandleType.Minute * 60 || tradeProfitRate >= (triggerRate / candleCount) + (feeRate * 2))) { // SELL // 코인평가금 최소 거래금액 보다 많음 // 분봉 하나의 시간이 지나면 시장가에 전체 매도 // 현재가가 평단가 보다 (수익율/캔들수 + 수료율2배) 이상일때 전체 매도 var vol = coinVol; vol = Math.Truncate(vol * 100000) / 100000; result = React.executeDeal(false, false, coinName, vol, 0, 0); LastSellDate = DateTime.Now; WriteLog("#### {0} SELL : 금액 {1:N0}, 수량 {2:F6}", coinName, vol * currPrice, vol); } } catch (Exception ex) { WriteLog(ex.StackTrace); } if (result != null) { WriteLog("#### RESULT : {0}", result.ToString()); var coinProfit = new Profit(ApiData, coinName, StartKRW); var profits = new object[] { coinName, StartKRW, coinProfit.TotalKrw, coinProfit.KrwProfit, coinProfit.KrwProfitRate }; txtProfitPrice.Text = coinProfit.KrwProfit.ToString("N0"); txtProfitRate.Text = coinProfit.KrwProfitRate.ToString("F6"); WriteLog("#### {0} 수익 : 거래시작금액 {1:N0}, 현재평가 금액 {2:N0}, 수익금액 {3:N0}, 수익율 {4:F6}", profits); } }