Exemplo n.º 1
0
        private async Task FlushEvent()
        {
            if (!_queue.Any())
            {
                return;
            }

            try
            {
                var events = GetQueuedEvents();
                if (!events.Any())
                {
                    return;
                }

                await _restClient.PostAsync(events);

                var unixTime    = UnixTime.Get();
                var lastRunTime = _lastFlushInMillis.Get() == 0 ? "never" : $"{(unixTime - _lastFlushInMillis.Get())/1000}";
                Logger.Info($"{events.Count} event(s) submitted. Elapsed time between last run {lastRunTime} seconds ago");

                _lastFlushInMillis.Set(unixTime);
            }
            catch (Exception e)
            {
                Logger.Error("There was an error submitting events to Unlaunch servers", e);
            }
        }
Exemplo n.º 2
0
        public async Task <CandlesResponse> GetCandles(string symbol, CandleInterval interval, DateTime start, DateTime end, int limit)
        {
            IDictionary <string, object> form = new Dictionary <string, object>(3)
            {
                ["start"] = UnixTime.Get(start),
                ["end"]   = UnixTime.Get(end),
                ["limit"] = limit
            };

            return(await this.Send <CandlesResponse>($"/klines/{symbol}/{this.ConvertToString(interval)}"));
        }
Exemplo n.º 3
0
        public void Date()
        {
            var unixTime = UnixTime.Get();

            CreateNotEqualsCondition(AttributeType.Date, unixTime.ToString());

            var attributes = new[]
            {
                UnlaunchAttribute.NewDate(AttributeKey, UnixTime.GetUtcDateTime(unixTime).AddDays(-1))
            };

            OnVariationTargetingRulesMatch(attributes);
        }
Exemplo n.º 4
0
        public void Date_userValue_is_less()
        {
            var date = DateTime.SpecifyKind(new DateTime(2019, 9, 26), DateTimeKind.Utc);

            CreateGreaterThanCondition(AttributeType.Date, UnixTime.Get(date).ToString());

            var attributes = new[]
            {
                UnlaunchAttribute.NewDate(AttributeKey, date.AddDays(-1))
            };

            OffVariationTargetingRulesNotMatch(attributes);
        }
Exemplo n.º 5
0
        public void DateTime_userValue_is_one_second_behind()
        {
            var unixTime = UnixTime.Get();

            CreateNotEqualsCondition(AttributeType.DateTime, unixTime.ToString());

            var attributes = new[]
            {
                UnlaunchAttribute.NewDateTime(AttributeKey, UnixTime.GetUtcDateTime(unixTime - 1000))
            };

            OnVariationTargetingRulesMatch(attributes);
        }
Exemplo n.º 6
0
        public void DateTime_userValue_is_less()
        {
            var unixTime = UnixTime.Get();

            CreateGreaterThanCondition(AttributeType.DateTime, unixTime.ToString());

            var attributes = new[]
            {
                UnlaunchAttribute.NewDateTime(AttributeKey, UnixTime.GetUtcDateTime(unixTime - 1000))
            };

            OffVariationTargetingRulesNotMatch(attributes);
        }
Exemplo n.º 7
0
        public void Date_userValue_is_greater_unixTime()
        {
            var unixTime = UnixTime.Get();

            CreateGreaterThanCondition(AttributeType.Date, unixTime.ToString());

            var attributes = new[]
            {
                UnlaunchAttribute.NewDate(AttributeKey, UnixTime.GetUtcDateTime(unixTime).AddDays(1))
            };

            OnVariationTargetingRulesMatch(attributes);
        }
Exemplo n.º 8
0
        public void DateTime_userValue_is_greater()
        {
            var date = DateTime.UtcNow;

            CreateLessThanCondition(AttributeType.DateTime, UnixTime.Get(date).ToString());

            var attributes = new[]
            {
                UnlaunchAttribute.NewDateTime(AttributeKey, date.AddSeconds(2))
            };

            OffVariationTargetingRulesNotMatch(attributes);
        }
