Exemplo n.º 1
0
 static void ClosePositions()
 {
     if (_account.Positions.TotalSize > 0m)
     {
         var tran = _market.PlaceOrder(BfxOrder.Market(_account.Positions.Side.GetOpposite(), _account.Positions.TotalSize));
         _transactions[tran.Id] = tran;
     }
 }
        static void UnexecutableOrders()
        {
            while (true)
            {
                Console.WriteLine("===================================================================");
                Console.WriteLine("L)imit order");
                Console.WriteLine("S)top Loss");
                Console.WriteLine("I)FD");
                Console.WriteLine("O)CO order");
                Console.WriteLine("1) Stop limit");
                Console.WriteLine("3) OCO market send");
                Console.WriteLine("");
                Console.WriteLine("C)ancel last order X) Close position");
                Console.Write("Main>Unexecutable Orders>");

                switch (GetCh())
                {
                case 'L':
                    PlaceOrder(BfxOrder.Limit(BfTradeSide.Buy, _market.BestBidPrice - UnexecutableGap, _orderSize));
                    break;

                case 'S':     // Stop sell
                    PlaceOrder(BfxOrder.Stop(BfTradeSide.Sell, _market.BestAskPrice - UnexecutableGap, _orderSize));
                    break;

                case 'I':
                    PlaceOrder(BfxOrder.IFD(
                                   BfxOrder.Limit(BfTradeSide.Buy, _market.BestBidPrice - UnexecutableGap, _orderSize),
                                   BfxOrder.Limit(BfTradeSide.Sell, _market.BestAskPrice + UnexecutableGap, _orderSize)
                                   ));
                    break;

                case 'O':
                    PlaceOrder(BfxOrder.OCO(
                                   BfxOrder.StopLimit(BfTradeSide.Sell, _market.LastTradedPrice + UnexecutableGap, _market.BestAskPrice + UnexecutableGap, _orderSize),
                                   BfxOrder.StopLimit(BfTradeSide.Buy, _market.LastTradedPrice - UnexecutableGap, _market.BestBidPrice - UnexecutableGap, _orderSize)
                                   ));
                    break;

                case '3':
                    PlaceOrder(BfxOrder.OCO(
                                   BfxOrder.Limit(BfTradeSide.Buy, _market.BestBidPrice - UnexecutableGap, _orderSize),
                                   BfxOrder.Limit(BfTradeSide.Sell, _market.BestAskPrice + UnexecutableGap, _orderSize)));
                    break;

                case '1':
                    PlaceOrder(BfxOrder.StopLimit(BfTradeSide.Sell, _market.BestAskPrice - UnexecutableGap, _market.BestAskPrice - UnexecutableGap, _orderSize));
                    break;

                case 'C': CancelOrder(); break;

                case 'X': ClosePositions(); break;

                case ESCAPE: return;
                }
            }
        }
