Пример #1
0
 public static CoinbaseResponse CancelRequest(string request, APIKey apiKey)
 {
     return (CoinbaseResponse)DeleteResource(
         "transactions",
         request,
         "cancel_request",
         typeof(CoinbaseResponse),
         apiKey
         );
 }
Пример #2
0
 public static CoinbaseResponse CompleteRequest(string request, APIKey apiKey)
 {
     return (CoinbaseResponse)PutResource(
         "transactions",
         request,
         "complete_request",
         typeof(CoinbaseResponse),
         apiKey
         );
 }
Пример #3
0
        public static Transfer BuyBitcoins(Quantity quantity, APIKey apiKey)
        {
            TransferResponse transferResponse = (TransferResponse)PostResource(
                "buys",
                quantity,
                typeof(Quantity),
                typeof(TransferResponse),
                apiKey
                );

            return transferResponse.Transfer;
        }
Пример #4
0
 public static User GetUser(APIKey apiKey)
 {
     Users users = (Users)GetResource(
         "users",
         typeof(Users),
         apiKey
         );
     return users.CurrentUser;
 }
Пример #5
0
 public static Amount GetBalance(APIKey apiKey)
 {
     return (Amount) GetResource(
         "account",
         "balance",
         typeof(Amount),
         apiKey
         );
 }
Пример #6
0
        public static void TestConductTransactions(
            APIKey key1,
            APIKey key2
            )
        {
            Console.Write("Testing SendMoney w/ Valid Key: ");
            ReceiveAddress addr1 = API.GetReceiveAddress(key1);
            ReceiveAddress addr2 = API.GetReceiveAddress(key2);

            SendMoneyTransaction sendMoney = new SendMoneyTransaction()
            {
                ToAddr = addr1.Address,
                Amount = new Amount() { AmountValue = 0.01m, Currency = "BTC" },
                Notes = "Testing send_money"
            };
            Transaction sendMoneyTransaction = API.SendMoney(
                sendMoney,
                key2
                );
            ASSERT(sendMoneyTransaction.IsValid, sendMoneyTransaction);

            if (!sendMoneyTransaction.IsValid)
            {
                return;
            }

            User user1 = API.GetUser(key1);
            if (!user1.IsValid)
            {
                return;
            }

            Console.Write("Testing RequestMoney w/ Valid Key: ");
            RequestMoneyTransaction requestMoney = new RequestMoneyTransaction()
            {
                FromAddr = user1.Email,
                Amount = new Amount() { AmountValue = 0.01m, Currency = "BTC" },
                Notes = "Testing request_money"
            };
            Transaction requestMoneyTransaction = API.RequestMoney(
                requestMoney,
                key2
                );
            ASSERT(requestMoneyTransaction.IsValid, requestMoneyTransaction);

            if (!requestMoneyTransaction.IsValid)
            {
                return;
            }

            Console.Write("Testing CancelRequest w/ Valid Key: ");
            CoinbaseResponse response = API.CancelRequest(requestMoneyTransaction.ID, key1);
            ASSERT(response.IsValid, response);

            requestMoneyTransaction = API.RequestMoney(
                requestMoney,
                key2
                );
            if (!requestMoneyTransaction.IsValid)
            {
                return;
            }

            response = API.ResendRequest(requestMoneyTransaction.ID, key2);
            Console.Write("Testing ResendRequest w/ Valid Key: ");
            ASSERT(response.IsValid, response);

            Console.Write("Testing CompleteRequest w/ Valid Key: ");
            response = API.CompleteRequest(requestMoneyTransaction.ID, key1);
            ASSERT(response.IsValid, response);
        }
Пример #7
0
 public static ReceiveAddress GenerateReceiveAddress(APIKey apiKey)
 {
     return (ReceiveAddress)PostResource(
         "account",
         "generate_receive_address",
         typeof(ReceiveAddress),
         apiKey
         );
 }
