public IHttpActionResult PutOrderHistoryData(int id, OrderHistoryData orderHistoryData)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != orderHistoryData.Id)
            {
                return(BadRequest());
            }

            db.Entry(orderHistoryData).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OrderHistoryDataExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult GetOrderHistoryData(int id)
        {
            OrderHistoryData orderHistoryData = db.OrderHistoryDatas.Find(id);

            if (orderHistoryData == null)
            {
                return(NotFound());
            }

            return(Ok(orderHistoryData));
        }
        public IHttpActionResult PostOrderHistoryData(OrderHistoryData orderHistoryData)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.OrderHistoryDatas.Add(orderHistoryData);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = orderHistoryData.Id }, orderHistoryData));
        }
        public IHttpActionResult DeleteOrderHistoryData(int id)
        {
            OrderHistoryData orderHistoryData = db.OrderHistoryDatas.Find(id);

            if (orderHistoryData == null)
            {
                return(NotFound());
            }

            db.OrderHistoryDatas.Remove(orderHistoryData);
            db.SaveChanges();

            return(Ok(orderHistoryData));
        }
Ejemplo n.º 5
0
        public async void CreateOrderMethod()
        {
            if (CreateVisibility == Visibility.Visible)
            {
                Order order = new Order("hahahaha");
                await Catalog <Order> .Instance.Create(order);

                Order latestOrder =
                    Catalog <Order> .Instance.GetList.Find(x => x.OrderDate >= DateTime.Now.Subtract(TimeSpan.FromSeconds(5)));

                OrderHistory orderHistory = new OrderHistory(latestOrder, Controller.StoreId);
                await Catalog <OrderHistory> .Instance.Create(orderHistory);

                bool gotData = false;

                foreach (var i in _listOfOrders)
                {
                    if (i.ActualAmount > 0)
                    {
                        OrderProduct op = new OrderProduct(latestOrder.Id, i.Product.Id, i.ActualAmount);
                        await Catalog <OrderProduct> .Instance.Create(op);

                        OrderHistoryData ohd = new OrderHistoryData(orderHistory.Id, i.Product.Name, i.SupplierName, i.SupplierEmail,
                                                                    i.Missing, i.Product.AmountPerBox, i.SuggestedAmount, i.ActualAmount);
                        await Catalog <OrderHistoryData> .Instance.Create(ohd);

                        gotData = true;
                    }
                }

                if (gotData == false)
                {
                    await Catalog <Order> .Instance.Delete(order.Id);

                    await Catalog <OrderHistory> .Instance.Delete(orderHistory.Id);
                }
                OnPropertyChanged(nameof(OrderHistoryCatalog));
            }
            else
            {
                OnPropertyChanged(nameof(OrderHistoryCatalog));

                DataVisibility   = Visibility.Collapsed;
                CreateVisibility = Visibility.Visible;

                OnPropertyChanged(nameof(DataVisibility));
                OnPropertyChanged(nameof(CreateVisibility));
            }
        }
Ejemplo n.º 6
0
        private static void Trade3()
        {
            // Settings
            BTCMarketsHelper.ProfitMargin = 0;

            // Get number of Open Orders
            OpenOrdersHistory = BTCMarketsHelper.OrderOpen(CURRENCY, INSTRUMENT, 10, "1");

            if (OpenOrdersHistory.success && OpenOrdersHistory.orders != null)
            {
                if (OpenOrdersHistory.orders.Length > 1)
                {
                    Console.WriteLine("Open orders are still active...");
                }
                else
                {
                    // get ETH/BTC market data i.e. instrument/currency
                    Console.WriteLine($"Previous Ask Price: {lastETH_BTC}");
                    MarketTickData marketData = BTCMarketsHelper.GetMarketTick($"{INSTRUMENT}/{CURRENCY}");
                    Console.WriteLine($"Current Ask Price: {marketData.bestAsk}");
                    lastETH_BTC = marketData.bestAsk;

                    // get trading data
                    TradingData tradingData = TradingHelper.GetTradingData(marketData);

                    if (lastETH_BTC > 0) // ensure first round is skipped when there is no history
                    {
                        if (marketData.bestAsk > lastETH_BTC)
                        {
                            Console.WriteLine($"Previous Volume (BTC): {lastBTC_Volume}");
                            if (tradingData.BuyVolume > lastBTC_Volume)
                            {
                                Console.WriteLine("ETH has gone stronger. Sell ETH.");
                            }
                        }
                        else if (marketData.bestAsk < lastETH_BTC)
                        {
                            Console.WriteLine("BTC has gone stronger. Buy ETH.");
                            Console.WriteLine($"Previous Buy Volume (ETH): {lastETH_Volume}");
                            Console.WriteLine($"Current Buy volume ({marketData.instrument}): {tradingData.BuyVolume}");
                        }
                    }

                    Console.WriteLine($"Buy price ({marketData.currency}): {tradingData.BuyPrice}");
                    Console.WriteLine($"Sell volume ({marketData.instrument}): {tradingData.SellVolume}");
                    Console.WriteLine($"Sell price ({marketData.currency}): {tradingData.SellPrice}");
                    Console.WriteLine($"Spend total ({marketData.currency}): {tradingData.SpendTotal}");

                    /*
                     * // create orders
                     * CreateOrderData buyOrder = BTCMarketsHelper.CreateNewOrder(marketData.currency, marketData.instrument,
                     *  (long)(tradingData.BuyPrice * ApplicationConstants.NUMERIC_MULTIPLIER),
                     *  (int)(tradingData.BuyVolume * ApplicationConstants.NUMERIC_MULTIPLIER),
                     *  "Bid", "Limit");
                     *
                     * if (buyOrder.success)
                     * {
                     *  CreateOrderData sellOrder = BTCMarketsHelper.CreateNewOrder(marketData.currency, marketData.instrument,
                     *   (long)(tradingData.SellPrice * ApplicationConstants.NUMERIC_MULTIPLIER),
                     *  (int)(tradingData.SellVolume * ApplicationConstants.NUMERIC_MULTIPLIER),
                     *   "Ask", "Limit");
                     *
                     *  if (sellOrder.success)
                     *  {
                     *      // append csv line
                     *      BotLogger.WriteLine($",{tradingData.BuyVolume.ToDecimalString(8)}, {marketData.instrument}, Balance (Unit 2), " +
                     *          $"{tradingData.BuyPrice.ToDecimalString(8)}, {marketData.currency}, {tradingData.SpendTotal.ToDecimalString(8)}, {BTCMarketsHelper.ProfitMargin}%, " +
                     *          $"{tradingData.SellVolume.ToDecimalString(8)}, {tradingData.SellPrice.ToDecimalString(8)}");
                     *  }
                     *  else
                     *  {
                     *      Console.WriteLine(sellOrder.errorMessage);
                     *  }
                     * }
                     * else
                     * {
                     *  Console.WriteLine(buyOrder.errorMessage);
                     * }
                     */
                }
            }
            else
            {
                Console.WriteLine(OpenOrdersHistory.errorMessage);
            }

            Console.WriteLine(CONSOLE_WAITING);
            Console.WriteLine();
        }
