public override void UpdateBalances() { CoinbaseRequest balanceInfoRequest = new CoinbaseRequest(AccountBalanceInfoPath, _apiInfo); balanceInfoRequest.AddSignatureHeader(); Dictionary <string, dynamic>[] response = ApiPost_Array(balanceInfoRequest); foreach (Dictionary <string, dynamic> currencyInfoDictionary in response) { if (String.Equals((string)GetValueFromResponseResult(currencyInfoDictionary, "currency"), "USD", StringComparison.InvariantCultureIgnoreCase)) { TotalFiat = TypeConversion.ParseStringToDecimalStrict((string)GetValueFromResponseResult(currencyInfoDictionary, "balance")); AvailableFiat = TypeConversion.ParseStringToDecimalStrict((string)GetValueFromResponseResult(currencyInfoDictionary, "available")); } else if (String.Equals((string)GetValueFromResponseResult(currencyInfoDictionary, "currency"), "BTC", StringComparison.InvariantCultureIgnoreCase)) { TotalBtc = TypeConversion.ParseStringToDecimalStrict((string)GetValueFromResponseResult(currencyInfoDictionary, "balance")); AvailableBtc = TypeConversion.ParseStringToDecimalStrict((string)GetValueFromResponseResult(currencyInfoDictionary, "available")); } } //Round everything to 8 decimal places. TotalFiat = Math.Round(TotalFiat, 8); AvailableFiat = Math.Round(AvailableFiat, 8); TotalBtc = Math.Round(TotalBtc, 8); AvailableBtc = Math.Round(AvailableBtc, 8); }
public override void DeleteOrder(string orderId) { string deleteOrderPathWithId = DeleteOrderPath + "/" + orderId; CoinbaseRequest deleteOrderRequest = new CoinbaseRequest(deleteOrderPathWithId, _apiInfo, Method.DELETE); deleteOrderRequest.AddSignatureHeader(); string response = SimplePost(deleteOrderRequest); //If the response was not 'ok', try to derserialize it and get the error message if (!String.Equals(response, "OK", StringComparison.InvariantCultureIgnoreCase)) { Dictionary <string, dynamic> returnedContent = null; try { returnedContent = new JavaScriptSerializer().Deserialize <Dictionary <string, dynamic> >(response); } catch { //No need to do anything here; just swallow the derserialzing exception. The null check below gives the proper error message. } if (returnedContent == null) { throw new Exception("Response from " + Name + " was null. Here is the raw response string: " + Environment.NewLine + response); } CheckResponseForErrors(returnedContent); } }
public override List <Dictionary <string, dynamic> > GetAllOpenOrders() { CoinbaseRequest openOrderRequest = new CoinbaseRequest(OpenOrderPath, _apiInfo); openOrderRequest.AddSignatureHeader(); Dictionary <string, dynamic>[] response = ApiPost_Array(openOrderRequest); return(response.ToList()); }
public override Dictionary <string, dynamic> GetOrderInformation(string orderId) { string orderPathWithId = OpenOrderPath + "/" + orderId; CoinbaseRequest orderRequest = new CoinbaseRequest(orderPathWithId, _apiInfo); orderRequest.AddSignatureHeader(); Dictionary <string, dynamic> response = ApiPost(orderRequest); return(response); }
public override void UpdateOrderBook(int?maxSize = null) { CoinbaseRequest orderBookRequest = new CoinbaseRequest(OrderBookPath); orderBookRequest.AddQueryParameter("level", "2"); Dictionary <string, dynamic> response = ApiPost(orderBookRequest); if (!response.ContainsKey("bids") || !response.ContainsKey("asks")) { throw new Exception("Could not update order book for " + Name + ", 'asks' or 'bids' object was not in the response."); } BuildOrderBook(response, 1, 0, maxSize); }
private string ExecuteOrder(decimal amount, decimal price, OrderType orderType) { AddOrderJsonBody requestBody = new AddOrderJsonBody() { product_id = _btcFiatPairSymbol, side = orderType.ToString().ToLower(), price = price.ToString(), size = amount.ToString(), type = "limit" }; CoinbaseRequest orderRequest = new CoinbaseRequest(_addOrderPath, _apiInfo, requestBody, Method.POST); orderRequest.AddSignatureHeader(); Dictionary <string, dynamic> orderResponse = ApiPost(orderRequest); return((string)GetValueFromResponseResult(orderResponse, "id")); }