public ZoneRecoveryBatchOrder(ZoneRecoveryAccount acc, OrderPOSTRequestParams postParams, ZoneRecoveryOrderType orderType) { PostParams = postParams; Account = acc; CurrentStatus = ZoneRecoveryOrderStatus.Undefined; OrderType = orderType; }
public void should_close_short_martket_position_by_limit() { // arrange DeleteAllOrders(); var @params = OrderPOSTRequestParams.CreateSimpleMarket("XBTUSD", 3, OrderSide.Sell); var result = Sut.Execute(BitmexApiUrls.Order.PostOrder, @params).Result; result.Should().NotBeNull(); result.OrdStatus.Should().Be("Filled"); result.OrderId.Should().NotBeNull(); // act var @paramsClosePosition = new OrderClosePositionPOSTRequestParams { Symbol = "XBTUSD", Price = _xbtAvgPrice - 500 }; var resultClosePostion = Sut.Execute(BitmexApiUrls.Order.PostOrderClosePosition, @paramsClosePosition).Result; Thread.Sleep(1000); // assert resultClosePostion.Should().NotBeNull(); resultClosePostion.OrderId.Should().NotBeNull(); }
public void should_receive_position_change_notification() { // arrange var connected = Sut.Connect(); var @params = OrderPOSTRequestParams.CreateSimpleMarket("XBTUSD", 3, OrderSide.Buy); // act IList <PositionDto> dtos = null; var dataReceived = new ManualResetEvent(false); Sut.Subscribe(BitmexApiSubscriptionInfo <IEnumerable <PositionDto> > .Create(SubscriptionType.position, a => { dtos = a.ToList(); dataReceived.Set(); })); var result = _bitmexApiService.Execute(BitmexApiUrls.Order.PostOrder, @params).Result; result.Should().NotBeNull(); result.OrdType.Should().Be("Market"); result.OrdStatus.Should().Be("Filled"); result.OrderId.Should().NotBeNull(); var received = dataReceived.WaitOne(TimeSpan.FromSeconds(20)); // assert // no exception raised connected.Should().BeTrue(); received.Should().BeTrue("data hasn't received"); dtos.Should().NotBeNull(); dtos.Count().Should().BeGreaterThan(0); }
public void should_cancel_order_by_setting_qty_to_0() { // arrange var @params = OrderPOSTRequestParams.CreateSimpleLimit("XBTUSD", 3, _xbtAvgPrice - LimitPriceSubtractor, OrderSide.Buy); var result = Sut.Execute(BitmexApiUrls.Order.PostOrder, @params).Result.Result; result.Should().NotBeNull(); result.OrdType.Should().Be("Limit"); result.OrdStatus.Should().Be("New"); result.OrderId.Should().NotBeNull(); var @paramsPut = new OrderPUTRequestParams() { OrderID = result.OrderId, OrderQty = 0 }; // act var resultPut = Sut.Execute(BitmexApiUrls.Order.PutOrder, paramsPut).Result.Result; // assert resultPut.Should().NotBeNull(); resultPut.OrdType.Should().Be("Limit"); resultPut.OrdStatus.Should().Be("Canceled"); resultPut.OrderId.Should().NotBeNull(); }
public void should_receive_limit_order_notification() { // arrange var connected = Sut.Connect(); var @params = OrderPOSTRequestParams.CreateSimpleLimit("XBTUSD", 3, _xbtAvgPrice - 500, OrderSide.Buy); // act IList <OrderDto> dtos = null; var dataReceived = new ManualResetEvent(false); Sut.Subscribe(BitmexApiSubscriptionInfo <IEnumerable <OrderDto> > .Create(SubscriptionType.order, a => { dtos = a.ToList(); dataReceived.Set(); })); var result = _bitmexApiService.Execute(BitmexApiUrls.Order.PostOrder, @params).Result; result.Should().NotBeNull(); result.OrdType.Should().Be("Limit"); result.OrdStatus.Should().Be("New"); result.OrderId.Should().NotBeNull(); Thread.Sleep(2000); var received = dataReceived.WaitOne(TimeSpan.FromSeconds(20)); // assert // no exception raised connected.Should().BeTrue(); received.Should().BeTrue(); dtos.Should().NotBeNull(); dtos.Count().Should().BeGreaterThan(0); dtos[0].OrdType.Should().Be("Limit"); dtos[0].OrdStatus.Should().Be("New"); dtos[0].OrderId.Should().Be(result.OrderId); }
public void should_change_sell_limit_order() { // arrange var @params = OrderPOSTRequestParams.CreateMarketStopOrder("XBTUSD", 3, _xbtAvgPrice - LimitPriceSubtractor, OrderSide.Sell); var result = Sut.Execute(BitmexApiUrls.Order.PostOrder, @params).Result.Result; result.Should().NotBeNull(); result.OrdType.Should().Be("Stop"); result.OrdStatus.Should().Be("New"); result.OrderId.Should().NotBeNull(); var @paramsPut = new OrderPUTRequestParams() { OrderID = result.OrderId, OrderQty = 2 }; // act var resultPut = Sut.Execute(BitmexApiUrls.Order.PutOrder, paramsPut).Result.Result; // assert resultPut.Should().NotBeNull(); resultPut.OrdType.Should().Be("Stop"); resultPut.OrdStatus.Should().Be("New"); resultPut.OrderQty.Should().Be(2); resultPut.OrderId.Should().NotBeNull(); }
public void should_delete_sell_limit_order() { // arrange var @params = OrderPOSTRequestParams.CreateMarketStopOrder("XBTUSD", 3, _xbtAvgPrice - LimitPriceSubtractor, OrderSide.Sell); var result = Sut.Execute(BitmexApiUrls.Order.PostOrder, @params).Result.Result; result.Should().NotBeNull(); result.OrdType.Should().Be("Stop"); result.OrdStatus.Should().Be("New"); result.OrderId.Should().NotBeNull(); var @paramsPut = new OrderDELETERequestParams() { OrderID = result.OrderId, Text = "testing api" }; // act var resultDelete = Sut.Execute(BitmexApiUrls.Order.DeleteOrder, paramsPut).Result.Result.FirstOrDefault(a => a.OrderId == result.OrderId); // assert resultDelete.Should().NotBeNull(); resultDelete.OrdType.Should().Be("Stop"); resultDelete.OrdStatus.Should().Be("Canceled"); resultDelete.OrderId.Should().NotBeNull(); }
public void should_delete_many_buy_orders() { // arrange var @params = new OrderBulkPOSTRequestParams { Orders = new[] { OrderPOSTRequestParams.CreateSimpleHidenLimit("XBTUSD", 3, _xbtAvgPrice - LimitPriceSubtractor, OrderSide.Buy), OrderPOSTRequestParams.CreateSimpleHidenLimit("XBTUSD", 3, _xbtAvgPrice - LimitPriceSubtractor, OrderSide.Buy) } }; var resultInsert = Sut.Execute(BitmexApiUrls.Order.PostOrderBulk, @params).Result.Result; // act var @paramsToDelete = new OrderDELETERequestParams { OrderID = string.Join(",", resultInsert.Select(a => a.OrderId)) }; var result = Sut.Execute(BitmexApiUrls.Order.DeleteOrder, @paramsToDelete).Result.Result; // assert result.Should().NotBeNull(); result.All(a => a.OrdStatus == "Canceled").Should().BeTrue(); result.All(a => !string.IsNullOrWhiteSpace(a.OrderId)).Should().BeTrue(); }
public void should_amend_sell_limit_orders_bulk() { // arrange var @params = new OrderBulkPOSTRequestParams { Orders = new[] { OrderPOSTRequestParams.CreateSimpleHidenLimit("XBTUSD", 3, _xbtAvgPrice + LimitPriceSubtractor, OrderSide.Sell), OrderPOSTRequestParams.CreateSimpleHidenLimit("XBTUSD", 3, _xbtAvgPrice + LimitPriceSubtractor, OrderSide.Sell) } }; var result = Sut.Execute(BitmexApiUrls.Order.PostOrderBulk, @params).Result.Result; result.Should().NotBeNull(); result.All(a => a.OrdStatus == "New").Should().BeTrue(); result.All(a => !string.IsNullOrWhiteSpace(a.OrderId)).Should().BeTrue(); var @paramsPut = new OrderBulkPUTRequestParams() { Orders = result.Select(a => new OrderPUTRequestParams() { OrderID = a.OrderId, OrderQty = 2, }).ToArray() }; // act var resultPut = Sut.Execute(BitmexApiUrls.Order.PutOrderBulk, @paramsPut).Result.Result; // assert resultPut.Should().NotBeNull(); resultPut.All(a => a.OrdStatus == "New").Should().BeTrue(); resultPut.All(a => a.OrderQty == 2).Should().BeTrue(); resultPut.All(a => !string.IsNullOrWhiteSpace(a.OrderId)).Should().BeTrue(); }
public void should_cancel_all_sell_limit_orders_after() { // arrange var @params = OrderPOSTRequestParams.CreateSimpleHidenLimit("XBTUSD", 3, _xbtAvgPrice + LimitPriceSubtractor, OrderSide.Sell); var result = Sut.Execute(BitmexApiUrls.Order.PostOrder, @params).Result.Result; result.Should().NotBeNull(); result.OrdType.Should().Be("Limit"); result.OrdStatus.Should().Be("New"); result.OrderId.Should().NotBeNull(); var paramCloseAfter = new OrderCancelAllAfterPOSTRequestParams { Timeout = 1000 }; // act Sut.Execute(BitmexApiUrls.Order.PostOrderCancelAllAfter, paramCloseAfter).Wait(); Thread.Sleep(1500); var resultCloseAfter = Sut.Execute(BitmexApiUrls.Order.GetOrder, new OrderGETRequestParams { Symbol = "XBTUSD" }).Result.Result; // assert resultCloseAfter.Should().NotBeNull(); resultCloseAfter.All(a => !string.IsNullOrWhiteSpace(a.OrderId)).Should().BeTrue(); }
private void DeleteAllOrders() { var @params = new OrderAllDELETERequestParams() { Symbol = "XBTUSD" }; Container.Resolve <IBitmexApiService>().Execute(BitmexApiUrls.Order.DeleteOrderAll, @params).Wait(); Container.Resolve <IBitmexApiService>().Execute(BitmexApiUrls.Order.PostOrder, OrderPOSTRequestParams.ClosePositionByMarket("XBTUSD")).Wait(); }
private async Task PrepareForMarketShift(MarketInfo marketInfo) { await _bitmexApiService.Execute(BitmexApiUrls.Order.DeleteOrderAll, new OrderAllDELETERequestParams { Symbol = marketInfo.Market }); await _bitmexApiService.Execute(BitmexApiUrls.Order.PostOrder, OrderPOSTRequestParams.ClosePositionByMarket(marketInfo.Market)); await SetLeverage(marketInfo.Market, marketInfo.Leverage); }
public void should_throw_bitmex_exception_with_deserialized_data_when_post() { // arrange var @params = OrderPOSTRequestParams.CreateSimpleMarket("SymbolWhichDoesNotExist", 3, OrderSide.Buy); // act Action action = () => { var result = Sut.Execute(BitmexApiUrls.Order.PostOrder, @params).Result.Result; }; // assert action.Should().Throw <BitmexApiException>().Which.Error?.Error.Should().NotBeNull(); }
public void should_receive_limit_order_notification() { try { // arrange var connected = Sut.Connect(); var @params = OrderPOSTRequestParams.CreateSimpleHidenLimit("XBTUSD", 3, _xbtAvgPrice - 500, OrderSide.Buy); // act IList <OrderDto> dtos = null; var dataReceived = new ManualResetEvent(false); Sut.OrderResponseReceived += (sender, args) => { if (args.Response.Data.Any(b => b.Symbol == "XBTUSD") && args.Response.Action == BitmexActions.Insert) { dtos = args.Response.Data; dataReceived.Set(); } }; var subscription = new SubscriptionRequest(SubscriptionType.order); Subscription = subscription; Sut.Subscribe(subscription); var result = _bitmexApiService.Execute(BitmexApiUrls.Order.PostOrder, @params).Result.Result; result.Should().NotBeNull(); //result.OrdType.Should().Be("Limit"); result.OrdStatus.Should().Be("New"); result.OrderId.Should().NotBeNull(); Thread.Sleep(2000); var received = dataReceived.WaitOne(TimeSpan.FromSeconds(20)); // assert // no exception raised connected.Should().BeTrue(); received.Should().BeTrue(); dtos.Should().NotBeNull(); dtos.Count().Should().BeGreaterThan(0); dtos[0].OrdType.Should().Be("Limit"); dtos[0].OrdStatus.Should().Be("New"); dtos[0].OrderId.Should().Be(result.OrderId); } catch (BitmexWebSocketLimitReachedException) { Assert.Fail("connection limit reached"); } }
public void should_place_sell_market_order() { // arrange var @params = OrderPOSTRequestParams.CreateSimpleMarket("XBTUSD", 3, OrderSide.Sell); // act var result = Sut.Execute(BitmexApiUrls.Order.PostOrder, @params).Result.Result; // assert result.Should().NotBeNull(); result.OrdStatus.Should().Be("Filled"); result.OrderId.Should().NotBeNull(); }
public void should_place_buy_limit_order() { // arrange var @params = OrderPOSTRequestParams.CreateSimpleHidenLimit("XBTUSD", 3, _xbtAvgPrice - LimitPriceSubtractor, OrderSide.Buy); // act var result = Sut.Execute(BitmexApiUrls.Order.PostOrder, @params).Result.Result; // assert result.Should().NotBeNull(); result.OrdType.Should().Be("Limit"); result.OrdStatus.Should().Be("New"); result.OrderId.Should().NotBeNull(); }
public void should_place_sell_market_stop_order() { // arrange var @params = OrderPOSTRequestParams.CreateMarketStopOrder("XBTUSD", 3, _xbtAvgPrice - LimitPriceSubtractor, OrderSide.Sell); // act var result = Sut.Execute(BitmexApiUrls.Order.PostOrder, @params).Result.Result; // assert result.Should().NotBeNull(); result.OrdType.Should().Be("Stop"); result.OrdStatus.Should().Be("New"); result.OrderId.Should().NotBeNull(); }
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); } }
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); }
public async Task <string> GoLong(MarketInfo marketInfo) { await _bitmexApiService.Execute(BitmexApiUrls.Order.PostOrder, OrderPOSTRequestParams.ClosePositionByMarket(marketInfo.Market)); await SetLeverage(marketInfo.Market, marketInfo.Leverage); var buyPrice = await GetCurrentPrice(marketInfo.Market); var orderDto = await _bitmexApiService.Execute(BitmexApiUrls.Order.PostOrder, OrderPOSTRequestParams.CreateSimpleLimit(marketInfo.Market, marketInfo.Quantity, buyPrice, OrderSide.Buy)); var stopPrice = Math.Round((decimal)orderDto.Price * 1.005M, 0); //await _bitmexApiService.Execute(BitmexApiUrls.Order.PostOrder, OrderPOSTRequestParams.CreateSimpleHidenLimit(marketInfo.Market, marketInfo.Quantity, buyPrice - 50, OrderSide.Buy)); await _bitmexApiService.Execute(BitmexApiUrls.Order.PostOrder, OrderPOSTRequestParams.CreateSimpleHidenLimit(marketInfo.Market, marketInfo.Quantity, stopPrice, OrderSide.Sell)); return($"Bought {orderDto.OrderQty} {marketInfo.Market} at {orderDto.Price}, stop order set to {stopPrice}"); }
public void should_close_long_market_position_by_limit() { // arrange var @params = OrderPOSTRequestParams.CreateSimpleMarket("XBTUSD", 3, OrderSide.Buy); var result = Sut.Execute(BitmexApiUrls.Order.PostOrder, @params).Result.Result; result.Should().NotBeNull(); result.OrdStatus.Should().Be("Filled"); result.OrderId.Should().NotBeNull(); // act var resultClosePostion = Sut.Execute(BitmexApiUrls.Order.PostOrder, OrderPOSTRequestParams.ClosePositionByLimit("XBTUSD", _xbtAvgPrice + LimitPriceSubtractor)).Result.Result; // assert resultClosePostion.Should().NotBeNull(); resultClosePostion.OrderId.Should().NotBeNull(); }
public void should_close_short_martket_position_by_market() { // arrange var @params = OrderPOSTRequestParams.CreateSimpleMarket("XBTUSD", 3, OrderSide.Sell); var result = Sut.Execute(BitmexApiUrls.Order.PostOrder, @params).Result.Result; result.Should().NotBeNull(); result.OrdStatus.Should().Be("Filled"); result.OrderId.Should().NotBeNull(); // act var resultClosePostion = Sut.Execute(BitmexApiUrls.Order.PostOrder, OrderPOSTRequestParams.ClosePositionByMarket("XBTUSD")).Result.Result; // assert resultClosePostion.Should().NotBeNull(); resultClosePostion.OrderId.Should().NotBeNull(); }
private async Task PrepareForMarketShift(TradeInfo tradeInfo) { try { await _bitmexApiService.Execute(BitmexApiUrls.Order.DeleteOrderAll, new OrderAllDELETERequestParams { Symbol = tradeInfo.Symbol }); await _bitmexApiService.Execute(BitmexApiUrls.Order.PostOrder, OrderPOSTRequestParams.ClosePositionByMarket(tradeInfo.Symbol)); await SetLeverage(tradeInfo.Symbol, tradeInfo.Leverage); } catch (Exception e) { Logger.Error(e.ToString()); } }
public void should_receive_market_buy_order_notification() { try { // arrange var connected = Sut.Connect(); var @params = OrderPOSTRequestParams.CreateSimpleMarket("XBTUSD", 3, OrderSide.Buy); // act IList <OrderDto> dtos = null; var dataReceived = new ManualResetEvent(false); var subscription = BitmexApiSubscriptionInfo <IEnumerable <OrderDto> > .Create(SubscriptionType.order, a => { if (a.Data.Any(b => b.Symbol == "XBTUSD") && a.Action == BitmexActions.Insert) { dtos = a.Data.ToList(); dataReceived.Set(); } }); Subscription = subscription; Sut.Subscribe(subscription); var result = _bitmexApiService.Execute(BitmexApiUrls.Order.PostOrder, @params).Result; result.Should().NotBeNull(); result.OrdType.Should().Be("Market"); result.OrdStatus.Should().Be("Filled"); result.OrderId.Should().NotBeNull(); var received = dataReceived.WaitOne(TimeSpan.FromSeconds(20)); // assert // no exception raised connected.Should().BeTrue(); received.Should().BeTrue(); dtos.Should().NotBeNull(); dtos.Count().Should().BeGreaterThan(0); dtos[0].OrderId.Should().Be(result.OrderId); } catch (BitmexWebSocketLimitReachedException) { Assert.Inconclusive("connection limit reached"); } }
public void should_receive_position_change_notification() { try { // arrange var connected = Sut.Connect(); var @params = OrderPOSTRequestParams.CreateSimpleMarket("XBTUSD", 3, OrderSide.Buy); IList <PositionDto> dtos = null; var dataReceived = new ManualResetEvent(false); Sut.PositionResponseReceived += (sender, args) => { dtos = args.Response.Data; dataReceived.Set(); }; var subscription = new SubscriptionRequest(SubscriptionType.position); Subscription = subscription; // act Sut.Subscribe(subscription); var result = _bitmexApiService.Execute(BitmexApiUrls.Order.PostOrder, @params).Result.Result; result.Should().NotBeNull(); result.OrdType.Should().Be("Market"); result.OrdStatus.Should().Be("Filled"); result.OrderId.Should().NotBeNull(); var received = dataReceived.WaitOne(TimeSpan.FromSeconds(20)); // assert // no exception raised connected.Should().BeTrue(); received.Should().BeTrue("data hasn't received"); dtos.Should().NotBeNull(); dtos.Count().Should().BeGreaterThan(0); } catch (BitmexWebSocketLimitReachedException) { Assert.Fail("connection limit reached"); } }
public void should_place_buy_market_orders_bulk() { // arrange var @params = new OrderBulkPOSTRequestParams { Orders = new[] { OrderPOSTRequestParams.CreateSimpleMarket("XBTUSD", 3, OrderSide.Buy), OrderPOSTRequestParams.CreateSimpleMarket("XBTUSD", 3, OrderSide.Buy) } }; // act var result = Sut.Execute(BitmexApiUrls.Order.PostOrderBulk, @params).Result; // assert result.Should().NotBeNull(); result.All(a => a.OrdStatus == "Filled").Should().BeTrue(); result.All(a => !string.IsNullOrWhiteSpace(a.OrderId)).Should().BeTrue(); }
public void should_place_sell_limit_orders_bulk() { // arrange var @params = new OrderBulkPOSTRequestParams { Orders = new[] { OrderPOSTRequestParams.CreateSimpleLimit("XBTUSD", 3, _xbtAvgPrice + LimitPriceSubtractor, OrderSide.Sell), OrderPOSTRequestParams.CreateSimpleLimit("XBTUSD", 3, _xbtAvgPrice + LimitPriceSubtractor, OrderSide.Sell) } }; // act var result = Sut.Execute(BitmexApiUrls.Order.PostOrderBulk, @params).Result.Result; // assert result.Should().NotBeNull(); result.All(a => a.OrdStatus == "New").Should().BeTrue(); result.All(a => !string.IsNullOrWhiteSpace(a.OrderId)).Should().BeTrue(); }
public void should_subscribe_on_executions() { try { // arrange var connected = Sut.Connect(); IEnumerable <ExecutionDto> dtos = null; var dataReceived = new ManualResetEvent(false); Sut.ExecutionResponseReceived += (sender, args) => { if (args.Response.Data.Any()) { dtos = args.Response.Data; dataReceived.Set(); } }; var subscription = new SubscriptionRequest(SubscriptionType.execution); Subscription = subscription; // act Sut.Subscribe(subscription); _bitmexApiService.Execute(BitmexApiUrls.Order.PostOrder, OrderPOSTRequestParams.CreateSimpleMarket("XBTUSD", 10, OrderSide.Buy)).Wait(); var received = dataReceived.WaitOne(TimeSpan.FromSeconds(30)); // assert // no exception raised connected.Should().BeTrue(); received.Should().BeTrue(); dtos.Should().NotBeNull(); dtos.Count().Should().BeGreaterThan(0); } catch (BitmexWebSocketLimitReachedException) { Assert.Fail("connection limit reached"); } }
public void should_close_long_market_position_by_market() { // arrange var @params = OrderPOSTRequestParams.CreateSimpleMarket("XBTUSD", 3, OrderSide.Buy); var result = Sut.Execute(BitmexApiUrls.Order.PostOrder, @params).Result; result.Should().NotBeNull(); result.OrdStatus.Should().Be("Filled"); result.OrderId.Should().NotBeNull(); // act var @paramsClosePosition = new OrderClosePositionPOSTRequestParams { Symbol = "XBTUSD" }; var resultClosePostion = Sut.Execute(BitmexApiUrls.Order.PostOrderClosePosition, @paramsClosePosition).Result; // assert resultClosePostion.Should().NotBeNull(); resultClosePostion.OrderId.Should().NotBeNull(); }
// Market Order private void btn3_Click(object sender, EventArgs e) { //Log.Debug("Testing Button clicked 123"); //var bitmexApiServiceA = BitmexApiService.CreateDefaultApi(new BitmexAuthorization //{ // BitmexEnvironment = BitmexEnvironment.Test, // Key = "vUVW4tbj-wZG5UQgRkqHL4_z", // Secret = "8HaCUEbx0qgJfQSo4EiX6RUGzDsjiY-uOsEsCBstIpYu-J7Q" //}); var bitmexApiServiceA = BitmexApiService_Test_POS_Outcome.CreateDefaultApi("111"); var OrderParamsA = OrderPOSTRequestParams.CreateSimpleLimit("XBTUSD", "1234HoedjeVanPapier-1234", 150, (decimal)10150.0, OrderSide.Buy); bitmexApiServiceA.Execute(BitmexApiUrls.Order.PostOrder, OrderParamsA).ContinueWith(HandleOrderResponse, TaskContinuationOptions.AttachedToParent); var OrderParams = new OrderDELETERequestParams() { ClOrdID = "bladieblakakkahahhaha" }; var result = bitmexApiServiceA.Execute(BitmexApiUrls.Order.DeleteOrder, OrderParams); MessageBox.Show(result.Result.Result[0].ToString()); }