//***************************************************************** public void RegisterOpenOrder(OpenOrder openOrd, string uniqueIdentifier) { bool added; do { added = OpenOrders.TryAdd(uniqueIdentifier, openOrd); } while (!added); }
public async Task ExecuteNewOrder(NewOrder ord) { Trace.WriteLine(string.Format("%%%%PLACING ORDER1: {0} {1} ... QTY: {2} ... RATE: {3} ", ord.BUYorSELL, ord.MarketDelta, ord.Qty, ord.Rate)); //PLACE INITIAL ORDER: var orderResp = await BtrexREST.PlaceLimitOrder(ord.MarketDelta, ord.BUYorSELL, ord.Qty, ord.Rate); if (!orderResp.success) { orderResp = await BtrexREST.PlaceLimitOrder2(ord.MarketDelta, ord.BUYorSELL, ord.Qty, ord.Rate); if (!orderResp.success) { Trace.WriteLine(" !!!!ERR ExecuteNewOrder-PLACE-ORDER1>> " + orderResp.message); Trace.WriteLine(string.Format("{0} {3} QTY: {1} ... RATE: {2}", ord.MarketDelta, ord.Qty, ord.Rate, ord.BUYorSELL)); return; } } //Wait for server processing time and then call order data: Thread.Sleep(1000); var getOrder1 = await BtrexREST.GetOrder(orderResp.result.uuid); if (!getOrder1.success) { Trace.WriteLine(" !!!!ERR ExecuteNewOrder-GET-ORDER1: " + getOrder1.message); } var totalQty = 0M; var totalReserved = 0M; if (getOrder1.result.Type.ToUpper() == "LIMIT_SELL") { totalQty = getOrder1.result.Quantity; totalReserved = getOrder1.result.Price; } else if (getOrder1.result.Type.ToUpper() == "LIMIT_BUY") { totalReserved = getOrder1.result.Reserved; totalQty = getOrder1.result.Quantity - getOrder1.result.QuantityRemaining; } //Enter Order Data into Dictionary var order = new OpenOrder(getOrder1.result, totalQty, totalReserved, ord.DataUpdateCallback, ord.ExecutionCompleteCallback, ord.CandlePeriod); RegisterOpenOrder(order, ord.UniqueID); }
public async Task VirtualExecuteNewOrder(NewOrder ord) { //CREATE ORDER-DATA FROM ord var type = ""; var TotRes = 0M; var openTime = DateTime.UtcNow; if (ord.BUYorSELL.ToUpper() == "BUY") { type = "LIMIT_BUY"; TotRes = ord.Qty * ord.Rate * 1.0025M; } else if (ord.BUYorSELL.ToUpper() == "SELL") { type = "LIMIT_SELL"; TotRes = ord.Qty * ord.Rate * 1.0025M; } var orderData = new OpenOrder("VIRTUAL-NO-ID", ord.MarketDelta, type, ord.Qty, TotRes, ord.Qty, 0M, ord.Rate, 0M, 0M, 0M, 0M, TotRes, 0M, openTime, ord.DataUpdateCallback, ord.ExecutionCompleteCallback, ord.CandlePeriod); var orderResult = new GetOrderResult() { CancelInitiated = false, Opened = openTime, Closed = DateTime.UtcNow, Exchange = ord.MarketDelta, IsOpen = false, Limit = ord.Rate, Price = TotRes, Quantity = ord.Qty, Reserved = TotRes, Type = type, OrderUuid = orderData.OrderUuid }; //CALL EXE-CALLBACK WITH MOCK DATA: orderData.CompleteOrder(orderResult); }