Пример #8
0
 public static Contacts GetContacts(int page, int limit, APIKey apiKey)
 {
     var dict = new Dictionary<string, string>();
     dict["page"] = page.ToString();
     dict["limit"] = Math.Min(limit, 1000).ToString();
     return (Contacts) GetResource(
         "contacts",
         null,
         dict,
         typeof(Contacts),
         apiKey
         );
 }
Пример #9
0
        private static void CheckBalanceStatus()
        {
            APIKey key1 = new APIKey(
                RoleEnvironment.GetConfigurationSettingValue("CoinbaseAccountKey1")
                );
            APIKey key2 = new APIKey(
                RoleEnvironment.GetConfigurationSettingValue("CoinbaseAccountKey2")
                );

            User user1 = API.GetUser(key1);
            if (!user1.IsValid)
            {
                Trace.TraceError(
                    "Unable to get information for {0}: {1}",
                    key1,
                    user1
                    );
                return;
            }
            User user2 = API.GetUser(key2);
            if (!user2.IsValid)
            {
                Trace.TraceError(
                    "Unable to get information for {0}: {1}",
                    key2,
                    user2
                    );
                return;
            }

            if (user1.Balance.Currency != "BTC")
            {
                user1.Balance = API.GetBalance(key1);
                if (!user1.Balance.IsValid)
                {
                    Trace.TraceError(
                        "Unable to convert user1's balance to BTC: {0}",
                        user1.Balance
                        );
                    return;
                }
            }

            if (user2.Balance.Currency != "BTC")
            {
                user2.Balance = API.GetBalance(key2);
                if (!user2.Balance.IsValid)
                {
                    Trace.TraceError(
                        "Unable to convert user2's balance to BTC: {0}",
                        user2.Balance
                        );
                    return;
                }
            }

            if (user1.Balance.AmountValue + user2.Balance.AmountValue < MINIMUM_TOTAL_BALANCE_AMOUNT.AmountValue)
            {
                SendEmail(user1);
                SendEmail(user2);
            }
        }
Пример #10
0
 public static object GetResource(
     string controller,
     string action,
     IDictionary<string, string> parameters,
     Type type,
     APIKey apiKey
     )
 {
     HttpWebRequest request = CreateRequest(
         controller,
         action,
         parameters,
         apiKey
         );
     try
     {
         return request.DownloadResponse(type);
     }
     catch (WebException ex)
     {
         var constructor = type.GetConstructor(
             new Type[] { typeof(WebException) }
             );
         return constructor.Invoke(new object[] { ex });
     }
 }
Пример #11
0
        public static object PutResource(
            string controller,
            string subcontroller,
            string action,
            IDictionary<string, string> parameters,
            object postObj,
            Type typeOfPostObj,
            Type responseType,
            APIKey apiKey
            )
        {
            HttpWebRequest request = CreateRequest(
                controller,
                subcontroller,
                action,
                parameters,
                apiKey
                );
            request.Method = "PUT";
            request.ContentType = "application/json";

            try
            {
                request.UploadData(postObj, typeOfPostObj);
                return request.DownloadResponse(responseType);
            }
            catch (WebException ex)
            {
                var constructor = responseType.GetConstructor(
                    new Type[] { typeof(WebException) }
                    );
                return constructor.Invoke(new object[] { ex });
            }
        }
Пример #12
0
 public static ReceiveAddress GetReceiveAddress(APIKey apiKey)
 {
     return (ReceiveAddress) GetResource(
         "account",
         "receive_address",
         typeof(ReceiveAddress),
         apiKey
         );
 }
Пример #13
0
 public static object GetResource(
     string controller,
     string action,
     Type type,
     APIKey apiKey
     )
 {
     return GetResource(controller, action, null, type, apiKey);
 }
Пример #14
0
 public static Orders GetOrders(APIKey apiKey)
 {
     return (Orders) GetResource("orders", typeof(Orders), apiKey);
 }
Пример #15
0
        public static Order GetOrder(string order, APIKey apiKey)
        {
            OrderResponse orderResponse = (OrderResponse) GetResource(
                "orders",
                order,
                typeof(OrderResponse),
                apiKey
                );

            return orderResponse.Order;
        }
