public override void UpdateBalances() { BtceRequest accountInfoRequest = new BtceRequest("", _apiInfo); accountInfoRequest.AddParameter("method", AccountBalanceInfoPath); accountInfoRequest.AddSignatureHeader(); //Make the api call Dictionary <string, dynamic> response = ApiPost(accountInfoRequest); //Pull the fiat and bitcoin amounts from the response response = (Dictionary <string, dynamic>)GetValueFromResponse(response, "return"); response = (Dictionary <string, dynamic>)GetValueFromResponse(response, "funds"); //Get the BTC value from the response, convert it to a decimal and sign it to this exchange. AvailableBtc = GetNumberFromResponse(response, "btc"); switch (FiatTypeToUse) { case FiatType.Eur: AvailableFiat = GetNumberFromResponse(response, EUR_SYMBOL); break; case FiatType.Usd: AvailableFiat = GetNumberFromResponse(response, USD_SYMBOL); break; } //TODO: Implement total balances for BTCe. For now, just make them the same as available TotalBtc = AvailableBtc; TotalFiat = AvailableFiat; }
/// <summary> /// With Btce, buying and selling is the same Api call. So both SellInternal and BuyInternal point to this. /// </summary> /// <param name="amount">Amount of btc to be bought/sold.</param> /// <param name="price">Price to set for the order.</param> /// <param name="orderType">Can be either be "buy" or "sell".</param> /// <returns>String representation of the executed order.</returns> private string ExecuteOrder(decimal amount, decimal price, OrderType orderType) { string orderTypeString = ""; switch (orderType) { case OrderType.Bid: orderTypeString = "buy"; break; case OrderType.Ask: orderTypeString = "sell"; break; } BtceRequest buyRequest = new BtceRequest("", _apiInfo); buyRequest.AddParameter("method", "Trade"); buyRequest.AddParameter("type", orderTypeString); buyRequest.AddParameter("pair", _btcFiatPairSymbol); buyRequest.AddParameter("rate", price); buyRequest.AddParameter("amount", amount); buyRequest.AddSignatureHeader(); //Make the api call Dictionary <string, dynamic> response = ApiPost(buyRequest); //Get order id from the response response = (Dictionary <string, dynamic>)GetValueFromResponse(response, "return"); return(Convert.ToString(GetNumberFromResponse(response, "order_id"), CultureInfo.InvariantCulture)); }
public override void DeleteOrder(string orderId) { //Build the request BtceRequest deleteOrderRequest = new BtceRequest("", _apiInfo); deleteOrderRequest.AddParameter("method", DeleteOrderPath); deleteOrderRequest.AddParameter("order_id", orderId); deleteOrderRequest.AddSignatureHeader(); //If the order is not valid, this will throw an error ApiPost(deleteOrderRequest); }
public Dictionary <string, dynamic> GetTradeList() { //Build the request BtceRequest tradeListRequest = new BtceRequest("", _apiInfo); tradeListRequest.AddParameter("method", _tradeListPath); tradeListRequest.AddSignatureHeader(); //Post the request to ANX Dictionary <string, dynamic> response = ApiPost(tradeListRequest); response = (Dictionary <string, dynamic>)GetValueFromResponseResult(response, "return"); return(response); }
public override void UpdateOrderBook(int?maxSize = null) { BtceRequest orderBookRequest = new BtceRequest(OrderBookPath); Dictionary <string, dynamic> response = ApiPost(orderBookRequest, "https://wex.nz/api/3/depth/btc_usd"); //TODO: Handle this more gracefully. Put this in here for now to get new BTCe API working if (response != null) { response = response["btc_usd"]; BuildOrderBook(response, 1, 0, maxSize); } else { throw new Exception("Something went wrong. The world is probably ending. Do something about it I guess?"); } }
public override List <Dictionary <string, dynamic> > GetAllOpenOrders() { List <Dictionary <string, dynamic> > returnList = new List <Dictionary <string, dynamic> >(); //Build the request BtceRequest orderInfoRequest = new BtceRequest("", _apiInfo); orderInfoRequest.AddParameter("method", OpenOrderPath); orderInfoRequest.AddSignatureHeader(); try { Dictionary <string, dynamic> response = ApiPost(orderInfoRequest); response = (Dictionary <string, dynamic>)GetValueFromResponseResult(response, "return"); //Loop through all the orders, add the id as one of the properties and build the return list foreach (var order in response) { order.Value["order-id"] = order.Key; returnList.Add(order.Value); } if (returnList.Count <= 0) { return(null); } return(returnList); } catch (Exception e) { //The ApiPost will throw an error if there aren't any open orders. Check for that condition; for anything else, throw the error if (!e.Message.Contains("no orders")) { throw; } return(null); } }
private Dictionary <string, dynamic> GetOpenOrderInformation(string orderId) { //Build the request BtceRequest orderInfoRequest = new BtceRequest("", _apiInfo); orderInfoRequest.AddParameter("method", OpenOrderPath); orderInfoRequest.AddSignatureHeader(); Dictionary <string, dynamic> response = ApiPost(orderInfoRequest); response = (Dictionary <string, dynamic>)GetValueFromResponseResult(response, "return"); //Post the request to ANX try { return((Dictionary <string, dynamic>)GetValueFromResponseResult(response, orderId)); } catch (Exception) { //Order was not found; return null return(null); } }
private Dictionary <string, dynamic> GetClosedOrderInformation(string orderId) { //Build the request BtceRequest orderInfoRequest = new BtceRequest("", _apiInfo); orderInfoRequest.AddParameter("method", _closedOrderQueryPath); orderInfoRequest.AddSignatureHeader(); Dictionary <string, dynamic> response = ApiPost(orderInfoRequest); response = (Dictionary <string, dynamic>)GetValueFromResponseResult(response, "return"); //Loop through all the orders, looking for one that matches the given id foreach (KeyValuePair <string, dynamic> orderInfo in response) { if (GetValueFromResponseResult(orderInfo.Value, "order_id").ToString() == orderId) { return(orderInfo.Value); } } //Order was not found, return null return(null); }