Beispiel #1
0
        private static void Client_OwnTradesReceived(object sender, Events.KrakenPrivateEventArgs<OwnTradesMessage> e)
        {

            List<TradeObject> trades = e.PrivateMessage.Trades;

            for (int i = 0; i < trades.Count; i++)
            {
                TradeObject t = trades[i];

                OsEngine.Entity.MyTrade trade = new OsEngine.Entity.MyTrade();
                trade.NumberOrderParent = t.OrderTxId;
                trade.Price = t.Price;
                trade.NumberTrade = t.TradeId;
                string pair = t.Pair.ToString();

                Sec security = Securities.Find(sec => sec.NameInSocket == pair);

                if (security == null)
                {
                    return;
                }

                trade.SecurityNameCode = security.NameInRest;
                trade.Volume = t.Volume;
                DateTime time = new DateTime(1970, 1, 1).AddSeconds(Convert.ToDouble(t.Time));
                trade.Time = time;

                if (t.Type == "sell")
                {
                    trade.Side = OsEngine.Entity.Side.Sell;
                }
                else
                {
                    trade.Side = OsEngine.Entity.Side.Sell;
                }

                if (MyTradeUpdateEvent != null)
                {
                    MyTradeUpdateEvent(trade);
                }
            }


            //
            // = (sender, e) => Console.WriteLine($"OwnTrades received");
        }
Beispiel #2
0
        private static void Client_OpenOrdersReceived(object sender, Events.KrakenPrivateEventArgs<OpenOrdersMessage> e)
        {
            //OrdersUpdateEvent

            List<Order> orders = e.PrivateMessage.Orders.ToList();

            for (int i = 0; i < orders.Count; i++)
            {
                Order o = orders[i];

                int numberUser = 0;

                if (o.UserRef == 0)
                {
                    OrdersRef myRef = _ordersRefs.Find(ord => ord.MarketRef == o.OrderId);
                    if(myRef == null)
                    {
                        continue;
                    }
                    else
                    {
                        numberUser = myRef.UserRef;
                    }
                }
                else if(_ordersRefs.Find(ord => ord.UserRef == o.UserRef) == null)
                {
                    OrdersRef newRef = new OrdersRef();
                    newRef.MarketRef = o.OrderId;
                    newRef.UserRef = Convert.ToInt32(o.UserRef);
                    _ordersRefs.Add(newRef);

                    numberUser = Convert.ToInt32(o.UserRef);
                }

                OsEngine.Entity.Order orderOsEngine = new OsEngine.Entity.Order();

                orderOsEngine.NumberMarket = o.OrderId;
                orderOsEngine.NumberUser = numberUser;

                DateTime time = new DateTime(1970, 1, 1).AddSeconds(Convert.ToDouble(o.OpenTimestamp));

                orderOsEngine.TimeCallBack = time;

                if (o.Status == "canceled" ||
                    o.Status == "expired")
                {
                    orderOsEngine.State = OsEngine.Entity.OrderStateType.Cancel;
                }

                else if (o.Status == "closed" ||
                    o.Status == "canceled" ||
                    o.Status == "expired")
                {
                    orderOsEngine.State = OsEngine.Entity.OrderStateType.Done;
                }

                else
                {
                    orderOsEngine.State = OsEngine.Entity.OrderStateType.Activ;
                }

                if (OrdersUpdateEvent != null)
                {
                    OrdersUpdateEvent(orderOsEngine);
                }
            }


            // = (sender, e) => Console.WriteLine($"OpenOrders received");
        }