Пример #1
0
 public void CreateTrade(decimal price, decimal Amount, TradeType type)
 {
     if (type == TradeType.Buy)
     {
         NewOrderResponse sell = api.ExecuteBuyOrderBTC(Convert.ToDecimal(Amount), Convert.ToDecimal(price), OrderExchange.Bitfinex, OrderType.MarginLimit);
     }
     else
     {
         NewOrderResponse sell = api.ExecuteSellOrderBTC(Convert.ToDecimal(Amount), Convert.ToDecimal(price), OrderExchange.Bitfinex, OrderType.MarginLimit);
     }
 }
Пример #2
0
 public IMessageIn Visit(NewOrderResponse msg)
 {
     Condition.Requires(_data, "data").IsNotNull();
     // {"order_id":"1476459990","result":"true"}
     if ((string)_data["result"] != "true")
     {
         _log.Error("Unexpected response to new future request. Ignoring it.");
         return(null);
     }
     msg.OrderId = (long)_data["order_id"];
     return(msg);
 }
Пример #3
0
        public void TestingOrderRules(int orderNumber, string customerName, string stateAbbreviation, decimal taxrate, string productType, decimal area, decimal costPerSquareFoot, decimal laborCostPerSquareFoot, bool expectedResult)
        {
            DateTime dateTime  = DateTime.Parse("01/01/2020");
            Orders   testOrder = new Orders()
            {
                State = stateAbbreviation, ProductType = productType
            };
            NewOrderResponse response = new NewOrderResponse();

            response = NewOrderRules.NewOrder(dateTime, testOrder.State, testOrder.ProductType);

            Assert.AreEqual(response.Success, expectedResult);
        }
Пример #4
0
        public NewOrderResponse ExecuteOrder(string symbol, decimal amount, decimal price, string exchange, string side, string type)
        {
            NewOrderRequest req      = new NewOrderRequest(Nonce, symbol, amount, price, exchange, side, type);
            string          response = SendRequest(req, "POST");

            if (response == string.Empty)
            {
                return(null);
            }
            NewOrderResponse resp = NewOrderResponse.FromJSON(response);

            return(resp);
        }
Пример #5
0
        public static NewOrderResponse NewOrder(DateTime dateTime, string state, string productType)
        {
            NewOrderResponse response  = new NewOrderResponse();
            IFileOrderRepo   orderRepo = new FileOrderRepo(dateTime.Day.ToString() + dateTime.Month.ToString() + dateTime.Year.ToString());
            List <Taxes>     taxes     = FileTaxRepo.LoadTaxes();
            List <Products>  products  = FileProductsRepo.LoadProducts();

            if (dateTime <= DateTime.Now)
            {
                response.Success = false;
                response.Message = "Error: New Orders must be set in the future";
                return(response);
            }

            bool stateVerification = taxes.Any(t => state.Contains(t.StateAbbreviation));

            if (stateVerification == false)
            {
                response.Success = false;
                response.Message = "Error: We do not sell in inputed state";
                return(response);
            }

            bool productVerification = products.Any(p => productType.Contains(p.ProductsType));

            if (productVerification == false)
            {
                response.Success = false;
                response.Message = "Error: Input for products was invalid";
                return(response);
            }
            else
            {
                response.Success                = true;
                response.OrderNumber            = orderRepo.NextOrderNumber();
                response.Date                   = dateTime;
                response.StringDate             = dateTime.ToString();
                response.State                  = state;
                response.Tax                    = taxes.FirstOrDefault(t => t.StateAbbreviation == response.State).TaxRate;
                response.Product                = productType;
                response.CostPerSquareFoot      = products.FirstOrDefault(p => p.ProductsType == response.Product).CostPerSquareFoot;
                response.LaborCostPerSquareFoot = products.FirstOrDefault(p => p.ProductsType == response.Product).LaborCostPerSquareFoot;
                return(response);
            }
        }
        public NewOrderResponse AddNewOrder(NewOrderRequest newOrderRequest, string customerId)
        {
            var response = new NewOrderResponse();

            using var transaction = _context.Database.BeginTransaction();
            try
            {
                if (!CustomerWithIdExists(customerId))
                {
                    throw new Exception("Customer with Id " + customerId + " DOESNT EXIST");
                }

                var confectioneries = newOrderRequest.Confectionery;
                foreach (var confectioneryRequest in confectioneries)
                {
                    if (!ConfectioneryExists(confectioneryRequest))
                    {
                        throw new Exception("Confectionery with name " + confectioneryRequest.Name + " DOESNT EXIST");
                    }
                }

                var idOrder = CreateNewOrder(newOrderRequest, customerId);

                response.CustomerSurname = GetCustomerSurnameById(customerId);
                response.IdOrder         = idOrder;
                response.IdEmployee      = GetEmployeeIdByOrderId(idOrder);
                List <int> confectioneryIdList = new List <int>();

                foreach (var confectioneryRequest in confectioneries)
                {
                    var confId = CreateNewConfectioneryOrder(idOrder, confectioneryRequest);
                    confectioneryIdList.Add(confId);
                }

                response.ConfectioneryIdList = confectioneryIdList;
                transaction.Commit();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw;
            }

            return(response);
        }
