Search code examples
c#visual-studiobitcoin

How do I call this function in c#?


I am trying to use an API from BTC-E. I can already do some requests, but thisone gets me puzzled: var orderList = btceApi.GetOrderList();

I don't know how I can use orderList to display my orderhistory and when I run this this it throws an exception (declared in code below).

I am using an example by DmT021 and trying to get some functionallity to work in my Form application.

The function is declared as:

public OrderList GetOrderList(int? from = null, int? count = null, int? fromId = null,
 int? endId = null, bool? orderAsc = null, DateTime? since = null, DateTime? end = null,
 BtcePair? pair = null, bool? active = null)


    {
        var args = new Dictionary<string, string>()
        {
            { "method", "OrderList" }
        };

        if (from != null) args.Add("from", from.Value.ToString());
        if (count != null) args.Add("count", count.Value.ToString());
        if (fromId != null) args.Add("from_id", fromId.Value.ToString());
        if (endId != null) args.Add("end_id", endId.Value.ToString());
        if (orderAsc != null) args.Add("order", orderAsc.Value ? "ASC" : "DESC");
        if (since != null) args.Add("since", UnixTime.GetFromDateTime(since.Value).ToString());
        if (end != null) args.Add("end", UnixTime.GetFromDateTime(end.Value).ToString());
        if (pair != null) args.Add("pair", BtcePairHelper.ToString(pair.Value));
        if (active != null) args.Add("active", active.Value ? "1" : "0");
        var result = JObject.Parse(Query(args));
        if (result.Value<int>("success") == 0)
            throw new Exception(result.Value<string>("error"));
        return OrderList.ReadFromJObject(result["return"] as JObject);
    }

Solution

  • I've never worked with this particular BtceApi API, but, I'll guide you to how to fetch the details.

    From the link what you've shared, you can get to know certain important points related to fetching Order details.

    GetorderList returns an object of type OrderList. // check line 114 of BtceApi.cs

    public OrderList GetOrderList(...){...}
    

    When we switch to OrderList.cs class, it contains one field which is of type dictionary.

    public Dictionary<int, Order> List { get; private set; }
    // my comment - poor naming convention **List** used as identifier name
    

    This Collection is having the values in the form of Order. The Order class is also defined in the same OrderList.cs file having these fields declared:

        public BtcePair Pair { get; private set; }
        public TradeType Type { get; private set; }
        public decimal Amount { get; private set; }
        public decimal Rate { get; private set; }
        public UInt32 TimestampCreated { get; private set; }
        public int Status { get; private set; }
    

    Now, the only task which you're left of with is to extract Order value from your dictionary object orderList, which I leave for you as a homework. Once you get the Order object from the collection, then you can simply read the fields value from the object using order.Amount, etc. where order is of type Order.