static async Task Main(string[] args)
        {
            // connect to API
            var key = Environment.GetEnvironmentVariable("HFT_API_KEY");
            var api = new ApiTrader("https://hft-apiv2-grpc.lykke.com", key);

            // create a bot with BTCUSD pair
            var trader = new MarketManager(api, "BTCUSD");

            // init trading bot: Current Price = 10950, Limit Order size = 0.0001 BTC, Delta(level spread) = 10 USD, count level per side = 15
            trader.ResetMarke(10950, 0.0001m, 10, 15);

            // place Limit Orders
            await trader.PlaceToMarketAsync();

            while (true)
            {
                try
                {
                    // subscribe to trade stream
                    var tradeStream = api.Client.PrivateApi.GetTradeUpdates(new Empty());

                    // wait next trade event
                    while (await tradeStream.ResponseStream.MoveNext())
                    {
                        // handle each trade from event
                        foreach (var trade in tradeStream.ResponseStream.Current.Trades)
                        {
                            Console.WriteLine($"TRADE: orderId: {trade.OrderId}, size: {trade.BaseVolume}, role: {trade.Role}");
                            await trader.HandleTrade(trade.OrderId);
                        }

                        // place new Limit Orders
                        await trader.PlaceToMarketAsync();
                    }

                    tradeStream.Dispose();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error on stream read:");
                    Console.WriteLine(ex);
                }
            }
        }
示例#2
0
        static async Task Main(string[] args)
        {
            var key = Environment.GetEnvironmentVariable("HFT_API_KEY");
            var api = new ApiTrader("https://hft-apiv2-grpc.lykke.com", key);

            var trader = new MarketManager(api, "BTCUSD");

            trader.ResetMarke(10950, 0.0001m, 10, 15);
            await trader.PlaceToMarketAsync();

            while (true)
            {
                try
                {
                    var tradeStream = api.Client.PrivateApi.GetTradeUpdates(new Empty());

                    while (await tradeStream.ResponseStream.MoveNext())
                    {
                        foreach (var trade in tradeStream.ResponseStream.Current.Trades)
                        {
                            Console.WriteLine($"TRADE: orderId: {trade.OrderId}, size: {trade.BaseVolume}, role: {trade.Role}");
                            await trader.HandleTrade(trade.OrderId);
                        }

                        await trader.PlaceToMarketAsync();
                    }

                    tradeStream.Dispose();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error on stream read:");
                    Console.WriteLine(ex);
                }
            }
        }
示例#3
0
        static async Task Main(string[] args)
        {
            var key = Environment.GetEnvironmentVariable("HFT_API_KEY");
            var api = new ApiTrader("https://hft-apiv2-grpc.lykke.com", key);

            var trader = new MarketManager(api, "ETHUSD");

            await trader.ResetMarke(350, 0.001m, 1, 50,
                                    0.1m, 4,
                                    0m, 0);

            await trader.PlaceToMarketAsync();

            var tradeReader = TradeReader(api, trader);

            var pulser = Pulser(trader);

            var cmd = Console.ReadLine();

            while (cmd != "exit")
            {
                cmd = Console.ReadLine();
            }
        }
示例#4
0
        static async Task MainMock(string[] args)
        {
            var api = new Mock();

            var trader = new MarketManager(api, "BTCUSD");

            await trader.ResetMarke(10500, 0.0001m, 10, 10,
                                    1m, 4, 0m, 0);

            await trader.PlaceToMarketAsync();

            Console.WriteLine();
            Console.WriteLine("-------------------------");
            Console.WriteLine();
            Console.ReadLine();
            await trader.Pulse();

            Console.WriteLine();
            Console.WriteLine("-------------------------");
            Console.WriteLine();
            Console.ReadLine();
            await trader.Pulse();

            Console.WriteLine();
            Console.WriteLine("-------------------------");
            Console.Write("orderId: ");
            var oid = Console.ReadLine();

            Console.Write("size: ");
            var sz = decimal.Parse(Console.ReadLine());

            await trader.HandleTrade(oid, sz);

            await trader.PlaceToMarketAsync();

            await trader.Pulse();

            Console.WriteLine();
            Console.WriteLine("-------------------------");
            Console.Write("orderId: ");
            oid = Console.ReadLine();
            Console.Write("size: ");
            sz = decimal.Parse(Console.ReadLine());

            await trader.HandleTrade(oid, sz);

            await trader.PlaceToMarketAsync();

            await trader.Pulse();

            Console.WriteLine();
            Console.WriteLine("-------------------------");
            Console.Write("orderId: ");
            oid = Console.ReadLine();
            Console.Write("size: ");
            sz = decimal.Parse(Console.ReadLine());

            await trader.HandleTrade(oid, sz);

            await trader.PlaceToMarketAsync();

            await trader.Pulse();
        }