Exemple #1
0
        public void UpdateFunds()
        {
            Funds f  = new Funds(MyAuth, CurContextValues.ProductName);
            var   af = f.GetAvailableFunds();

            if (af == null)
            {
                Logger.WriteLog("An error occured in getting funds");
                return;
            }

            Logger.WriteLog(String.Format("Funds Updated: \n\tavailable {0}: {1}\n\tavailable {2}: {3}",
                                          "USD $", af.AvailableDollars.ToString(), f.ProductName, af.AvailableProduct));

            FundsUpdatedEvent?.Invoke(this, new FundsEventArgs {
                AvaFunds = af
            });
        }
Exemple #2
0
        internal virtual async void Sell()
        {
            CurrentValues.WaitingBuyOrSell = true;
            CurrentValues.WaitingSellFill  = true;
            CurrentValues.WaitingBuyFill   = false;

            SetNextActionTo_Buy();

            try
            {
                //limit order
                var sellResult = await CurrentValues.MyOrderBook.PlaceNewOrder("sell", CurrentValues.ProductName, CurrentValues.BuySellAmount.ToString(), CurrentValues.CurrentBufferedPrice.ToString(), true);

                //market order
                //var sellResult = await CurrentValues.MyOrderBook.PlaceNewOrder("sell", CurrentValues.ProductName, CurrentValues.BuySellAmount.ToString(), CurrentValues.CurrentBufferedPrice.ToString(), true, "market");

                //wait for the sell result
                if (sellResult == null)
                {
                    Logger.WriteLog("Sell result is null");
                }

                //test//await MyOrderBook.PlaceNewOrder("sell", ProductName, BuySellAmount.ToString(), (CurrentBufferedPrice + 10.00m).ToString(), true);
                Logger.WriteLog(string.Format("Order placed, Waiting {0} min before placing any new order", CurrentValues.WaitTimeAfterBigSmaCrossInMin));
            }
            catch (Exception ex)
            {
                var msg = ex.Message + "\n";
                while (ex.InnerException != null)
                {
                    ex  = ex.InnerException;
                    msg = msg + ex.Message;
                }

                Logger.WriteLog("Error Selling: \n" + msg);
                Logger.WriteLog("Retrying to sell on next price tick...");


                if (msg.ToLower().Contains("Insufficient funds".ToLower()))
                {
                    var f  = new Funds(CurrentValues.Auth, CurrentValues.ProductName);
                    var af = f.GetAvailableFunds();

                    if (af != null)
                    {
                        var usd  = af.AvailableDollars;
                        var prod = af.AvailableProduct;

                        var prodBuyCapacity = Math.Round(usd / CurrentValues.CurrentBufferedPrice, 4);

                        Logger.WriteLog(string.Format("You only have {0} {1} available to sell ",
                                                      prod.ToString(), CurrentValues.ProductName));

                        Logger.WriteLog("Setting max sell amount to: " + prod.ToString() + " " + CurrentValues.ProductName);

                        CurrentValues.BuySellAmount = (prod - 0.1m);
                    }
                }



                SetNextActionTo_Sell();


                CurrentValues.WaitingBuyFill   = false;
                CurrentValues.WaitingBuyOrSell = false; //set wait flag to false to place new order

                //simulate last cross time so sells immidiately instead of waiting. since error occured
                CurrentValues.LastLargeSmaCrossTime = DateTime.UtcNow.ToLocalTime().AddMinutes((-1 * CurrentValues.WaitTimeAfterBigSmaCrossInMin) - 1);
                //CurrentValues.LastSmallSmaCrossTime = DateTime.UtcNow.ToLocalTime().AddMinutes((-1 * CurrentValues.WaitTimeAfterSmallSmaCrossInMin) - 1);
            }
        }