Пример #7
0
        private static void HandleOrderSubmit(string response)
        {
            Console.ForegroundColor = ConsoleColor.Cyan;
            NewOrderResponse nor = JsonConvert.DeserializeObject <NewOrderResponse>(response);

            if (nor.Success)
            {
                Console.WriteLine("Order successfully submitted.");
                Console.ForegroundColor = ConsoleColor.DarkCyan;
                Console.WriteLine("Balance available: " + nor.BuyBalance + btc + ", " + nor.SellBalance + " TRTL");
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine(nor.Error);
            }
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine();
        }
Пример #8
0
        public async Task <NewOrderResponse> RequestWaffleOrder(int waffleCount, int chocolateCount, string referenceNum, float amount)
        {
            Dictionary <string, string> body = new Dictionary <string, string>()
            {
                { "waffle_quantity", waffleCount.ToString() },
                { "chocolate_numbers", chocolateCount.ToString() },
                { "transaction_number", referenceNum.ToString() },
                { "amount_paid", amount.ToString() }
            };

            StringContent bodyJson = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");

            HttpResponseMessage result = await httpClient.PostAsync(host + baseUri + orderApiPath, bodyJson);

            bodyJson.Dispose();

            if (result != null)
            {
                try
                {
                    string dataString = await result.Content.ReadAsStringAsync();

                    Dictionary <string, object> data = JsonConvert.DeserializeObject <Dictionary <string, object> >(dataString);

                    NewOrderResponse response = new NewOrderResponse(result.StatusCode, bool.Parse(data["accepted"].ToString()), int.Parse(data["order_id"].ToString()));
                    return(response);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);

                    NewOrderResponse response = new NewOrderResponse(HttpStatusCode.BadRequest, false, -1);
                    return(response);
                }
            }

            return(new NewOrderResponse(HttpStatusCode.BadRequest, false, -1));
        }
        public OrderInformation CreateNewOrder(string symbol, string side, double quantity, double price = -1, double stopPrice = -1,
                                               string timeInForce = "Day", DateTime expireTime = default, string clientOrderId = null, bool strictValidate = true)
        {
            NewOrderResponse response = hitbtcClient.CreateNewOrder(symbol, side, quantity, price, stopPrice, timeInForce, expireTime, clientOrderId, strictValidate);

            OrderInformation result = new OrderInformation()
            {
                Id            = response.Id,
                ClientOrderId = response.ClientOrderId,
                Symbol        = response.Symbol,
                Side          = response.Side,
                Status        = response.Status,
                TypeOrder     = response.TypeOrder,
                TimeInForce   = response.TimeInForce,
                Quantity      = response.Quantity,
                Price         = response.Price,
                CumQuantity   = response.CumQuantity,
                CreatedAt     = response.CreatedAt,
                UpdatedAt     = response.UpdatedAt
            };

            return(result);
        }