Пример #16
0
 public static Contacts GetContacts(
     int page, 
     string query, 
     APIKey apiKey
     )
 {
     var dict = new Dictionary<string, string>();
     dict["page"] = page.ToString();
     dict["query"] = query;
     return (Contacts)GetResource(
         "contacts",
         null,
         dict,
         typeof(Contacts),
         apiKey
         );
 }
Пример #17
0
 public static object PutResource(
     string controller,
     string subcontroller,
     string action,
     Type responseType,
     APIKey apiKey
     )
 {
     return PutResource(controller, subcontroller, action, null, null, null, responseType, apiKey);
 }
Пример #18
0
 public static Transfer SellBitcoins(decimal qty, APIKey apiKey)
 {
     Quantity quantity = new Quantity() { Value = qty };
     return SellBitcoins(quantity, apiKey);
 }
Пример #19
0
 public static object PutResource(
     string controller,
     string subcontroller,
     object postObj,
     Type typeOfPostObj,
     Type responseType,
     APIKey apiKey
     )
 {
     return PutResource(
         controller,
         subcontroller,
         null,
         null,
         postObj,
         typeOfPostObj,
         responseType,
         apiKey
         );
 }
Пример #20
0
        public static User UpdateUser(
            User user,
            APIKey apiKey
            )
        {
            User updatedUser = new User()
            {
                Email = user.Email,
                Name = user.Name,
                NativeCurrency = user.NativeCurrency,
                TimeZone = user.TimeZone
            };

            UserResponse userResponse = (UserResponse)PutResource(
                "users",
                user.ID,
                updatedUser,
                typeof(User),
                typeof(UserResponse),
                apiKey
                );

            return userResponse.User;
        }
Пример #21
0
        public static Transaction GetTransaction(string transaction, APIKey apiKey)
        {
            TransactionResponse transactionResponse = (TransactionResponse) GetResource(
                "transactions",
                transaction,
                typeof(TransactionResponse),
                apiKey
                );

            return transactionResponse.Transaction;
        }
Пример #22
0
 public static Contacts GetContacts(APIKey apiKey)
 {
     return (Contacts) GetResource("contacts", typeof(Contacts), apiKey);
 }
Пример #23
0
        public static Transaction SendMoney(SendMoneyTransaction transaction, APIKey apiKey)
        {
            SendMoneyTransactionRequest request = new SendMoneyTransactionRequest()
            {
                Transaction = transaction
            };
            TransactionResponse transactionResponse = (TransactionResponse) PostResource(
                "transactions",
                "send_money",
                request,
                typeof(SendMoneyTransactionRequest),
                typeof(TransactionResponse),
                apiKey
                );

            return transactionResponse.Transaction;
        }
Пример #24
0
 public static Transactions GetTransactions(APIKey apiKey)
 {
     return (Transactions) GetResource(
         "transactions",
         typeof(Transactions),
         apiKey
         );
 }
Пример #25
0
        public static Button CreatePaymentButton(
            string name,
            Amount cost,
            string description,
            APIKey apiKey
            )
        {
            Button button = new Button()
            {
                Name = name,
                Cost = cost.AmountValue,
                PriceCurrencyISO = cost.Currency,
                Description = description
            };

            return CreatePaymentButton(button, apiKey);
        }
Пример #26
0
 public static Transfers GetTransfers(APIKey apiKey)
 {
     return (Transfers)GetResource(
         "transfers",
         typeof(Transfers),
         apiKey
         );
 }
Пример #27
0
        private bool PopulateBitcoinInformation(Proof proof)
        {
            APIKey apiKey = new APIKey(RoleEnvironment.GetConfigurationSettingValue(
                "CoinbaseAccountKey1"
                ));

            Transaction coinbaseTransaction = API.GetTransaction(proof.CoinbaseTransactionID, apiKey);

            if (coinbaseTransaction.Hash != null)
            {
                proof.BitcoinTransactionHash = coinbaseTransaction.Hash;
                BitcoinTransaction bitcoinTransaction =
                    BlockchainAPI.GetTransaction(coinbaseTransaction.Hash);
                if (bitcoinTransaction.BlockHeight > 0)
                {
                    proof.BitcoinBlockNumber = bitcoinTransaction.BlockHeight;
                    return true;
                }
            }

            return false;
        }
