public async Task Test_getposition_success()
        {
            // open position
            var buysellrequest = new BuySellRequest
            {
                instrument_name = DeribitInstruments.Perpetual.BTCPERPETUAL,
                type            = OrderType.market,
                amount          = 30,
            };
            var order = (await this.deribit.Trading.Buy(buysellrequest)).order;
            // wait
            await Task.Delay(1 << 9);

            // get position
            var position = await this.deribit.AccountManagement.GetPosition(new GetPositionRequest
            {
                instrument_name = DeribitInstruments.Perpetual.BTCPERPETUAL,
            });

            // assert
            new Position.Validator().ValidateAndThrow(position);
            Assert.That(position.size == order.amount);
            Assert.That(position.direction == order.direction);
            Assert.That(position.instrument_name == order.instrument_name);
            // wait
            await Task.Delay(1 << 9);

            // close position
            await this.deribit.Trading.ClosePosition(new ClosePositionRequest
            {
                instrument_name = DeribitInstruments.Perpetual.BTCPERPETUAL,
                type            = "market",
            });
        }
Exemple #2
0
        public async Task Test_buy_market_success()
        {
            // form request
            BuySellRequest req = new BuySellRequest()
            {
                instrument_name = DeribitInstruments.Perpetual.BTCPERPETUAL,
                amount          = 10,
                type            = OrderType.market,
                label           = "mylabel",
            };
            // execute
            BuySellResponse response = await this.deribit.Trading.Buy(req);

            // assert
            new BuySellResponse.Validator().ValidateAndThrow(response);
            Assert.That(response.order, Is.Not.Null);
            Assert.That(response.order.direction, Is.EqualTo(BuySell.Buy));
            Assert.That(response.order.label, Is.EqualTo(req.label));
            Assert.That(response.order.order_id, Is.Not.Null);
            Assert.That(response.trades.Count, Is.GreaterThan(0));
            // wait
            await Task.Delay(1 << 9);

            // cleanup
            var response2 = await this.deribit.Trading.ClosePosition(new ClosePositionRequest
            {
                instrument_name = DeribitInstruments.Perpetual.BTCPERPETUAL,
                type            = "market",
            });

            // assert
            new ClosePositionResponse.Validator().ValidateAndThrow(response2);
        }
Exemple #3
0
        public async Task Test_buy_limit_success()
        {
            // form request
            BuySellRequest req = new BuySellRequest()
            {
                instrument_name = DeribitInstruments.Perpetual.BTCPERPETUAL,
                amount          = 10,
                type            = OrderType.limit,
                label           = "mylabel",
                price           = 2000,
            };
            // execute
            BuySellResponse response = await this.deribit.Trading.Buy(req);

            // assert
            new BuySellResponse.Validator().ValidateAndThrow(response);
            Assert.That(response.order, Is.Not.Null);
            Assert.That(response.order.direction, Is.EqualTo(BuySell.Buy));
            Assert.That(response.order.label, Is.EqualTo(req.label));
            Assert.That(response.order.order_id, Is.Not.Null);
            // wait
            await Task.Delay(1 << 9);

            // cleanup
            var response2 = await this.deribit.Trading.CancelAll();

            // assert
            Assert.That(response2.cancelledcount, Is.GreaterThan(0));
        }
Exemple #4
0
        public async Task Test_cancelallbyinstrument()
        {
            //----------------------------------------------------------------------------
            // submit bid
            //----------------------------------------------------------------------------
            // form request
            BuySellRequest req = new BuySellRequest()
            {
                instrument_name = DeribitInstruments.Perpetual.BTCPERPETUAL,
                amount          = 30,
                type            = OrderType.limit,
                label           = "mylabel",
                price           = 930,
                post_only       = true,
            };
            // execute
            BuySellResponse response = await this.deribit.Trading.Buy(req);

            Assert.That(response.order, Is.Not.Null);
            //----------------------------------------------------------------------------
            // cancel all
            //----------------------------------------------------------------------------
            // wait
            await Task.Delay(1 << 9);

            // execute
            var response2 = await this.deribit.Trading.CancelAllByInstrument(new CancelAllByInstrumentRequest
            {
                instrument_name = DeribitInstruments.Perpetual.BTCPERPETUAL,
            });

            // assert
            Assert.That(response2.cancelledcount, Is.GreaterThan(0));
        }
        public async Task <Trades> SellByMarketPriceAsync(string units, string currency)
        {
            var request = new BuySellRequest
            {
                apiKey    = _apiKey,
                secretKey = _apiSecretKey,
                units     = units,
                currency  = currency,
            };

            return(await RestClient.Instance.PostAsync <BuySellRequest, Trades>(PrivateAPI.Deposit, request));
        }