Пример #10
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            var symbol   = txtSecurity.Text;
            var side     = comboBuySell.SelectedValue;
            var type     = comboBoxOrderType.SelectedValue;
            var amount   = txtQuantity.Text;
            var exchange = comboBoxExchange.SelectedValue;

            if (symbol == string.Empty || symbol == "Security")
            {
                MessageBox.Show(this, "Please fill security", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else if (side == null)
            {
                MessageBox.Show(this, "Please fill side", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else if (type == null)
            {
                MessageBox.Show(this, "Please fill type", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else if (amount == null || amount == "Quantity")
            {
                MessageBox.Show(this, "Please fill quantity", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else if (exchange == null)
            {
                MessageBox.Show(this, "Please fill exchange", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            decimal quantity;
            var     isNumeric = decimal.TryParse(amount, out quantity);

            if (!isNumeric)
            {
                MessageBox.Show(this, "Please fill numeric value for quantity", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            NewOrderResponse response = null;

            if (symbol.ToLower().IndexOf(Broker.BitFinex.ToString().ToLower()) > -1)
            {
                var instrumentCode = symbol.Split('.');
                symbol = instrumentCode[1].ToUpper();
                if (side.ToString().ToLower() == "buy")
                {
                    response = bitfinexAPI.ExecuteBuyOrderBTC(symbol.ToLower(), quantity, 10, exchange.ToString().ToLower(), type.ToString().ToLower());
                }
                else
                {
                    response = bitfinexAPI.ExecuteSellOrderBTC(symbol.ToLower(), quantity, 10, exchange.ToString().ToLower(), type.ToString().ToLower());
                }
                if (response != null)
                {
                    RefreshDataGrid();
                }
            }
        }
Пример #11
0
        public void Execute()
        {
            Console.Clear();

            IFileOrderRepo fileOrderRepo;
            Orders         newOrder = new Orders();
            Products       products = new Products();

            Console.WriteLine("New Order Form");
            Console.WriteLine("----------------------");

            Console.WriteLine("Enter a date (New orders must be set in future dates): ");
            var userInput = Console.ReadLine();
            var path      = ConsoleIO.UserDateValidateToString(userInput);
            var userDate  = ConsoleIO.UserDateToDateTime(userInput);

            newOrder.CustomerName = ConsoleIO.ValidateCompanyName("Enter company name: ");

            ConsoleIO.DisplayStateAbbreviation(FileTaxRepo.LoadTaxes());
            newOrder.State = ConsoleIO.ValidateStateFormat("Enter a State: (States must be abbreviated)");

            Console.WriteLine("Select A Product: ");
            ConsoleIO.DisplayProducts(FileProductsRepo.LoadProducts());
            newOrder.ProductType = Console.ReadLine();

            newOrder.Area = ConsoleIO.ValidateAreaFormat("What's the Area? (Must be minimum of 100 square feet): ");

            NewOrderResponse response = new NewOrderResponse();

            response = NewOrderRules.NewOrder(userDate, newOrder.State, newOrder.ProductType);

            if (response.Success == false)
            {
                Console.WriteLine(response.Message);
                Console.ReadKey();
            }
            else
            {
                newOrder.TaxRate                = response.Tax;
                newOrder.CostPerSquareFoot      = response.CostPerSquareFoot;
                newOrder.LaborCostPerSquareFoot = response.LaborCostPerSquareFoot;
                newOrder.OrderNumber            = response.OrderNumber;


                Console.Clear();
                Console.WriteLine("Summary");
                Console.WriteLine("-------------------------------------------------------------");

                ConsoleIO.DisplayOrderDetails(new List <Orders> {
                    newOrder
                }, path);


                if (ConsoleIO.Exit("Do you want to SAVE new order? [Y/N]") == false)
                {
                    return;
                }
                else
                {
                    fileOrderRepo = new FileOrderRepo(path);

                    if (!File.Exists(path))
                    {
                        File.Create(path).Dispose();
                        fileOrderRepo.Create(newOrder);
                    }
                    else
                    {
                        fileOrderRepo.Create(newOrder);
                    }
                }

                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
            }
        }
Пример #12
0
 public string Visit(NewOrderResponse msg)
 {
     return(NewOrder(msg.ProductType, msg.Currency));
 }
Пример #13
0
        public void Execute()
        {
            Console.Clear();
            IFileOrderRepo fileOrderRepo;
            Orders         newOrder = new Orders();

            Console.WriteLine("Edit Order Form");
            Console.WriteLine("--------------------------");

            Console.WriteLine("Enter a date: ");

            string userInputDate = Console.ReadLine();

            if (string.IsNullOrEmpty(userInputDate))
            {
                Console.WriteLine("Error: User input was invalid...Hit any key to return to menu...");
                Console.ReadKey();
                return;
            }

            var path = ConsoleIO.UserDateValidateToString(userInputDate);



            OrderManager manager = OrderManagerFactory.Create(path);

            OrderLookupResponse respose = manager.LookupOrders(path);

            if (respose.Success)
            {
                ConsoleIO.DisplayOrderDetails(respose.orders, path);
            }
            else
            {
                Console.WriteLine("An error has occurred: ");
                Console.WriteLine(respose.Message);
            }

            int orderNumber = ConsoleIO.StringToInt("Which order would you like to edit? (Choose order by it's ORDER NUMBER): ");

            Console.Clear();

            fileOrderRepo = new FileOrderRepo(path);
            fileOrderRepo.LoadOrder();

            Orders oldOrder = fileOrderRepo.ReadByOrderNumber(orderNumber);

            ConsoleIO.DisplayOrderDetails(new List <Orders> {
                oldOrder
            }, path);

            string newName = ConsoleIO.ValidateCompanyName("Enter new NAME or hit enter to continue: ");

            if (string.IsNullOrEmpty(newName))
            {
                newOrder.CustomerName = oldOrder.CustomerName;
            }
            else
            {
                newOrder.CustomerName = newName;
            }

            ConsoleIO.DisplayStateAbbreviation(FileTaxRepo.LoadTaxes());
            Console.WriteLine("Enter new STATE or hit enter to continue:");
            Console.WriteLine("REMINDER: States MUST be abbreviated!!");
            string newState = Console.ReadLine();

            if (string.IsNullOrEmpty(newState))
            {
                newOrder.State = oldOrder.State;
            }
            else
            {
                newOrder.State = newState;
            }

            ConsoleIO.DisplayProducts(FileProductsRepo.LoadProducts());
            Console.WriteLine("Enter new PRODUCT TYPE or hit enter to continue:");
            string newProduct = Console.ReadLine();

            if (string.IsNullOrEmpty(newProduct))
            {
                newOrder.ProductType = oldOrder.ProductType;
            }
            else
            {
                newOrder.ProductType = newProduct;
            }

            Console.WriteLine("Enter new AREA or hit enter to continue:");
            Console.WriteLine("REMINDER: Area MUST be at minimum 100");
            string newArea = Console.ReadLine();

            if (string.IsNullOrEmpty(newArea))
            {
                newOrder.Area = oldOrder.Area;
            }
            else
            {
                newOrder.Area = ConsoleIO.StringToDecimal(newArea);
            }

            DateTime.TryParse(userInputDate, CultureInfo.GetCultureInfo("en-us"), DateTimeStyles.NoCurrentDateDefault, out DateTime dateTime);

            NewOrderResponse response = new NewOrderResponse();

            response = NewOrderRules.NewOrder(dateTime, newOrder.State, newOrder.ProductType);

            if (response.Success == false)
            {
                Console.WriteLine(response.Message);
                Console.ReadKey();
            }
            else
            {
                newOrder.TaxRate                = response.Tax;
                newOrder.CostPerSquareFoot      = response.CostPerSquareFoot;
                newOrder.LaborCostPerSquareFoot = response.LaborCostPerSquareFoot;
                newOrder.OrderNumber            = response.OrderNumber;

                Console.Clear();

                Console.WriteLine("Summary");
                Console.WriteLine("-------------------------------------------------------------");

                Console.WriteLine("OLD ORDER");
                Console.WriteLine("*************************************************************");
                ConsoleIO.DisplayOrderDetails(new List <Orders> {
                    oldOrder
                }, path);
                Console.WriteLine("*************************************************************");

                Console.WriteLine("NEW ORDER");
                Console.WriteLine("-------------------------------------------------------------");
                ConsoleIO.DisplayOrderDetails(new List <Orders> {
                    newOrder
                }, path);
                Console.WriteLine("-------------------------------------------------------------");

                if (ConsoleIO.Exit("Do you want to SAVE edited order? [Y/N]") == false)
                {
                    return;
                }
                else
                {
                    fileOrderRepo.Delete(oldOrder.OrderNumber, oldOrder);

                    fileOrderRepo.Create(newOrder);
                }
            }


            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
Пример #14
0
        /// <summary>
        /// Process the incoming messages
        /// </summary>
        /// <param name="message">Incoming message</param>
        private void processMessage(string message)
        {
            // Deserialize the incoming command to check wich message has just arrived
            // The action property brings the command name
            switch (Command.Deserialize(message).action)
            {
            case KeepAlive.CLASSNAME:
            {           // If it is a KeepAlive message, just answer Quantsis Conneciton Box another KeepAlive message
                        //CheckAsyncTaskInProgress
                this.send(new KeepAlive().Serialize());
                break;
            }

            case NewOrderResponse.CLASSNAME:
            {           // If it is an NewOrderResponse message and it contains error, show the error message
                var cmd = NewOrderResponse.Deserialize(message);
                if (!cmd.success)
                {
                    NotifyOMS(cmd.ToString());
                }
                break;
            }

            case NewStopOrderResponse.CLASSNAME:
            {           // If it is an NewStopOrderResponse message and it contains error, show the error message
                var cmd = NewStopOrderResponse.Deserialize(message);
                if (!cmd.success)
                {
                    NotifyOMS(cmd.ToString());
                }
                break;
            }

            case NewStopGainLossOrderResponse.CLASSNAME:
            {           // If it is an NewStopGainLossOrderResponse message and it contains error, show the error message
                var cmd = NewStopGainLossOrderResponse.Deserialize(message);
                if (!cmd.success)
                {
                    NotifyOMS(cmd.ToString());
                }
                break;
            }

            case CancelOrderResponse.CLASSNAME:
            {           // If it is an CancelOrderResponse message and it contains error, show the error message
                var cmd = CancelOrderResponse.Deserialize(message);
                if (!cmd.success)
                {
                    NotifyOMS(cmd.ToString());
                }
                break;
            }

            case ExecutionReport.CLASSNAME:
            {           // If it is an ExecutionReport message, check if it was successful and updates the order list or show error message
                var cmd = ExecutionReport.Deserialize(message);
                if (cmd.success)
                {
                    NotifyOMS(cmd.ToString());
                }
                else
                {
                    NotifyOMS(cmd.ToString());
                }

                break;
            }

            case OrderListResponse.CLASSNAME:
            {           // If it is an OrderListResponse, check if it was successful. In negative case show error message.
                var cmd = OrderListResponse.Deserialize(message);
                if (!cmd.success)
                {
                    NotifyOMS(cmd.ToString());
                }
                break;
            }

            case PositionResponse.CLASSNAME:
            {           // If it is a Position Response, check if it was successful and updates the position list. In case of failure, show error messasge
                var cmd = PositionResponse.Deserialize(message);
                if (cmd.success)
                {
                    NotifyOMS(cmd.ToString());
                }
                else
                {
                    NotifyOMS(cmd.ToString());
                }

                break;
            }

            case QuoteResponse.CLASSNAME:
            {           // If it is a Quote Response, check if it was successful and logs the message
                var cmd = QuoteResponse.Deserialize(message);
                if (cmd.success)
                {
                    OnQuoteResponse(cmd);
                }
                else
                {
                    NotifyQCB(cmd.ToString());
                }
                break;
            }

            case QuoteUpdate.CLASSNAME:
            {           // If it is a Quote Update, check if it was successful and logs the message
                var cmd = QuoteUpdate.Deserialize(message);
                if (cmd.success)
                {
                    OnQuoteUpdate(cmd);
                }
                else
                {
                    NotifyQCB(cmd.ToString());
                }
                break;
            }

            case QuoteUnsubscribeResponse.CLASSNAME:
            {           // If it is a Quote Unsubscribe Response, check if it was successful
                var cmd = QuoteUnsubscribeResponse.Deserialize(message);
                if (cmd.success)
                {
                    NotifyOMS(cmd.ToString());
                }
                else
                {
                    NotifyOMS(cmd.ToString());
                }
                break;
            }

            case CandleResponse.CLASSNAME:
            {           // If it is a Quote Update, check if it was successful and logs the message
                var cmd = CandleResponse.Deserialize(message);
                if (cmd.success)
                {
                    if (cmd.candles != null)
                    {
                        if (cmd.candles.Count <= 0)
                        {
                            NotifyOMS("Nenhum foi possivel retornar nenhum candle para " + cmd.security + " - Timeframe: " + cmd.timeframe);
                        }
                        else
                        {
                            NotifyOMS("Dados Historicos Intraday para: " + cmd.security + " - Qtd de Candles: " + cmd.candles.Count + " - Timeframe: " + cmd.timeframe);
                            //foreach (Candle candle in cmd.candles)
                            //    this.mainForm.log(candle.ToString());
                        }
                    }
                }
                else
                {
                    NotifyOMS(cmd.ToString());
                }

                break;
            }

            // Candle Update
            case CandleUpdate.CLASSNAME:
            {           // If it is a Candle Update, check if it was successful and logs the message
                var cmd = CandleUpdate.Deserialize(message);

                if (cmd.success)
                {
                    if (cmd.candle != null)
                    {
                        switch (cmd.timeframe)
                        {
                        case CandleUpdate.TIMEFRAME_INTRADAY_1_MIN:
                            NotifyOMS("Candle Intraday Update: " + cmd.security + " - Last: " + cmd.candle.close + " - Time: " + cmd.candle.date);
                            break;

                        case CandleUpdate.TIMEFRAME_DAILY:
                            NotifyOMS("Candle Daily Update: " + cmd.security + " - Last: " + cmd.candle.close + " - Time: " + cmd.candle.date);
                            break;
                        }
                    }
                }
                //this.mainForm.updatePositions(cmd);
                else
                {
                    NotifyOMS(cmd.ToString());
                }

                break;
            }

            // QCB has disconnected (shut down)
            case Disconnect.CLASSNAME:
                this.disconnect();
                break;
            }
        }
Пример #15
0
        public decimal Long()
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
            string baseCurrency = Properties.Settings.Default.BaseCurrency;
            string market       = Properties.Settings.Default.Market;

            decimal price = 0;

            try
            {
                decimal balance = this.GetBalance(baseCurrency);
                //-------------------------------
                string pair = (market + baseCurrency).ToLower();

                price = this.GetCurrentPrice(baseCurrency, market);

                decimal ammount;
                if (Properties.Settings.Default.UsingFixedAmount)
                {
                    ammount = decimal.Parse(Properties.Settings.Default.FixedAmmount.ToString());
                }
                else
                {
                    ammount = Properties.Settings.Default.CapitalPercentageInEachOrder * (balance / price);
                }

                decimal limitBuyPrice = price * ((100 + Properties.Settings.Default.LimitSpreadPercentage) / 100);

                //------------------------------------------------------
                string decimalString = ammount.ToString();
                if (decimalString.Contains(","))
                {
                    decimalString = decimalString.Replace(",", ".");
                    ammount       = Convert.ToDecimal(decimalString);
                }
                //------------------------------------------------------

                //CancelAllOrdersResponse cancelOrdersResponse = api.CancelAllOrders();

                ActivePositionsResponse activePositionsResponse = api.GetActivePositions();

                foreach (var pos in activePositionsResponse.positions)
                {
                    decimal posAmmount = decimal.Parse(pos.amount);
                    if (pos.symbol == pair && posAmmount < 0)
                    {
                        ammount -= posAmmount;
                    }
                }

                //------------------------------------------------------


                NewOrderResponse buyResponse = api.ExecuteBuyOrder(pair.ToUpper(), ammount, limitBuyPrice, OrderExchange.Bitfinex, OrderType.MarginMarket);

                string orderId = buyResponse.order_id;

                OrderStatusResponse buyStatus = api.GetOrderStatus(Int64.Parse(buyResponse.order_id));

                if (bool.Parse(buyStatus.is_cancelled))
                {
                    //Console.ForegroundColor = ConsoleColor.Magenta;
                    //Console.WriteLine("Order was canceled...");
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("-----------------------------------------------------------------------------------");
                    Console.WriteLine("Market LONG order executed on " + buyResponse.symbol + " id = " + orderId);
                    Console.WriteLine("Price: " + buyStatus.price);
                    Console.WriteLine("Average Execution Price: " + buyStatus.avg_execution_price);
                    Console.WriteLine("Executed ammount: " + buyStatus.executed_amount);
                    Console.WriteLine("Remaining ammount : " + buyStatus.remaining_amount);

                    //update price, to return real price per unit
                    price = Convert.ToDecimal(buyStatus.avg_execution_price);

                    Console.ForegroundColor = ConsoleColor.White;

                    //-------------------------------------------------------------
                    //    logger.Log("------" + DateTime.Now.ToShortDateString() + "--------------------------------------------------------------------");
                    //    logger.Log("Market LONG order executed on " + buyResponse.symbol + " id = " + orderId);
                    //    logger.Log("Price: " + buyStatus.price);
                    //    logger.Log("Average Execution Price: " + buyStatus.avg_execution_price);
                    //    logger.Log("Executed ammount: " + buyStatus.executed_amount);
                    //    logger.Log("Remaining ammount : " + buyStatus.remaining_amount);
                }
                return(price);
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Error on Long Order: ");
                Console.WriteLine("ex.Message");
                Console.WriteLine(ex.InnerException);
                Console.WriteLine(ex.StackTrace);
                Console.ForegroundColor = ConsoleColor.White;
            }
            return(price);
        }