Ejemplo n.º 7
0
        private static void Trade1()
        {
            // Settings
            BTCMarketsHelper.ProfitMargin = 2;

            // Get number of Open Orders
            OpenOrdersHistory = BTCMarketsHelper.OrderOpen(CURRENCY, INSTRUMENT, 10, "1");

            if (OpenOrdersHistory.success && OpenOrdersHistory.orders != null)
            {
                if (OpenOrdersHistory.orders.Length > 1)
                {
                    Console.WriteLine("Open orders are still active...");
                }
                else
                {
                    // get ETH/BTC market data i.e. instrument/currency
                    MarketTickData marketData = BTCMarketsHelper.GetMarketTick($"{INSTRUMENT}/{CURRENCY}");

                    // get trading data
                    TradingData tradingData = TradingHelper.GetTradingData(marketData, splitProfitMargin: true);

                    Console.WriteLine($"Buy volume ({marketData.instrument}): {tradingData.BuyVolume}");
                    Console.WriteLine($"Buy price ({marketData.currency}): {tradingData.BuyPrice}");
                    Console.WriteLine($"Sell volume ({marketData.instrument}): {tradingData.SellVolume}");
                    Console.WriteLine($"Sell price ({marketData.currency}): {tradingData.SellPrice}");
                    Console.WriteLine($"Spend total ({marketData.currency}): {tradingData.SpendTotal}");

                    // create orders
                    CreateOrderData buyOrder = BTCMarketsHelper.CreateNewOrder(marketData.currency, marketData.instrument,
                                                                               (long)(tradingData.BuyPrice * ApplicationConstants.NUMERIC_MULTIPLIER),
                                                                               (long)(tradingData.BuyVolume * ApplicationConstants.NUMERIC_MULTIPLIER),
                                                                               "Bid", "Limit");

                    if (buyOrder.success)
                    {
                        System.Threading.Thread.Sleep(rnd.Next(1, 10) * 1000);
                        CreateOrderData sellOrder = BTCMarketsHelper.CreateNewOrder(marketData.currency, marketData.instrument,
                                                                                    (long)(tradingData.SellPrice * ApplicationConstants.NUMERIC_MULTIPLIER),
                                                                                    (long)(tradingData.SellVolume * ApplicationConstants.NUMERIC_MULTIPLIER),
                                                                                    "Ask", "Limit");

                        if (sellOrder.success)
                        {
                            // append csv line
                            BotLogger.WriteLine($",{tradingData.BuyVolume}, {marketData.instrument}, Balance (Unit 2), " +
                                                $"{tradingData.BuyPrice}, {marketData.currency}, {tradingData.SpendTotal}, {BTCMarketsHelper.ProfitMargin}%, " +
                                                $"{tradingData.SellVolume}, {tradingData.SellPrice}");
                        }
                        else
                        {
                            Console.WriteLine(sellOrder.errorMessage);
                        }
                    }
                    else
                    {
                        Console.WriteLine(buyOrder.errorMessage);
                    }
                }
            }
            else
            {
                Console.WriteLine(OpenOrdersHistory.errorMessage);
            }

            Console.WriteLine(CONSOLE_WAITING);
            Console.WriteLine();
        }