예제 #1
0
파일: Program.cs 프로젝트: thewindev/CryBot
        private static async Task PlayWithBitmex()
        {
            try
            {
                const string market = "XBTUSD";
                var          bitmexAuthorization = new BitmexAuthorization();
                bitmexAuthorization.BitmexEnvironment = BitmexEnvironment.Test;
                bitmexAuthorization.Key    = "wcZtcAiFMff8kLWaSLl8U877";
                bitmexAuthorization.Secret = "uOtP5-0sEtiis5d1_Qv1-LW8FLsV3qW9Qsmsf_OWBXVzw-c3";
                _bitmexApiService          = BitmexApiService.CreateDefaultApi(bitmexAuthorization);

                await _bitmexApiService.Execute(BitmexApiUrls.Order.DeleteOrderAll, new OrderAllDELETERequestParams
                {
                    Symbol = "BCHU18"
                });

                var bitcoinOrderBook = await _bitmexApiService.Execute(BitmexApiUrls.OrderBook.GetOrderBookL2,
                                                                       new OrderBookL2GETRequestParams { Depth = 1, Symbol = market });

                var currentPrice  = Math.Round((bitcoinOrderBook[0].Price + bitcoinOrderBook[1].Price) / 2);
                var stopSellOrder = await _bitmexApiService.Execute(BitmexApiUrls.Order.PostOrder, OrderPOSTRequestParams.CreateLimitStopOrder(market, 1500, 6500, 6467, OrderSide.Buy));

                var positions = await _bitmexApiService.Execute(BitmexApiUrls.Position.GetPosition, new PositionGETRequestParams { Count = 50 });

                var positionLeveragePostRequestParams = new PositionLeveragePOSTRequestParams();
                positionLeveragePostRequestParams.Leverage = 50;
                positionLeveragePostRequestParams.Symbol   = market;

                /*var positionDto = await bitmexApiService.Execute(BitmexApiUrls.Position.PostPositionLeverage,
                 *  positionLeveragePostRequestParams);*/
                foreach (var position in positions)
                {
                    await _bitmexApiService.Execute(BitmexApiUrls.Order.PostOrder, OrderPOSTRequestParams.ClosePositionByMarket(market));
                }
                var positionDto = await _bitmexApiService.Execute(BitmexApiUrls.Position.PostPositionLeverage, positionLeveragePostRequestParams);

                var initialOrder = await CreateLimitOrder(market, 1500, currentPrice, OrderSide.Sell);

                var round     = Math.Round((decimal)initialOrder.Price * 0.9M, 0);
                var stopOrder = await _bitmexApiService.Execute(BitmexApiUrls.Order.PostOrder, OrderPOSTRequestParams.CreateSimpleHidenLimit(market, 1500, round, OrderSide.Buy));

                var stopLoss = await CreateLimitOrder(market, 1500, currentPrice + 40, OrderSide.Sell);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }