TradersOrder

class tradersbot.TradersOrder
addBuy(ticker, quantity, price=None, token=None)

Add a buy order for ticker, of size quantity shares. If no price is passed in, the buy is taken as a market order. If quantity is negative, it is interpreted as a sell order of the positive amount. See Tokens for the token parameter.

addSell(ticker, quantity, price=None, token=None)

Add a sell order for ticker, of size quantity shares. If no price is passed in, the sell is taken as a market order. If quantity is negative, it is interpreted as a buy order of the positive amount. See Tokens for the token parameter.

addTrade(ticker, isBuy, quantity, price=None, token=None)

Submit an order for ticker, of size quantity shares. The order is a buy if isBuy is True and a sell otherwise. The order is a market order if no price is passed in. If quantity is negative, it is interpreted as an order of the opposite type, of the positive amount. See Tokens for the token parameter.

addCancel(ticker, orderId)

Cancel the order for ticker with the given orderId. The orderId is returned on onAckModifyOrders.

toJson(token=None)

Turns a TradersOrder into a JSON string ready to be sent over to MangoCore. See Client-to-Server JSON Format for the details of this format. By default, TradersBot will call this function for you with token=None and then send the JSON to MangoCore, so there’s no need to call it manually. However, there are two possible reasons to call it in your own code:

  1. You want to specify a token for this set of orders, so you can keep track of them later. In this case, call toJson(token) at the end of your code, after you added all your buys, sells, and cancels.

  2. You want to split your orders to be split up into multiple JSON messages. This scenario is highly unlikely; splitting up the orders will make you hit your rate limit faster, and offers no obvious benefits. Regardless, here is example code showing how to do so and the how the sent message differs from the usual:

    # When callback1 is called, MangoCore will receive 1 message
    # 1: {"message_type":"MODIFY ORDERS", "orders":[{"ticker":"AAPL","buy":true,"quantity":20},{"ticker":"GOOG","buy":false,"quantity":50}]}
    def callback1(msg, order):
            order.addBuy('AAPL', 20)
            order.addSell('GOOG', 50)
    
    # When callback2 is called, MangoCore will receive 2 messages
    # 1: {"message_type":"MODIFY ORDERS", "orders":[{"ticker":"AAPL","buy":true,"quantity":20}]}
    # 2: {"message_type":"MODIFY ORDERS", "orders":[{"ticker":"GOOG","buy":false,"quantity":50}], "token":"TOKEN123"}
    def callback2(msg, order):
            order.addBuy('AAPL', 20)
            order.toJson()
            order.addSell('GOOG', 50)
            order.toJson("TOKEN123")