public MainWindowViewModel() { _bitmexAuthorization = new BitmexAuthorization() { BitmexEnvironment = BitmexEnvironment.Test }; _bitmexApiService = BitmexApiService.CreateDefaultApi(_bitmexAuthorization); BuyCmd = new DelegateCommand(Buy); SellCmd = new DelegateCommand(Sell); Size = 1; }
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); }
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); }
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); } }
public MainWindowViewModel() { _bitmexAuthorization = new BitmexAuthorization { BitmexEnvironment = BitmexEnvironment.Test }; _bitmexApiService = BitmexApiService.CreateDefaultApi(_bitmexAuthorization); _bitmexApiSocketService = BitmexApiSocketService.CreateDefaultApi(_bitmexAuthorization); BuyCmd = new DelegateCommand(Buy); SellCmd = new DelegateCommand(Sell); StartLoadSymbolsCmd = new DelegateCommand(StartLoad, CanStart); Size = 1; Instruments = new ObservableCollection <InstrumentModel>(); OrderUpdates = new ObservableCollection <OrderUpdateModel>(); BindingOperations.EnableCollectionSynchronization(Instruments, _syncObj); BindingOperations.EnableCollectionSynchronization(OrderUpdates, _syncObjOrders); }
private void btn1_Click(object sender, EventArgs e) { LabelOnOff.Text = (LabelOnOff.Text == "OFF") ? "ON" : "OFF"; var posOrderParamsA = OrderPOSTRequestParams.CreateMarketStopOrder("XBTUSD", 150, 8000, OrderSide.Buy); bitmexApiServiceA = BitmexApiService.CreateDefaultApi(_bitmexAuthorizationA); bitmexApiServiceA.Execute(BitmexApiUrls.Order.PostOrder, posOrderParamsA).ContinueWith(ProcessPostOrderResult); var posOrderParamsB = OrderPOSTRequestParams.CreateMarketStopOrder("XBTUSD", 150, 6500, OrderSide.Sell); bitmexApiServiceB = BitmexApiService.CreateDefaultApi(_bitmexAuthorizationB); bitmexApiServiceB.Execute(BitmexApiUrls.Order.PostOrder, posOrderParamsB).ContinueWith(ProcessPostOrderResult); }
// TODO: Simplify private void ConfigureRestApi() { var appSettings = ConfigurationManager.AppSettings; string apiA, secA, apiB, secB; BitmexEnvironment env; if (_view.isTest) { apiA = appSettings["API_KEY_BITMEX_A_TEST"] ?? string.Empty; secA = appSettings["API_SECRET_BITMEX_A_TEST"] ?? string.Empty; apiB = appSettings["API_KEY_BITMEX_B_TEST"] ?? string.Empty; secB = appSettings["API_SECRET_BITMEX_B_TEST"] ?? string.Empty; env = BitmexEnvironment.Test; } else { apiA = appSettings["API_KEY_BITMEX_A_LIVE"] ?? string.Empty; secA = appSettings["API_SECRET_BITMEX_A_LIVE"] ?? string.Empty; apiB = appSettings["API_KEY_BITMEX_B_LIVE"] ?? string.Empty; secB = appSettings["API_SECRET_BITMEX_B_LIVE"] ?? string.Empty; env = BitmexEnvironment.Prod; } if (!string.IsNullOrEmpty(apiA) && !string.IsNullOrEmpty(secA) && !string.IsNullOrEmpty(apiB) && !string.IsNullOrEmpty(secB)) { bitmexApiServiceA = BitmexApiService.CreateDefaultApi(new BitmexAuthorization { BitmexEnvironment = env, Key = apiA, Secret = secA }); bitmexApiServiceB = BitmexApiService.CreateDefaultApi(new BitmexAuthorization { BitmexEnvironment = env, Key = apiB, Secret = secB }); } else { throw new NullReferenceException("API key or secret missing"); } }
private void CreateServices() { try { _bitmexAuthorization = new BitmexAuthorization() { BitmexEnvironment = BitmexEnvironment.Prod, Key = "Your_API_Key", Secret = "Your_API_Secret" }; _bitmexApiService = BitmexApiService.CreateDefaultApi(_bitmexAuthorization); _bitmexApiSocketService = BitmexApiSocketService.CreateDefaultApi(_bitmexAuthorization); _bitmexApiSocketService.Connect(); } catch (Exception e) { Console.WriteLine(e); } }
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); }
private async void ChaseOrder() { var putOrderParams = OrderPUTRequestParams.ModifyOrderByID(SelectedOrder, NewOrderPrice, NewOrderQty); var bitmexApiService = BitmexApiService.CreateDefaultApi(_bitmexAuthorization); await bitmexApiService.Execute(BitmexApiUrls.Order.PutOrder, putOrderParams); }
private async void CancleOrder() { var deleteOrderParams = OrderDELETERequestParams.CancleOrderByID(SelectedOrder); var bitmexApiService = BitmexApiService.CreateDefaultApi(_bitmexAuthorization); await bitmexApiService.Execute(BitmexApiUrls.Order.DeleteOrder, deleteOrderParams); }
private async void BuyLimit() { var posOrderParams = OrderPOSTRequestParams.CreateSimpleLimit(_pair, Size, Price, OrderSide.Buy); var bitmexApiService = BitmexApiService.CreateDefaultApi(_bitmexAuthorization); await bitmexApiService.Execute(BitmexApiUrls.Order.PostOrder, posOrderParams).ContinueWith(ProcessPostOrderResult); }
private async void Sell() { var posOrderParams = OrderPOSTRequestParams.CreateSimpleMarket("XBTUSD", Size, OrderSide.Sell); var bitmexApiService = BitmexApiService.CreateDefaultApi(_bitmexAuthorization); await bitmexApiService.Execute(BitmexApiUrls.Order.PostOrder, posOrderParams).ContinueWith(ProcessPostOrderResult); }