Ejemplo n.º 1
0
def demo_01(trader: shift.Trader):
    # We haven't developed a strategy yet.
    # We only want to test whether we could
    # get through the market/limit orders

    limit_buy = shift.Order(shift.Order.Type.LIMIT_BUY, "AAPL", 10, 165.00)
    trader.submit_order(limit_buy)

    xom_limit_buy = shift.Order(shift.Order.Type.LIMIT_BUY, "XOM", 10, 10.00)
    trader.submit_order(xom_limit_buy)

    aapl_market_buy = shift.Order(shift.Order.Type.MARKET_BUY, "AAPL", 1)
    trader.submit_order(aapl_market_buy)

    xom_market_buy = shift.Order(shift.Order.Type.MARKET_BUY, "XOM", 1)
    trader.submit_order(xom_market_buy)

    aapl_market_sell = shift.Order(shift.Order.Type.MARKET_SELL, "AAPL", 1)
    trader.submit_order(aapl_market_sell)

    xom_market_sell = shift.Order(shift.Order.Type.MARKET_SELL, "XOM", 1)
    trader.submit_order(xom_market_sell)

    print("AAPL:")
    print("  Price\t\tSize\t  Dest\t\tTime")
    for order in trader.get_order_book("AAPL", shift.OrderBookType.LOCAL_BID):
        print("%7.2f\t\t%4d\t%6s\t\t%19s" %
              (order.price, order.size, order.destination, order.time))

    print()

    print("XOM:")
    print("  Price\t\tSize\t  Dest\t\tTime")
    for order in trader.get_order_book("XOM", shift.OrderBookType.LOCAL_BID):
        print("%7.2f\t\t%4d\t%6s\t\t%19s" %
              (order.price, order.size, order.destination, order.time))

    print("Buying Power\tTotal Shares\tTotal P&L\tTimestamp")
    print("%12.2f\t%12d\t%9.2f\t%26s" % (
        trader.get_portfolio_summary().get_total_bp(),
        trader.get_portfolio_summary().get_total_shares(),
        trader.get_portfolio_summary().get_total_realized_pl(),
        trader.get_portfolio_summary().get_timestamp(),
    ))

    return
Ejemplo n.º 2
0
def demo_03(trader: shift.Trader):
    """
    This method prints the local bid order book for corresponding symbols.
    :param trader:
    :return:
    """

    print("AAPL:")
    print("  Price\t\tSize\t  Dest\t\tTime")
    for o in trader.get_order_book("AAPL", shift.OrderBookType.LOCAL_BID):
        print("%7.2f\t\t%4d\t%6s\t\t%19s" % (o.price, o.size, o.destination, o.time))

    print()

    print("XOM:")
    print("  Price\t\tSize\t  Dest\t\tTime")
    for o in trader.get_order_book("XOM", shift.OrderBookType.LOCAL_BID):
        print("%7.2f\t\t%4d\t%6s\t\t%19s" % (o.price, o.size, o.destination, o.time))
Ejemplo n.º 3
0
def demo_10(trader: shift.Trader):
    """
    This method prints the global bid order book for a corresponding symbol and type.
    :param trader:
    :return:
    """

    print("  Price\t\tSize\t  Dest\t\tTime")
    for o in trader.get_order_book("AAPL", shift.OrderBookType.GLOBAL_BID, 5):
        print("%7.2f\t\t%4d\t%6s\t\t%19s" % (o.price, o.size, o.destination, o.time))