Exemplo n.º 9
0
        public void Date_userValue_is_one_hour_less_which_is_previous_day()
        {
            var date = DateTime.SpecifyKind(new DateTime(2019, 9, 26), DateTimeKind.Utc);

            CreateGreaterThanCondition(AttributeType.Date, UnixTime.Get(date).ToString());

            var attributes = new[]
            {
                UnlaunchAttribute.NewDate(AttributeKey, date.AddHours(1)) // one hour more but still in same day
            };

            OffVariationTargetingRulesNotMatch(attributes);
        }
Exemplo n.º 10
0
        public void Date_userValue_is_the_same_dateTime()
        {
            var date = DateTime.SpecifyKind(new DateTime(2019, 9, 26), DateTimeKind.Utc);

            CreateEqualsCondition(AttributeType.Date, UnixTime.Get(date).ToString());

            var attributes = new[]
            {
                UnlaunchAttribute.NewDate(AttributeKey, date)
            };

            OnVariationTargetingRulesMatch(attributes);
        }
Exemplo n.º 11
0
        public void DateTime_userValue_is_same_dateTime()
        {
            var date = DateTime.UtcNow;

            CreateEqualsCondition(AttributeType.DateTime, UnixTime.Get(date).ToString());

            var attributes = new[]
            {
                UnlaunchAttribute.NewDateTime(AttributeKey, date)
            };

            OnVariationTargetingRulesMatch(attributes);
        }
Exemplo n.º 12
0
        [Fact] public void Date_userValue_is_the_same_unixTime()
        {
            var unixTime = UnixTime.Get();

            CreateGteCondition(AttributeType.Date, unixTime.ToString());

            var attributes = new[]
            {
                UnlaunchAttribute.NewDate(AttributeKey, UnixTime.GetUtcDateTime(unixTime))
            };

            OnVariationTargetingRulesMatch(attributes);
        }
Exemplo n.º 13
0
        public void DateTime_userValue_is_greater_unixTime()
        {
            var unixTime = UnixTime.Get();

            CreateLteCondition(AttributeType.DateTime, unixTime.ToString());

            var attributes = new[]
            {
                UnlaunchAttribute.NewDateTime(AttributeKey, unixTime + 1000)
            };

            OffVariationTargetingRulesNotMatch(attributes);
        }
Exemplo n.º 14
0
        private static bool Equals(string value, IUnlaunchValue userValue, AttributeType type)
        {
            switch (type)
            {
            case AttributeType.DateTime:
            {
                var userDateTime = (DateTime)userValue.Get();
                return(UnixTime.Get(userDateTime) == long.Parse(value));
            }

            case AttributeType.Date:
            {
                var userDateTime = (DateTime)userValue.Get();
                return(userDateTime.Date == UnixTime.GetUtcDateTime(long.Parse(value)).Date);
            }

            case AttributeType.Set:
            {
                var userSet = (ISet <string>)userValue.Get();
                return(userSet.SetEquals(value.Split(',')));
            }

            case AttributeType.Number:
            {
                var userNumber = (double)userValue.Get();
                // ReSharper disable once CompareOfFloatsByEqualityOperator
                return(userNumber == double.Parse(value));
            }

            case AttributeType.Boolean:
            {
                var userBoolean = (bool)userValue.Get();
                return(userBoolean == (value.ToLower() == "true"));
            }

            default:
                return((string)userValue.Get() == value);
            }
        }
