Exemplo n.º 1
0
        public void PlaceTradeAsync(int tradingAccountId, int marketId, TradeDirection direction, decimal quantity, decimal bidPrice, decimal offerPrice, int[] close, TradeOrderResponseDelegate callback)
        {
            NewTradeOrderRequestDTO orderRequest;

            lock (_syncObj)
            {
                PriceDTO price;

                _prices.TryGetValue(marketId, out price);

                if (price == null)
                {
                    throw new Exception("you must have a price subscription in order to place a trade");
                }

                orderRequest = new NewTradeOrderRequestDTO
                {
                    AuditId          = price.AuditId,
                    MarketId         = marketId,
                    Direction        = direction.ToString(),
                    BidPrice         = bidPrice,
                    OfferPrice       = offerPrice,
                    Quantity         = quantity,
                    Close            = close,
                    TradingAccountId = tradingAccountId
                };
            }

            PlaceTradeAsync(orderRequest, callback);
        }
Exemplo n.º 2
0
        public override string ToString()
        {
            //return base.ToString();

            return(String.Format("Trade:  {0}, timestamp:{1}, tradedirection:{2}, No of shares: {3},  price:{4} ",
                                 Stock.Symbol,
                                 TimeStamp.ToString("yyyyMMddHHmmssfff"),
                                 TradeDirection.ToString(),
                                 SharesNumber,
                                 Price.ToString("F")

                                 ));
        }
 public void HitBtcHedgePositionOpen(string clOrdID, TradeDirection direction)
 {
     // New order
     //Int32 b = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds);
     clOrdID = "123456" + clOrdID;
     _dataService.WebSocket.Send("{\"method\": \"newOrder\",\"params\": {\"clientOrderId\": \"" + clOrdID + "\",\"symbol\": \"ETHUSD\",\"side\": \"" + direction.ToString().ToLower() + "\",\"type\": \"market\",\"price\": \"0.05983\",\"quantity\": \"0.001\"},\"id\": 123}");
 }
Exemplo n.º 4
0
 public override string ToString()
 {
     return($"TradeDirection : {TradeDirection.ToString()}, OrderTimeStamp:{OrderOpenTimeStamp}, EntryPrice: {EntryPrice}, TargetPrice: {TargetPrice}, MaximumDrawDown: {MaxDrawDownPips}");
 }
Exemplo n.º 5
0
 public override string ToString()
 {
     return($"TradeGroupId : {TradeGroupId.ToString()},ConsecutiveWinNumber: {ConsecutiveWinNumber}, WinAfterConsecutiveLoses:{WinAfterConsecutiveLoses},  TradeDirection : {TradeDirection.ToString()}, OrderTimeStamp:{OrderOpenTimeStamp}, EntryPrice: {EntryPrice}, ExitPrice: {ExitPrice}, MaximumDrawDown: {MaximumDrawDownPips}");
 }
Exemplo n.º 6
0
        private void sendorder(Option o, TradeDirection tradedirection, double price, int volume)
        {
            //查询同向委托
            List <OrderBook> entrustlist = o.entrustbook.FindAll(delegate(OrderBook b) { return(b.tradecode == o.tradecode && b.tradedirection == tradedirection); });

            //有同向委托
            bool flg = false;

            if (entrustlist != null && entrustlist.Count > 0)
            {
                //检查若委托价量相同,则跳过
                foreach (OrderBook b in entrustlist)
                {
                    if (Math.Abs(b.price - price) < 0.0001 && b.volume == volume)
                    {
                        //委托价量相同
                        Debug.Print(string.Format("委托已经存在:c={0},t={1}.p={2},v={3}", o.tradecode, tradedirection.ToString(), price, volume));
                        flg = true;
                        continue;
                    }
                    else
                    {
                        //委托价量不同,则撤单
                        o._hunsun.Withdraw(b.entrustno);
                    }
                }

                //相同价量委托已存在,跳过
                if (flg)
                {
                    return;
                }
            }

            //无同向委托,或者已被撤单,查反向持仓
            OrderBook revposition = null;

            if (tradedirection == TradeDirection.BUY)
            {
                //欲委托买入,先查询当前空头持仓,优先买入平仓
                revposition = o.positionbook.Find(delegate(OrderBook b) { return(b.tradecode == o.tradecode && b.tradedirection == TradeDirection.SELL); });
            }
            else
            {
                //欲委托卖出,先查询当前多头持仓,优先卖出平仓
                revposition = o.positionbook.Find(delegate(OrderBook b) { return(b.tradecode == o.tradecode && b.tradedirection == TradeDirection.BUY); });
            }

            EntrustHunsun.EntrustPara para = new EntrustHunsun.EntrustPara();
            para.marketno  = ((int)Exchange.SH).ToString();
            para.stockcode = o.tradecode;
            para.volume    = volume;
            para.price     = price;

            if (revposition == null)
            {
                //无反向持仓,开仓
                para.entrustdirection = ((int)tradedirection).ToString();
                para.futuredirection  = ((int)FutureDirection.OPEN).ToString();
                o._hunsun.Entrust(para);
                Debug.Print(string.Format("开仓:T={0},c={1},p={2},v={3}", tradedirection.ToString(), o.tradecode, price, volume));
            }
            else
            {
                //有反向持仓
                if (revposition.volume >= volume)
                {
                    //持有足够反向头寸,平仓
                    para.entrustdirection = ((int)tradedirection).ToString();
                    para.futuredirection  = ((int)FutureDirection.COVER).ToString();
                    o._hunsun.Entrust(para);
                    Debug.Print(string.Format("平仓:T={0},c={1},p={2},v={3}", tradedirection.ToString(), o.tradecode, price, volume));
                }
                else
                {
                    //持有反向头寸不足,先平后开
                    para.entrustdirection = ((int)tradedirection).ToString();
                    para.futuredirection  = ((int)FutureDirection.COVER).ToString();
                    para.volume           = revposition.volume;
                    o._hunsun.Entrust(para);
                    Debug.Print(string.Format("平仓:T={0},c={1},p={2},v={3}", tradedirection.ToString(), o.tradecode, price, revposition.volume));

                    para.entrustdirection = ((int)tradedirection).ToString();
                    para.futuredirection  = ((int)FutureDirection.OPEN).ToString();
                    para.volume           = volume - revposition.volume;
                    o._hunsun.Entrust(para);
                    Debug.Print(string.Format("开仓:T={0},c={1},p={2},v={3}", tradedirection.ToString(), o.tradecode, price, volume - revposition.volume));
                }
            }
        }
Exemplo n.º 7
0
        public void PlaceTradeAsync(int tradingAccountId, int marketId, TradeDirection direction, decimal quantity, decimal bidPrice, decimal offerPrice, int[] close, TradeOrderResponseDelegate callback)
        {
            NewTradeOrderRequestDTO orderRequest;
            lock (_syncObj)
            {
                PriceDTO price;

                _prices.TryGetValue(marketId, out price);

                if (price == null)
                {
                    throw new Exception("you must have a price subscription in order to place a trade");
                }

                orderRequest = new NewTradeOrderRequestDTO
                                   {
                                       AuditId = price.AuditId,
                                       MarketId = marketId,
                                       Direction = direction.ToString(),
                                       BidPrice = bidPrice,
                                       OfferPrice = offerPrice,
                                       Quantity = quantity,
                                       Close = close,
                                       TradingAccountId = tradingAccountId
                                   };
            }

            PlaceTradeAsync(orderRequest, callback);


        }