Esempio n. 1
0
        public OrderModel PostBestSellOrderFictive(CurrencyPair currencyPair, double USDT = 0)
        {
            OrderModel order            = new OrderModel();
            double     bestPricePerCoin = 0;
            double     amountQuote      = 0;

            bestPricePerCoin = FindBestPrice(currencyPair, OrderType.Sell);
            amountQuote      = USDT;

            //PushMessage("SOLD!",
            //    $"Currency: {currencyPair}\\n" +
            //    $"USDT: {string.Format("{0:0.00}$", USDT)}\\n" +
            //    $"At: {bestPricePerCoin}\\n" +
            //    $"Profit: {string.Format("{0:0.00}%", 0 * 100)}");

            order.CurrencyPair = currencyPair;
            order.OrderType    = OrderType.Buy;
            order.AmountBase   = 0;
            order.AmountQuote  = amountQuote;
            order.PricePerCoin = bestPricePerCoin;
            order.IdOrder      = 0;

            return(order);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets a data summary of a specific market.
        /// </summary>
        /// <param name="markets"></param>
        /// <param name="currencyPair"></param>
        /// <returns></returns>
        public IMarketData GetMarket(IDictionary <CurrencyPair, IMarketData> markets, CurrencyPair currencyPair)
        {
            IMarketData market =
                (from m in markets
                 where m.Key.BaseCurrency == currencyPair.BaseCurrency &&
                 m.Key.QuoteCurrency == currencyPair.QuoteCurrency
                 select m.Value).Single();

            return(market);
        }
Esempio n. 3
0
 public IList <ITrade> MCGetTrades(CurrencyPair currencyPair, DateTime startTime, DateTime endTime)
 {
     return(PoloniexClient.Markets.GetTrades(currencyPair, startTime, endTime));
 }
Esempio n. 4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="currencyPair"></param>
 /// <param name="depth"></param>
 /// <returns></returns>
 public IOrderBook GetOpenOrders(CurrencyPair currencyPair, uint depth)
 {
     return(PoloniexClient.Markets.GetOpenOrdersSync(currencyPair, depth));
 }
Esempio n. 5
0
 public IList <ITrade> GetTrades(CurrencyPair currencyPair)
 {
     return(client.Trading.GetTrades(currencyPair));
 }
Esempio n. 6
0
 public IList <ITrade> GetTrades(CurrencyPair currencyPair, DateTime startTime, DateTime endTime)
 {
     return(client.Trading.GetTrades(currencyPair, startTime, endTime));
 }
Esempio n. 7
0
 public ulong PostOrder(CurrencyPair currencyPair, OrderType type, double pricePerCoin, double amountQuote)
 {
     return(client.Trading.PostOrder(currencyPair, type, pricePerCoin, amountQuote));
 }
Esempio n. 8
0
        public OrderModel PostBestSellOrder(CurrencyPair currencyPair, bool realTrade, double USDT = 0, ulong previousIdOrder = 0)
        {
            if (!realTrade)
            {
                return(PostBestSellOrderFictive(currencyPair, USDT));
            }

            var        tradeId              = new ulong();
            OrderModel order                = new OrderModel();
            double     bestPricePerCoin     = 0;
            double     bestPricePerCoinTemp = 0;
            double     amountQuote          = 0; // Quantité de la monnaie que je possède

            double profitMade = 0;
            IList <TradingTools.ITrade> trades = null;

            // Procéder à la vente
            do
            {
                try
                {
                    bestPricePerCoin = FindBestPrice(currencyPair, OrderType.Sell);
                    amountQuote      = InitPost(currencyPair, bestPricePerCoin, OrderType.Sell, USDT);

                    if (amountQuote == 0)
                    {
                        Debug.WriteLine(string.Format("\nY'A RIEN À VENDRE !!!"));
                        return(null);
                    }

                    // ### DANGER ### DANGER ### DANGER ### DANGER ### DANGER ### DANGER ### DANGER ### DANGER ### DANGER ###
                    // ######################################################################################################
                    tradeId = PostOrder(currencyPair, bestPricePerCoin, amountQuote, OrderType.Sell);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }
            }while (tradeId == 0);

            // Tant que tout n'est pas vendu
            while ((from x in GetBalances() where x.Type == currencyPair.QuoteCurrency select x.QuoteOnOrders).SingleOrDefault() > 0)
            {
                try
                {
                    bestPricePerCoinTemp = FindBestPrice(currencyPair, OrderType.Sell, amountQuote);

                    if (bestPricePerCoin != bestPricePerCoinTemp)   // empêche de me détrôner moi-même
                    {
                        bestPricePerCoin = bestPricePerCoinTemp;
                        Debug.WriteLine($"\nnew bestPrice: {bestPricePerCoin}");

                        amountQuote = (from x in GetBalances() where x.Type == currencyPair.QuoteCurrency select x.QuoteOnOrders).SingleOrDefault();

                        if (amountQuote > 0)
                        {
                            // Si erreur retournée = "Total must be at least 1", le move se fait pas et ça loop......
                            tradeId = MoveOrder(currencyPair, tradeId, bestPricePerCoin, amountQuote);
                        }

                        Debug.WriteLine(string.Format("MoveOrder: amountQuote = {0}", amountQuote));
                    }

                    Thread.Sleep(SLEEP_BETWEEN_MOVEORDER);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }
            }

            System.Media.SystemSounds.Exclamation.Play();
            Debug.WriteLine("SELL COMPLETED!\n");

            //if (previousIdOrder != 0)
            //{
            //    trades = GetTrades(currencyPair);
            //    profitMade = (trades.Where(x => x.IdOrder == tradeId).FirstOrDefault().PricePerCoin -
            //                  trades.Where(x => x.IdOrder == previousIdOrder).FirstOrDefault().PricePerCoin) /
            //                  trades.Where(x => x.IdOrder == previousIdOrder).FirstOrDefault().PricePerCoin;
            //}
            trades     = GetTrades(currencyPair);
            profitMade = (GetLastTrade(trades, OrderType.Sell) - GetLastTrade(trades, OrderType.Buy)) / GetLastTrade(trades, OrderType.Buy);

            PushMessage("SOLD!",
                        $"Currency: {currencyPair}\\n" +
                        $"USDT: {string.Format("{0:0.00}$", (from x in GetBalances() where x.Type == currencyPair.BaseCurrency select x.QuoteAvailable).SingleOrDefault())}\\n" +
                        $"At: {bestPricePerCoin}\\n" +
                        $"Profit: {string.Format("{0:0.00}%", profitMade * 100)}");

            order.CurrencyPair = currencyPair;
            order.OrderType    = OrderType.Buy;
            order.AmountBase   = 0;
            order.AmountQuote  = amountQuote;
            order.PricePerCoin = bestPricePerCoin;
            order.IdOrder      = ulong.Parse(tradeId.ToString());

            return(order);
        }
Esempio n. 9
0
 public IList <MarketTools.ITrade> MCGetTrades(CurrencyPair currencyPair, DateTime startTime, DateTime endTime)
 {
     return(MC.MCGetTrades(currencyPair, startTime, endTime));
 }
Esempio n. 10
0
 public IList <TradingTools.ITrade> GetTrades(CurrencyPair currencyPair, DateTime startTime, DateTime endTime)
 {
     return(TC.GetTrades(currencyPair, startTime, endTime));
 }
Esempio n. 11
0
 public IList <TradingTools.ITrade> GetTrades(CurrencyPair currencyPair)
 {
     return(TC.GetTrades(currencyPair));
 }
Esempio n. 12
0
 public IMarketData GetCurrency(IDictionary <CurrencyPair, IMarketData> markets, CurrencyPair currencyPair)
 {
     return(MC.GetMarket(markets, currencyPair));
 }
Esempio n. 13
0
 public IMarketData GetCurrency(CurrencyPair currencyPair)
 {
     return(MC.GetMarket(currencyPair));
 }
Esempio n. 14
0
 public bool Equals(CurrencyPair b)
 {
     return(b.BaseCurrency == BaseCurrency && b.QuoteCurrency == QuoteCurrency);
 }
Esempio n. 15
0
 public IOrderBook GetOpenOrders(CurrencyPair currencyPair, uint depth)
 {
     return(MC.GetOpenOrders(currencyPair, depth));
 }
Esempio n. 16
0
 public TickerChangedEventArgs(CurrencyPair currencyPair, MarketData marketData)
 {
     CurrencyPair = currencyPair;
     MarketData   = marketData;
 }
Esempio n. 17
0
        public OrderModel PostBestBuyOrder(CurrencyPair currencyPair, bool realTrade, double USDT = 0)
        {
            if (!realTrade)
            {
                return(PostBestBuyOrderFictive(currencyPair, USDT));
            }

            var        tradeId              = new ulong();
            OrderModel order                = new OrderModel();
            double     bestPricePerCoin     = 0;
            double     bestPricePerCoinTemp = 0;
            double     amountQuote          = 0; // Quantité de la monnaie à acheter

            // Procéder à l'achat
            do
            {
                try
                {
                    bestPricePerCoin = FindBestPrice(currencyPair, OrderType.Buy);
                    amountQuote      = InitPost(currencyPair, bestPricePerCoin, OrderType.Buy, USDT);

                    if (amountQuote == 0)
                    {
                        Debug.WriteLine(string.Format("\nY'A RIEN À ACHETER !!!"));
                        return(null);
                    }

                    // ### DANGER ### DANGER ### DANGER ### DANGER ### DANGER ### DANGER ### DANGER ### DANGER ### DANGER ###
                    // ######################################################################################################
                    tradeId = PostOrder(currencyPair, bestPricePerCoin, amountQuote, OrderType.Buy);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }
            }while (tradeId == 0);

            // Tant que tout n'est pas acheté
            while ((from x in GetBalances() where x.Type == currencyPair.BaseCurrency select x.QuoteOnOrders).SingleOrDefault() > 0)
            {
                try
                {
                    bestPricePerCoinTemp = FindBestPrice(currencyPair, OrderType.Buy, amountQuote);

                    if (bestPricePerCoin != bestPricePerCoinTemp)   // empêche de me détrôner moi-même
                    {
                        bestPricePerCoin = bestPricePerCoinTemp;
                        Debug.WriteLine($"\nnew bestPrice {bestPricePerCoin}");

                        amountQuote = Utilities.TruncateDouble((from x in GetBalances() where x.Type == currencyPair.BaseCurrency select x.QuoteOnOrders).SingleOrDefault() / bestPricePerCoin);

                        if (amountQuote > 0)
                        {
                            tradeId = MoveOrder(currencyPair, tradeId, bestPricePerCoin, amountQuote);
                        }

                        Debug.WriteLine(string.Format("MoveOrder: amountQuote = {0}", amountQuote));
                    }

                    Thread.Sleep(SLEEP_BETWEEN_MOVEORDER);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }
            }

            System.Media.SystemSounds.Exclamation.Play();
            Debug.WriteLine("BUY COMPLETED!\n");

            PushMessage("BOUGHT!",
                        $"Currency: {currencyPair}\\n" +
                        $"USDT: {string.Format("{0:0.00}$", (from x in GetBalances() where x.Type == currencyPair.QuoteCurrency select x.USDT_Value).SingleOrDefault())}\\n" +
                        $"At: {bestPricePerCoin}");

            order.CurrencyPair = currencyPair;
            order.OrderType    = OrderType.Buy;
            order.AmountBase   = 0;
            order.AmountQuote  = amountQuote;
            order.PricePerCoin = bestPricePerCoin;
            order.IdOrder      = ulong.Parse(tradeId.ToString());

            return(order);
        }