Exemplo n.º 15
0
        static void Main(string[] args)
        {
            TradeioApi api    = new TradeioApi("aaaaaaaa-bbbb-cccc-dddd-eeeeeeee", "aaaaaaaa-bbbb-cccc-dddd-eeeeeeee");
            string     symbol = "btc_usdt";

            Console.WriteLine("******PAIRS******");
            PairsResponse pairsResponse = api.GetPairs().Result;

            Console.WriteLine(string.Join(',', pairsResponse.Pairs));

            Console.WriteLine("******CANDLES******");
            CandlesResponse candles = api.GetCandles("btc_usdt", CandleInterval.OneDay, DateTime.UtcNow.AddMonths(-1), DateTime.UtcNow, 20).Result;

            foreach (CandleInfo candle in candles.Candles)
            {
                Console.WriteLine($"open: {candle.Open}; close: {candle.Close}; low: {candle.Low}; high: {candle.High}");
            }

            Console.WriteLine("******ORDER BOOK******");
            OrderBookResponse orderBookResponse = api.GetOrderBook(symbol, 2).Result;

            Console.WriteLine("***ASK***");
            foreach (var askArray in orderBookResponse.Book.Asks)
            {
                Console.WriteLine($"Price: {askArray[0]}; Count: {askArray[1]}");
            }
            Console.WriteLine("***BID***");
            foreach (var bidArray in orderBookResponse.Book.Bids)
            {
                Console.WriteLine($"Price: {bidArray[0]}; Count: {bidArray[1]}");
            }

            Console.WriteLine("******TICKER******");
            TickerResponse tickerResponse = api.GetTicker(symbol).Result;

            Console.WriteLine($"ASK price: {tickerResponse.Ticker.AskPrice}, qty: {tickerResponse.Ticker.AskQty}; BID price: {tickerResponse.Ticker.BidPrice}, qty: {tickerResponse.Ticker.BidQty}");
            //tickers for all pairs
            //var tickers = api.GetTickers().Result;

            Console.WriteLine("******RECENT TRADES******");
            TradesResponse tradesResponse = api.GetRecentTrades("btc_usdt", 2).Result;

            foreach (TradeInfo trade in tradesResponse.Trades)
            {
                Console.WriteLine($"{trade.Symbol} price: {trade.Price}, qty: {trade.Quantity}, side: {trade.Type}, date: {UnixTime.GetDateTime(trade.Time)} UTC");
            }


            //PRIVATE METHODS. NOT WORKING WITHOUT PUBLIC AND PRIVATE KEY

            Console.WriteLine("******CURRENT BALANCES******");
            AccountBalanceResponse accountBalance = api.GetAccount().Result;

            foreach (BalanceInfo balanceInfo in accountBalance.Balances)
            {
                Console.WriteLine($"{balanceInfo.Asset}:{balanceInfo.Available} (locked: {balanceInfo.Locked})");
            }

            Console.WriteLine("******OPEN ORDERS******");
            OrdersResponse ordersResponse = api.GetOpenOrders(symbol).Result;

            foreach (OrderInfoResponse order in ordersResponse.Orders)
            {
                Console.WriteLine($"{order.Side} {order.Instrument} for {order.Price}. Filled: {order.UnitsFilled}");
            }
            Console.WriteLine("******CLOSED ORDERS******");
            FilteredResponse <OrderInfoResponse> closeOrdersResponse = api.GetClosedOrders(symbol, UnixTime.Get(DateTime.UtcNow.AddDays(-1)), UnixTime.Get(DateTime.UtcNow)).Result;

            foreach (OrderInfoResponse order in closeOrdersResponse.Data)
            {
                Console.WriteLine($"{order.Side} {order.Instrument} for {order.Price}. Filled: {order.UnitsFilled}. Status: {order.Status}");
            }
            Console.WriteLine("******PLACE ORDER******");
            var orderResponse = api.PlaceOrder(new Models.OrderRequest()
            {
                Price    = 4000,
                Quantity = 10,
                Side     = Models.OrderSide.Buy,
                Symbol   = symbol,
                Type     = Models.OrderType.Limit
            }).Result;

            Console.WriteLine("******CANCEL ORDER******");
            Response response = api.CancelOrder(orderResponse.Order.OrderId).Result;

            if (response.Code == 200)
            {
                Console.WriteLine("Order canceled");
            }
            Console.ReadLine();
        }