public async Task <CryptsyOrderResult> CreateOrder(long marketId, CryptsyOrderType orderType, decimal quantity, decimal price, CancellationToken token = default(CancellationToken)) { return(await RetryHelper.DoAsync(async() => { if (orderType == CryptsyOrderType.Na) { return new CryptsyOrderResult { Success = false, OrderId = -1, Message = "orderType must be BUY or SELL." } } ; CryptsyResponse response = await CryptsyPrivateQuery(new Dictionary <string, string> { { "method", "createorder" }, { "marketid", Convert.ToString(marketId) }, { "ordertype", orderType == CryptsyOrderType.Buy ? "Buy" : "Sell" }, { "quantity", Convert.ToString(quantity, CultureInfo.InvariantCulture) }, { "price", Convert.ToString(price, CultureInfo.InvariantCulture) } }, token, RequestCategory.SubmitOrder); return response.Success ? new CryptsyOrderResult { Success = true, OrderId = response.OrderId, Message = response.Info } : new CryptsyOrderResult { Success = false, OrderId = -1, Message = response.Error }; }, TimeSpan.FromMilliseconds(Constant.DefaultRetryInterval))); }
public static CryptsyOrder ReadFromJObject(JObject o, Int64 marketId = -1, CryptsyOrderType orderType = CryptsyOrderType.Na) { if (o == null) { return(null); } var order = new CryptsyOrder { 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" ? CryptsyOrderType.Buy : CryptsyOrderType.Sell), 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 async Task <decimal> CalculateFee(CryptsyOrderType orderType, decimal quantity, decimal price, CancellationToken token = default(CancellationToken)) { var culture = CultureHelper.GetEnglishCulture(); return(await RetryHelper.DoAsync(async() => { if (orderType == CryptsyOrderType.Na) { return -1; } CryptsyResponse response = await CryptsyPrivateQuery( new Dictionary <string, string> { { "method", "calculatefees" }, { "ordertype", orderType == CryptsyOrderType.Buy ? "Buy" : "Sell" }, { "quantity", Convert.ToString(quantity, culture.NumberFormat) }, { "price", Convert.ToString(price, culture.NumberFormat) } }, token); return response.Success && response.Data != null ? response.Data.Value <decimal>("fee") : -1; }, TimeSpan.FromMilliseconds(Constant.DefaultRetryInterval))); }