Пример #28
0
        public static Transfers GetTransfers(int page, APIKey apiKey)
        {
            var dict = new Dictionary<string, string>();
            dict["page"] = page.ToString();

            return (Transfers)GetResource(
                "transfers",
                null,
                dict,
                typeof(Transfers),
                apiKey
                );
        }
Пример #29
0
        private Transaction SnapshotCommitmentIntoBitcoin(string commitment)
        {
            APIKey key1 = new APIKey(
                RoleEnvironment.GetConfigurationSettingValue("CoinbaseAccountKey1")
                );
            APIKey key2 = new APIKey(
                RoleEnvironment.GetConfigurationSettingValue("CoinbaseAccountKey2")
                );

            Amount balance1 = API.GetBalance(key1);

            if (!balance1.IsValid)
            {
                Trace.TraceError(
                    "Unable to get balance for {0}: {1}",
                    key1,
                    balance1
                    );
                return null;
            }

            Amount balance2 = API.GetBalance(key2);
            if (!balance2.IsValid)
            {
                Trace.TraceError(
                    "Unable to get balance for {0}: {1}",
                    key2,
                    balance2
                    );
                return null;
            }

            if (balance1.AmountValue < balance2.AmountValue)
            {
                APIKey tempKey = key1;
                Amount tempBalance = balance1;
                key1 = key2;
                balance1 = balance2;
                key2 = tempKey;
                balance2 = tempBalance;
            }

            if (balance1.AmountValue < API.MINIMUM_PAYMENT_AMOUNT)
            {
                Trace.TraceError(
                    "Insufficient Funds ({0}) to send miniumum payment of {1} BTC",
                    balance1,
                    API.MINIMUM_PAYMENT_AMOUNT
                    );
                return null;
            }

            User user2 = API.GetUser(key2);
            if (!user2.IsValid)
            {
                Trace.TraceError(
                    "Unable to get User Information for {0}: {1}",
                    key2,
                    user2
                    );
                return null;
            }

            SendMoneyTransaction sendMoney = new SendMoneyTransaction()
            {
                Amount = new Amount() { AmountValue = API.MINIMUM_PAYMENT_AMOUNT, Currency = "BTC" },
                ToAddr = user2.Email,
                Notes = commitment
            };

            Transaction transaction = API.SendMoney(sendMoney, key1);

            if (!transaction.IsValid)
            {
                Trace.TraceError(
                    "Unable to complete SendMoney Transaction: {0}",
                    transaction
                    );
                return null;
            }

            return transaction;
        }
Пример #30
0
        public static HttpWebRequest CreateRequest(
            string controller,
            string subcontroller,
            string action,
            IDictionary<string, string> parameters,
            APIKey apiKey
            )
        {
            var builder = new UriBuilder(CoinbaseURL);

            if (!string.IsNullOrWhiteSpace(controller))
            {
                if (!string.IsNullOrWhiteSpace(subcontroller))
                {
                    builder.Path += (string.IsNullOrWhiteSpace(action))
                        ? string.Format("{0}/{1}", controller, subcontroller)
                        : string.Format("{0}/{1}/{2}", controller, subcontroller, action);
                }
                else
                {
                    builder.Path += controller;
                }
            }

            var queryParams = HttpUtility.ParseQueryString(string.Empty);
            if (apiKey != null)
            {
                queryParams["api_key"] = apiKey.KeyValue;
            }

            if (parameters != null)
            {
                foreach (string key in parameters.Keys)
                {
                    queryParams[key] = parameters[key];
                }
            }

            builder.Query = queryParams.ToString();

            return WebRequest.CreateHttp(builder.Uri);
        }