public void can_list_orders() { var api = new CoinbaseApi(ApiKey, ApiSecretKey, useSandbox: true, proxy: proxy, useTimeApi: true); var response = api.SendRequest("orders", null, Method.GET); response.Dump(); }
protected override string generate(string itemName, Money amount, string command, object[] args) { CoinbaseApi api = new CoinbaseApi(AppSettings.Cryptocurrencies.CoinbaseAPIKey, AppSettings.Cryptocurrencies.CoinbaseAPISecret, false); string description = String.Join(ArgsDelimeter + "", args); string AmountString = amount.ToClearString(); string CurrencyCode = AppSettings.Site.CurrencyCode; if (amount is CryptocurrencyMoney) { //We have direct BTC -> BTC Wallet transfer AmountString = ((CryptocurrencyMoney)amount).ToClearString(); CurrencyCode = ((CryptocurrencyMoney)amount).cryptocurrencyType.ToString(); } var options = new { amount = AmountString, currency = CurrencyCode, name = itemName, description = command, customer_defined_amount = false, success_url = SUCCESS_URL, cancel_url = FAILURE_URL, //notifications_url = AppSettings.Site.Url + "Handlers/Bitcoins/Coinbase.ashx", collect_email = false, collect_country = false, metadata = new { all = description } }; string data = string.Empty; try { var request = api.SendRequest(String.Format("/checkouts"), options, RestSharp.Method.POST); if (request.Errors != null) { ErrorLogger.Log(request.Errors[0].Message); return(String.Empty); } data = request.Data["embed_code"].ToString(); } catch (Exception ex) { ErrorLogger.Log(ex); } return(data); }
public override void TryWithDrawCryptocurrencyFromWallet(decimal amountInCryptocurrency, string userAddress, CryptocurrencyType cryptocurrencyType) { CoinbaseApi api = new CoinbaseApi(AppSettings.Cryptocurrencies.CoinbaseAPIKey, AppSettings.Cryptocurrencies.CoinbaseAPISecret, false); var options = new { type = "send", to = userAddress, amount = amountInCryptocurrency, currency = cryptocurrencyType.ToString() }; var response = api.SendRequest(String.Format("/accounts/{0}/transactions", GetAccountId(api)), options, RestSharp.Method.POST); if (response.Errors != null) { throw new MsgException(response.Errors[0].Message); } }
public void refund_example() { var api = new CoinbaseApi(ApiKey, ApiSecretKey, useSandbox: true, proxy: proxy, useTimeApi: true); var options = new { currency = "BTC" }; var orderId = "ORDER_ID_HERE"; var response = api.SendRequest($"/orders/{orderId}/refund", options); //process response as needed }
public override Money GetAccountBalance() { try { CoinbaseApi api = new CoinbaseApi(AppSettings.Cryptocurrencies.CoinbaseAPIKey, AppSettings.Cryptocurrencies.CoinbaseAPISecret, false); var accounts = api.SendRequest("/accounts", null, RestSharp.Method.GET); var account = accounts.Data.First(acc => acc["currency"].ToString() == "BTC"); var balance = account["balance"]; var amount = balance["amount"].ToString(); return(new Money(Convert.ToDecimal(amount))); } catch (Exception ex) { return(Money.Zero); } }
public override string CreateNewAddress(int userId) { CoinbaseApi api = new CoinbaseApi(AppSettings.Cryptocurrencies.CoinbaseAPIKey, AppSettings.Cryptocurrencies.CoinbaseAPISecret, false); var options = new { name = DateTime.Now.ToString() }; string adminAddress = string.Empty; try { var request = api.SendRequest(String.Format("/accounts/{0}/addresses", GetAccountId(api)), options, RestSharp.Method.POST); if (request.Errors != null) { ErrorLogger.Log(request.Errors[0].Message, LogType.Coinbase); return(adminAddress); } adminAddress = request.Data["address"].ToString(); if (!string.IsNullOrWhiteSpace(adminAddress)) { string query = string.Format("SELECT * FROM BitcoinAddresses WHERE UserId = {0}", userId); BitcoinAddress address = TableHelper.GetListFromRawQuery <BitcoinAddress>(query).FirstOrDefault(); if (address == null) { address = new BitcoinAddress(); address.UserId = userId; } address.CoinbaseAddress = adminAddress; address.Save(); } } catch (Exception ex) { ErrorLogger.Log(ex); } return(adminAddress); }
public static string GetAccountId(CoinbaseApi api) { var accounts = api.SendRequest("/accounts", null, RestSharp.Method.GET); if (accounts.Errors != null) { throw new MsgException(accounts.Errors[0].Message); } return(accounts.Data.First(account => account["currency"].ToString() == "BTC")["id"].ToString()); }