public override void UpdateBalances() { ItBitRequest request = new ItBitRequest(BaseUrl, AccountBalanceInfoPath, _apiInfo.Key, _apiInfo.Secret); request.AddParameter("userId", _apiInfo.UserId); request.AddSignatureHeader(); Dictionary <string, dynamic> response = ApiPost(request); ArrayList balancesArrayList = (ArrayList)GetValueFromResponseResult(response, "balances"); //Get EUR from response Dictionary <string, object> fiatWallet = null; switch (FiatTypeToUse) { case FiatType.Eur: fiatWallet = GetDictionaryFromArrayList(balancesArrayList, "currency", "EUR"); break; case FiatType.Usd: fiatWallet = GetDictionaryFromArrayList(balancesArrayList, "currency", "USD"); break; } AvailableFiat = TypeConversion.ParseStringToDecimalLoose((string)GetValueFromResponseResult(fiatWallet, "availableBalance")); TotalFiat = TypeConversion.ParseStringToDecimalLoose((string)GetValueFromResponseResult(fiatWallet, "totalBalance")); //Get BTC from response Dictionary <string, object> btcWallet = GetDictionaryFromArrayList(balancesArrayList, "currency", "XBT"); AvailableBtc = TypeConversion.ParseStringToDecimalLoose((string)GetValueFromResponseResult(btcWallet, "availableBalance")); TotalBtc = TypeConversion.ParseStringToDecimalLoose((string)GetValueFromResponseResult(btcWallet, "totalBalance")); }
public override void UpdateOrderBook(int?maxSize = null) { ItBitRequest orderBookRequest = new ItBitRequest(OrderBookPath); Dictionary <string, dynamic> response = ApiPost(orderBookRequest); BuildOrderBook(response, 1, 0, maxSize); }
/// <summary> /// With ItBit, 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) { //Need to round amount to 4 decimal places, as that is all ItBit accepts amount = Math.Round(amount, 4); AddOrderJsonBody requestBody = BuildAddOrderJsonBody(orderType, price, amount); ItBitRequest request = new ItBitRequest(BaseUrl, _addOrderPath, _apiInfo.Key, _apiInfo.Secret, requestBody); request.AddSignatureHeader(); Dictionary <string, dynamic> response = ApiPost(request); //Pull the order Id from the response and return it return((string)GetValueFromResponseResult(response, "id")); }
protected override string TransferInternal(decimal amount, string address) { TransferJsonBody requestBody = new TransferJsonBody { currency = "XBT", amount = amount.ToString(CultureInfo.InvariantCulture), address = address }; ItBitRequest transferRequest = new ItBitRequest(BaseUrl, _transferPath, _apiInfo.Key, _apiInfo.Secret, requestBody); transferRequest.AddSignatureHeader(); Dictionary <string, dynamic> response = ApiPost(transferRequest); //Pull the transfer Id from the response and return it //Note, this is an int in the object, thus the toString return(GetValueFromResponseResult(response, "withdrawalId").ToString()); }
public override void DeleteOrder(string orderId) { //Need to build the url from the order id string fullDeleteOrderPath = DeleteOrderPath + orderId; ItBitRequest deleteOrderRequest = new ItBitRequest(BaseUrl, fullDeleteOrderPath, _apiInfo.Key, _apiInfo.Secret, Method.DELETE); deleteOrderRequest.AddParameter("walletId", _walletId); deleteOrderRequest.AddParameter("orderId", orderId); deleteOrderRequest.AddSignatureHeader(); //ItBit doesn't error properly when given a bad order id, so wrap the api call in a try/catch to get a more useful error message. try { ApiPost(deleteOrderRequest); } catch (Exception e) { throw new Exception("Could not delete order " + orderId + " from " + Name + ", most likely the order Id was wrong: " + Environment.NewLine + e.Message); } }
public override Dictionary <string, dynamic> GetOrderInformation(string orderId) { //Need to build the url from the order id string fullOrderQueryPath = OrderQueryPath + orderId; ItBitRequest orderQueryRequest = new ItBitRequest(BaseUrl, fullOrderQueryPath, _apiInfo.Key, _apiInfo.Secret); orderQueryRequest.AddParameter("walletId", _walletId); orderQueryRequest.AddParameter("orderId", orderId); orderQueryRequest.AddSignatureHeader(); //ItBit doesn't error properly when given a bad order id, so wrap the api call in a try/catch to get a more useful error message. try { Dictionary <string, dynamic> orderQueryResponse = ApiPost(orderQueryRequest); return(orderQueryResponse); } catch (Exception e) { throw new Exception("Could not get information for order " + orderId + " from " + Name + ", most likely the order Id was wrong: " + Environment.NewLine + e.Message); } }