Beispiel #1
0
        protected override void Initialize()
        {
            Container.RegisterType <IBitmexApiProxy, BitmexApiProxy>();
            Container.RegisterType <IBitmexApiService, BitmexApiService>();
            Container.RegisterType <IBitmexApiSocketService, BitmexApiSocketService>();
            Container.RegisterType <IBitmexApiSocketProxy, BitmexApiSocketProxy>();
            Container.RegisterType <IExpiresTimeProvider, ExpiresTimeProvider>(new ContainerControlledLifetimeManager());
            Container.RegisterType <ISignatureProvider, SignatureProvider>(new ContainerControlledLifetimeManager());

            var config = new ConfigurationBuilder()
                         .AddJsonFile("appsettings.test.json")
                         .Build();

            var key               = config.GetValue <string>("Key");
            var secret            = config.GetValue <string>("Secret");
            var env               = config.GetValue <string>("Environment");
            var bitmexEnvironment = (BitmexEnvironment)Enum.Parse(typeof(BitmexEnvironment), env);

            var authorization = new BitmexAuthorization
            {
                Key               = key,
                Secret            = secret,
                BitmexEnvironment = bitmexEnvironment,
            };

            Container.RegisterInstance <IBitmexAuthorization>(authorization);
        }
Beispiel #2
0
        public BitmexManager(string accessKey, string accessSecret, bool isTestEnvironment)
        {
            _accessKey    = accessKey;
            _accessSecret = accessSecret;

            var bitmexAuthorization = new BitmexAuthorization()
            {
                BitmexEnvironment = isTestEnvironment ? BitmexEnvironment.Test : BitmexEnvironment.Prod,
                Key    = accessKey,
                Secret = accessSecret
            };
            var _client = BitmexApiService.CreateDefaultApi(bitmexAuthorization);
        }
Beispiel #3
0
        private IBitmexApiService CreateBitmexClient()
        {
            var bitmexAuthorization = new BitmexAuthorization
            {
                BitmexEnvironment = Environment.GetEnvironmentVariable("bitmexEnvironment") == "Test"
                    ? BitmexEnvironment.Test
                    : BitmexEnvironment.Prod,
                Key    = Environment.GetEnvironmentVariable("bitmexTestnetKey"),
                Secret = Environment.GetEnvironmentVariable("bitmexTestnetSecret")
            };
            var bitmexApiService = BitmexApiService.CreateDefaultApi(bitmexAuthorization);

            return(bitmexApiService);
        }
Beispiel #4
0
        protected override void Initialize()
        {
            Container.RegisterType <IBitmexApiProxy, BitmexApiProxy>();
            Container.RegisterType <IBitmexApiService, BitmexApiService>();

            var authorization = new BitmexAuthorization
            {
                Key               = ConfigurationManager.AppSettings["Key"],
                Secret            = ConfigurationManager.AppSettings["Secret"],
                BitmexEnvironment =
                    (BitmexEnvironment)Enum.Parse(typeof(BitmexEnvironment), ConfigurationManager.AppSettings["Environment"]),
            };

            Container.RegisterInstance <IBitmexAuthorization>(authorization);
        }
Beispiel #5
0
        static Container RegisterBitmexAPI(this Container c)
        {
            c.Register <IBitmexApiProxy, BitmexApiProxy>(Lifestyle.Singleton);
            c.Register <IBitmexApiService, BitmexApiService>(Lifestyle.Singleton);

            var authorization = new BitmexAuthorization
            {
                BitmexEnvironment = Bitmex.NET.Models.BitmexEnvironment.Test,
                Key    = KEY,
                Secret = SECRET
            };

            c.RegisterInstance <IBitmexAuthorization>(authorization);
            return(c);
        }
Beispiel #6
0
        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);
            }
        }
        protected override void Initialize()
        {
            Container.RegisterType <IBitmexApiProxy, BitmexApiProxy>();
            Container.RegisterType <IBitmexApiService, BitmexApiService>();
            Container.RegisterType <IBitmexApiSocketService, BitmexApiSocketService>();
            Container.RegisterType <IBitmexApiSocketProxy, BitmexApiSocketProxy>();
            Container.RegisterType <INonceProvider, NonceProvider>(new ContainerControlledLifetimeManager());
            Container.RegisterType <ISignatureProvider, SignatureProvider>(new ContainerControlledLifetimeManager());

            var authorization = new BitmexAuthorization
            {
                Key               = ConfigurationManager.AppSettings["Key"],
                Secret            = ConfigurationManager.AppSettings["Secret"],
                BitmexEnvironment =
                    (BitmexEnvironment)Enum.Parse(typeof(BitmexEnvironment), ConfigurationManager.AppSettings["Environment"]),
            };

            Container.RegisterInstance <IBitmexAuthorization>(authorization);
        }
        private IBitmexApiService CreateBitmexClient(string env)
        {
            var key = env == "Test"
                ? Environment.GetEnvironmentVariable("bitmexTestnetKey")
                : Environment.GetEnvironmentVariable("bitmexProdKey");
            var secret = env == "Test"
                ? Environment.GetEnvironmentVariable("bitmexTestnetSecret")
                : Environment.GetEnvironmentVariable("bitmexProdSecret");
            var bitmexAuthorization = new BitmexAuthorization
            {
                BitmexEnvironment = env == "Test"
                    ? BitmexEnvironment.Test
                    : BitmexEnvironment.Prod,
                Key    = key,
                Secret = secret
            };
            var bitmexApiService = BitmexApiService.CreateDefaultApi(bitmexAuthorization);

            return(bitmexApiService);
        }