Esempio n. 1
0
        public async Task can_place_buyorder()
        {
            SetupServerSingleResponse(Buy2);

            var create = new PlaceBuy
            {
                Amount        = 0.1m,
                Currency      = "BTC",
                PaymentMethod = "B28EB04F-BD70-4308-90A1-96065283A001"
            };
            var r = await client.Buys.PlaceBuyOrderAsync("fff", create);

            var truth = new Response <Buy>
            {
                Data = Buy2Model
            };

            truth.Should().BeEquivalentTo(r);

            server.ShouldHaveRequestBody(
                @"{""amount"":0.1,""currency"":""BTC"",""payment_method"":""B28EB04F-BD70-4308-90A1-96065283A001"",""agree_btc_amount_varies"":false,""commit"":false,""quote"":false}");

            server.ShouldHaveExactCall($"https://api.coinbase.com/v2/accounts/fff/buys")
            .WithVerb(HttpMethod.Post);
        }
Esempio n. 2
0
 /// <summary>
 /// Buys a user-defined amount of bitcoin, bitcoin cash, litecoin or ethereum.
 /// There are two ways to define buy amounts–you can use either the amount or the total parameter:
 /// 1. When supplying amount, you’ll get the amount of bitcoin, bitcoin cash, litecoin or ethereum defined.With amount it’s recommended to use BTC or ETH as the currency value, but you can always specify a fiat currency and and the amount will be converted to BTC or ETH respectively.
 /// 2. When supplying total, your payment method will be debited the total amount and you’ll get the amount in BTC or ETH after fees have been reduced from the total.With total it’s recommended to use the currency of the payment method as the currency parameter, but you can always specify a different currency and it will be converted.
 /// Given the price of digital currency depends on the time of the call and on the amount of purchase, it’s recommended to use the commit: false parameter to create an uncommitted buy to show the confirmation for the user or get the final quote, and commit that with a separate request.
 /// If you need to query the buy price without locking in the buy, you can use quote: true option.This returns an unsaved buy and unlike commit: false, this buy can’t be completed.This option is useful when you need to show the detailed buy price quote for the user when they are filling a form or similar situation.
 /// </summary>
 Task <Response <Buy> > IBuysEndpoint.PlaceBuyOrderAsync(string accountId, PlaceBuy placeBuy, CancellationToken cancellationToken)
 {
     return(this.AccountsEndpoint
            .AppendPathSegmentsRequire(accountId, "buys")
            .WithClient(this)
            .PostJsonAsync(placeBuy, cancellationToken)
            .ReceiveJson <Response <Buy> >());
 }
        public async Task buys
        (
            [Values(null, "", "  ")] string accountId)
        {
            var create = new PlaceBuy
            {
                Amount        = 0.1m,
                Currency      = "BTC",
                PaymentMethod = "B28EB04F-BD70-4308-90A1-96065283A001"
            };

            Func <Task <Response <Buy> > > a = async() => await client.Buys.PlaceBuyOrderAsync(accountId, create);

            a.Should().Throw <ArgumentException>();
        }