public static async Task <LimitOrderResponse> PlaceLimitOrder3(string delta, string buyORsell, decimal qty, decimal rate) { TimeSpan t = DateTime.UtcNow - new DateTime(1970, 1, 1); double timeUnix = t.TotalSeconds; string uri = string.Format("market/{0}limit?apikey={1}&nonce={2}&market={3}&quantity={4}&rate={5}", buyORsell, API_KEY3, timeUnix, delta, qty, rate); HttpRequestMessage mesg = new HttpRequestMessage() { RequestUri = new Uri(uri, UriKind.Relative), Method = HttpMethod.Get }; string sign = GetSignature3(new Uri(client.BaseAddress, mesg.RequestUri)); mesg.Headers.Add("apisign", sign); LimitOrderResponse limitOrder = null; HttpResponseMessage response = await client.SendAsync(mesg); if (response.IsSuccessStatusCode) { limitOrder = await response.Content.ReadAsAsync <LimitOrderResponse>(); } return(limitOrder); }
public static async Task <LimitOrderResponse> CancelLimitOrder(string orderID) { TimeSpan t = DateTime.UtcNow - new DateTime(1970, 1, 1); double timeUnix = t.TotalSeconds; string uri = string.Format("market/cancel?apikey={0}&nonce={1}&uuid={2}", API_KEY, timeUnix, orderID); HttpRequestMessage mesg = new HttpRequestMessage() { RequestUri = new Uri(uri, UriKind.Relative), Method = HttpMethod.Get }; string sign = GetSignature(new Uri(client.BaseAddress, mesg.RequestUri)); mesg.Headers.Add("apisign", sign); LimitOrderResponse limitOrder = null; HttpResponseMessage response = await client.SendAsync(mesg); if (response.IsSuccessStatusCode) { limitOrder = await response.Content.ReadAsAsync <LimitOrderResponse>(); } return(limitOrder); }
public async Task ExecuteStopLoss(StopLoss stopLoss) { if (!stopLoss.virtualSL) { var lowestRate = minimumTradeSatoshis / stopLoss.Quantity; LimitOrderResponse orderResp = await BtrexREST.PlaceLimitOrder(stopLoss.MarketDelta, "sell", stopLoss.Quantity, lowestRate); if (!orderResp.success) { Trace.WriteLine(string.Format(" !!!!ERR ExecuteStopLoss-PLACE-ORDER1>> " + orderResp.message)); Trace.WriteLine(string.Format(" QTY: {1} ... STOP-LOSS RATE: {2}", stopLoss.Quantity, stopLoss.StopRate)); //REDUNTANT (FAILSAFE) CALL ON INITIAL CALL FAILURE orderResp = await BtrexREST.PlaceLimitOrder(stopLoss.MarketDelta, "sell", stopLoss.Quantity, lowestRate); if (!orderResp.success) { Trace.WriteLine(" !!!!ERR ExecuteStopLoss-PLACE-ORDER1.2ndTry>> " + orderResp.message); Trace.WriteLine(string.Format(" QTY: {1} ... STOP-LOSS RATE: {2}", stopLoss.Quantity, stopLoss.StopRate)); return; } } Thread.Sleep(1500); var order = await BtrexREST.GetOrder(orderResp.result.uuid); if (!order.success) { Trace.WriteLine(" !!!!ERR ExecuteStopLoss-GET-ORDER: " + order.message); } stopLoss.ExecutionCallback(order.result, stopLoss.CandlePeriod); } else { var vSell = new GetOrderResult() { Exchange = stopLoss.MarketDelta, Quantity = stopLoss.Quantity, PricePerUnit = BtrexData.Markets[stopLoss.MarketDelta].TradeHistory.RecentFills.Last().Rate * 0.9975M, Closed = DateTime.UtcNow }; stopLoss.ExecutionCallback(vSell, stopLoss.CandlePeriod); } }