public decimal CalculateFee(Order.ORDER_TYPE orderType,decimal quantity, decimal price)
        {
            if (orderType == Order.ORDER_TYPE.NA) return -1;

            CryptsyResponse response = CryptsyQuery(true, new Dictionary<string, string>() { { "method", "calculatefees" },{"ordertype",orderType==Order.ORDER_TYPE.BUY ? "Buy" : "Sell"},{"quantity",quantity.ToString(CultureInfo.InvariantCulture)}, {"price",price.ToString(CultureInfo.InvariantCulture)} });

            if (response.Success)
            {
                JObject o = (JObject)response.Data;
                if (o != null)
                    return o.Value<decimal>("fee");
                else
                    return -1;
            }
            else
                return -1;
        }
Example #2
0
        public static Order ReadFromJObject(JObject o, Int64 marketID = -1, ORDER_TYPE orderType = ORDER_TYPE.NA)
        {
            if (o == null)
                return null;

            var order = new Order()
            {
                Price = o.Value<decimal>("price"),
                Quantity = o.Value<decimal>("quantity"),
                Total = o.Value<decimal>("total"),
                OriginalQuantity = o.Value<decimal?>("orig_quantity") ?? -1,
                MarketID = o.Value<Int64?>("marketid") ?? marketID,

                //If ordertype is present, use it, if not: use the ordertype passed to the method
                OrderType = o.Value<string>("ordertype") == null ? orderType : (o.Value<string>("ordertype").ToLower() == "buy" ? ORDER_TYPE.BUY : ORDER_TYPE.SELL)

            };

            order.CreatedUTC = o.Value<DateTime?>("created");
            if (order.CreatedUTC != null)
                order.CreatedUTC = TimeZoneInfo.ConvertTime((DateTime)order.CreatedUTC, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"), TimeZoneInfo.Utc); //Convert to UTC

            return order;
        }
        public OrderResult CreateOrder(Int64 marketID, Order.ORDER_TYPE orderType, decimal quantity, decimal price)
        {
            if (orderType == Order.ORDER_TYPE.NA) return new OrderResult() { Success = false, OrderID = -1, Message = "orderType must be BUY or SELL." };

            CryptsyResponse response = CryptsyQuery(true, new Dictionary<string, string>() {
            { "method", "createorder" },
            {"marketid",marketID.ToString() },
            {"ordertype",orderType==Order.ORDER_TYPE.BUY?"Buy":"Sell"},
            {"quantity",quantity.ToString(CultureInfo.InvariantCulture)},
            {"price",price.ToString(CultureInfo.InvariantCulture)}});

            if (response.Success)
                return new OrderResult() { Success = true, OrderID = response.OrderID, Message = response.Info };
            else
                return new OrderResult() { Success = false, OrderID = -1, Message = response.Error };
        }