Exemple #6
0
        public async Task Test_editorder()
        {
            //----------------------------------------------------------------------------
            // submit bid
            //----------------------------------------------------------------------------
            // form request
            BuySellRequest req = new BuySellRequest()
            {
                instrument_name = DeribitInstruments.Perpetual.BTCPERPETUAL,
                amount          = 10,
                type            = OrderType.limit,
                label           = "mylabel",
                price           = 1000,
                post_only       = true,
            };
            // execute
            BuySellResponse response = await this.deribit.Trading.Buy(req);

            Assert.That(response.order, Is.Not.Null);
            // wait
            await Task.Delay(1 << 9);

            //----------------------------------------------------------------------------
            // modify bid
            //----------------------------------------------------------------------------
            // form request
            EditOrderRequest req2 = new EditOrderRequest()
            {
                order_id = response.order.order_id,
                amount   = 20,
                price    = 500,
            };
            // execute request
            EditOrderResponse res2 = await this.deribit.Trading.EditOrder(req2);

            // assert
            var modifiedorder = res2.order;

            Assert.That(modifiedorder.order_id, Is.EqualTo(req2.order_id));
            Assert.That(modifiedorder.amount, Is.EqualTo(req2.amount));
            Assert.That(modifiedorder.price, Is.EqualTo(req2.price));
            //----------------------------------------------------------------------------
            // cleanup
            var response2 = await this.deribit.Trading.CancelAll();

            // assert
            Assert.That(response2.cancelledcount, Is.GreaterThan(0));
        }
Exemple #7
0
        public async Task Test_buy_stopmarket_success()
        {
            // form request
            BuySellRequest req = new BuySellRequest()
            {
                instrument_name = DeribitInstruments.Perpetual.BTCPERPETUAL,
                amount          = 10,
                type            = OrderType.stop_market,
                label           = "mylabel",
                stop_price      = 10000,
                trigger         = OrderTriggerType.index_price,
            };
            // execute
            BuySellResponse response = await this.deribit.Trading.Buy(req);

            // assert
            new BuySellResponse.Validator().ValidateAndThrow(response);
            Assert.That(response.order, Is.Not.Null);
            Assert.That(response.order.direction, Is.EqualTo(BuySell.Buy));
            Assert.That(response.order.label, Is.EqualTo(req.label));
            Assert.That(response.order.order_id, Is.Not.Null);
        }
Exemple #8
0
        public async Task Test_cancel()
        {
            //----------------------------------------------------------------------------
            // submit bid
            //----------------------------------------------------------------------------
            // form request
            BuySellRequest req = new BuySellRequest()
            {
                instrument_name = DeribitInstruments.Perpetual.BTCPERPETUAL,
                amount          = 30,
                type            = OrderType.limit,
                label           = "mylabel",
                price           = 1100,
                post_only       = true,
            };
            // execute
            BuySellResponse response = await this.deribit.Trading.Buy(req);

            Assert.That(response.order, Is.Not.Null);
            // wait
            await Task.Delay(1 << 9);

            //----------------------------------------------------------------------------
            // cancel bid
            //----------------------------------------------------------------------------
            // form request
            CancelRequest req2 = new CancelRequest()
            {
                order_id = response.order.order_id,
            };
            // execute request
            Order cancelledorder = await this.deribit.Trading.Cancel(req2);

            // assert
            Assert.That(cancelledorder.order_id, Is.EqualTo(response.order.order_id));
            Assert.That(cancelledorder.order_state, Is.EqualTo(OrderState.cancelled));
            //----------------------------------------------------------------------------
        }