Exemplo n.º 3
0
        static void ConditionalOrders()
        {
            while (true)
            {
                Console.WriteLine("I)FDOCO trailing");
                Console.WriteLine("L)imit IFDOCO");
                Console.WriteLine("T)railing IFDOCO");
                Console.WriteLine("E)xpire test");
                Console.WriteLine("F)OK test");
                Console.WriteLine("C)ancel last order");
                Console.WriteLine("X) Close position");
                Console.WriteLine();
                Console.Write("Main/Conditional Orders>");

                switch (GetCh())
                {
                case 'I':
                    switch (SelectSide())
                    {
                    case BfTradeSide.Buy:
                        PlaceOrder(BfxOrder.IFDOCO(
                                       BfxOrder.Limit(BfTradeSide.Buy, _market.BestBidPrice, _orderSize),
                                       BfxOrder.Trailing(BfTradeSide.Sell, TrailingOffset, _orderSize),
                                       BfxOrder.Stop(BfTradeSide.Sell, _market.BestAskPrice - PnLGap, _orderSize)
                                       ));
                        break;

                    case BfTradeSide.Sell:
                        PlaceOrder(BfxOrder.IFDOCO(
                                       BfxOrder.Limit(BfTradeSide.Sell, _market.BestAskPrice, _orderSize),
                                       BfxOrder.Trailing(BfTradeSide.Buy, TrailingOffset, _orderSize),
                                       BfxOrder.Stop(BfTradeSide.Buy, _market.BestBidPrice + PnLGap, _orderSize)
                                       ));
                        break;
                    }
                    break;

                case 'L':
                    switch (SelectSide())
                    {
                    case BfTradeSide.Buy:
                    {
                        var buyPrice = _market.BestBidPrice;
                        PlaceOrder(BfxOrder.IFDOCO(
                                       BfxOrder.Limit(BfTradeSide.Buy, buyPrice, _orderSize),
                                       BfxOrder.StopLimit(BfTradeSide.Sell, buyPrice - PnLGap, buyPrice - PnLGap, _orderSize),
                                       BfxOrder.Limit(BfTradeSide.Sell, buyPrice + PnLGap * 2m, _orderSize)
                                       ));
                    }
                    break;

                    case BfTradeSide.Sell:
                    {
                        var sellPrice = _market.BestAskPrice;
                        PlaceOrder(BfxOrder.IFDOCO(
                                       BfxOrder.Limit(BfTradeSide.Sell, sellPrice, _orderSize),
                                       BfxOrder.StopLimit(BfTradeSide.Buy, sellPrice + PnLGap, sellPrice + PnLGap, _orderSize),
                                       BfxOrder.Limit(BfTradeSide.Buy, sellPrice - PnLGap * 2m, _orderSize)
                                       ));
                    }
                    break;
                    }
                    break;

                case 'T':
                    switch (SelectSide())
                    {
                    case BfTradeSide.Buy:
                    {
                        var buyPrice = _market.BestBidPrice;
                        PlaceOrder(BfxOrder.IFDOCO(
                                       BfxOrder.Limit(BfTradeSide.Buy, buyPrice, _orderSize),
                                       BfxOrder.Trailing(BfTradeSide.Sell, PnLGap, _orderSize),
                                       BfxOrder.Limit(BfTradeSide.Sell, buyPrice + PnLGap * 2, _orderSize)
                                       ));
                    }
                    break;

                    case BfTradeSide.Sell:
                    {
                        var sellPrice = _market.BestAskPrice;
                        PlaceOrder(BfxOrder.IFDOCO(
                                       BfxOrder.Limit(BfTradeSide.Sell, sellPrice, _orderSize),
                                       BfxOrder.Trailing(BfTradeSide.Buy, PnLGap, _orderSize),
                                       BfxOrder.Limit(BfTradeSide.Buy, sellPrice - PnLGap * 2, _orderSize)
                                       ));
                    }
                    break;
                    }
                    break;

                case 'E':
                    PlaceOrder(BfxOrder.OCO(
                                   BfxOrder.Limit(BfTradeSide.Sell, _market.BestAskPrice + UnexecutableGap, _orderSize),
                                   BfxOrder.Limit(BfTradeSide.Buy, _market.BestBidPrice - UnexecutableGap, _orderSize)),
                               TimeSpan.FromMinutes(1),
                               BfTimeInForce.NotSpecified
                               );
                    break;

                case 'F':
                    PlaceOrder(BfxOrder.OCO(
                                   BfxOrder.Limit(BfTradeSide.Sell, _market.BestAskPrice + UnexecutableGap, _orderSize),
                                   BfxOrder.Limit(BfTradeSide.Buy, _market.BestBidPrice - UnexecutableGap, _orderSize)),
                               TimeSpan.Zero,
                               BfTimeInForce.FOK
                               );
                    break;

                case 'C':
                    CancelOrder();
                    break;

                case 'X':
                    ClosePositions();
                    break;

                case ESCAPE:
                    return;
                }
            }
        }
Exemplo n.º 4
0
        static void SimpleOrders()
        {
            while (true)
            {
                Console.WriteLine("L)imit price order best ask/bid price");
                Console.WriteLine("M)arket price order");
                Console.WriteLine("T)railing");
                Console.WriteLine("E)xpire test");
                Console.WriteLine("F)OK");
                Console.WriteLine("C)ancel last order");
                Console.WriteLine("X) Close position");
                Console.WriteLine();
                Console.Write("Main/Simple Orders>");

                switch (GetCh())
                {
                case 'L':
                    switch (SelectSide())
                    {
                    case BfTradeSide.Buy:
                        PlaceOrder(BfxOrder.Limit(BfTradeSide.Buy, _market.BestBidPrice, _orderSize));
                        break;

                    case BfTradeSide.Sell:
                        PlaceOrder(BfxOrder.Limit(BfTradeSide.Sell, _market.BestAskPrice, _orderSize));
                        break;
                    }
                    break;

                case 'M':
                    switch (SelectSide())
                    {
                    case BfTradeSide.Buy:
                        PlaceOrder(BfxOrder.Market(BfTradeSide.Buy, _orderSize));
                        break;

                    case BfTradeSide.Sell:
                        PlaceOrder(BfxOrder.Market(BfTradeSide.Sell, _orderSize));
                        break;
                    }
                    break;

                case 'T':
                    switch (SelectSide())
                    {
                    case BfTradeSide.Buy:
                        PlaceOrder(BfxOrder.Trailing(BfTradeSide.Buy, PnLGap * 2, _orderSize));
                        break;

                    case BfTradeSide.Sell:
                        PlaceOrder(BfxOrder.Trailing(BfTradeSide.Sell, PnLGap * 2, _orderSize));
                        break;
                    }
                    break;

                case 'E':
                    PlaceOrder(BfxOrder.Limit(BfTradeSide.Buy, _market.BestBidPrice - UnexecutableGap, _orderSize), TimeSpan.FromMinutes(1), BfTimeInForce.NotSpecified);
                    break;

                case 'F':
                    PlaceOrder(BfxOrder.Limit(BfTradeSide.Buy, _market.BestBidPrice - UnexecutableGap, _orderSize), TimeSpan.Zero, BfTimeInForce.FOK);
                    break;

                case 'C':
                    CancelOrder();
                    break;

                case 'X':
                    ClosePositions();
                    break;

                case ESCAPE:
                    return;
                }
            }
        }