Beispiel #1
0
        public async Task SyncExistingPositionsWithStock(Action <PositionChangedEventArgs> onPositionChangedCallback)
        {
            var storedPositions = await GetOpenPositions();

            foreach (var currentPosition in storedPositions)
            {
                var currencyPair = currentPosition.OpenPositionOrder.CurrencyPair;
                var activeOrders = await _stockRestConnector.GetActiveOrders(currencyPair);

                var updatedPosition = currentPosition.Clone();

                var updatedOpenPositionOrder = activeOrders.FirstOrDefault(order => order.ClientId == currentPosition.OpenPositionOrder.ClientId) ??
                                               await _stockRestConnector.GetOrderFromHistory(currentPosition.OpenPositionOrder.ClientId, currencyPair) ??
                                               currentPosition.OpenPositionOrder;

                updatedPosition.OpenPositionOrder.SyncWithAnotherOrder(updatedOpenPositionOrder);

                var updatedClosePositionOrder = activeOrders.FirstOrDefault(order => order.ClientId == currentPosition.ClosePositionOrder.ClientId) ??
                                                await _stockRestConnector.GetOrderFromHistory(currentPosition.ClosePositionOrder.ClientId, currencyPair) ??
                                                currentPosition.ClosePositionOrder;

                updatedPosition.ClosePositionOrder.SyncWithAnotherOrder(updatedClosePositionOrder);

                var updatedStopLossOrder = activeOrders.FirstOrDefault(order => order.ClientId == currentPosition.StopLossOrder.ClientId) ??
                                           await _stockRestConnector.GetOrderFromHistory(currentPosition.StopLossOrder.ClientId, currencyPair) ??
                                           currentPosition.StopLossOrder;

                updatedPosition.StopLossOrder.SyncWithAnotherOrder(updatedStopLossOrder);

                await _tradingWorkflowManager.UpdateTradingPositionState(currentPosition, updatedPosition, false, onPositionChangedCallback);
            }
        }
Beispiel #2
0
        private async void OnRunTestClick(object sender, EventArgs e)
        {
            var currencyPair = (await _stockRestConnector.GetCurrencyPairs()).FirstOrDefault(item => item.Id == "DASHBTC");

            var orderId = Guid.NewGuid();

            var initialOrder = new Infrastructure.Common.Models.Trading.Order
            {
                CurrencyPair   = currencyPair,
                ClientId       = orderId,
                Role           = OrderRoleType.ClosePosition,
                OrderSide      = OrderSide.Sell,
                OrderType      = OrderType.Limit,
                OrderStateType = OrderStateType.Suspended,
                TimeInForce    = OrderTimeInForceType.GoodTillCancelled,
                Quantity       = 0.001m,
                Price          = 0.022m,
                StopPrice      = 0
            };

            var newOrder = await _stockRestConnector.CreateOrder(initialOrder, true);

            var cancelledOrder = await _stockRestConnector.CancelOrder(newOrder);

            var testOrder = await _stockRestConnector.GetOrderFromHistory(initialOrder.ClientId, currencyPair);

            MessageBox.Show(@"Passed");
        }
Beispiel #3
0
 public async Task <Order> GetOrderFromHistory(Guid clientOrderId, Infrastructure.Common.Models.Market.CurrencyPair currencyPair)
 {
     return(await _stockRestConnector.GetOrderFromHistory(clientOrderId, currencyPair));
 }