Example #1
0
    def update_order_status():

        if TradeManager.stopLossTriggered == False:
            orders = DatabaseManager.get_all_open_orders()

            client = RestClient(ConfigManager.get_config().apiKey1,
                                ConfigManager.get_config().apiSecret1,
                                ConfigManager.get_config().apiUrl)

            for order in orders:

                try:

                    updatedOrder = client.getorderstate(order.orderId)

                    DatabaseManager.update_order_entry(order.orderId,
                                                       updatedOrder['state'])

                    if updatedOrder['state'] == "filled":

                        if "SLMS" in order.orderId:
                            # Stop loss fired
                            Util.get_logger().info(
                                "STOP LOSS FIRED - CANCELLING ALL ORDERS")
                            TradeManager.cancel_all_current_orders()

                            TradeManager.stopLossTriggered = True

                        else:
                            if updatedOrder['direction'] == "buy":

                                if ConfigManager.get_config().fcbMode:
                                    #Create new one
                                    DatabaseManager.create_order_entry(
                                        "",
                                        order.price + ConfigManager.get_config(
                                        ).priceDistance,
                                        ConfigManager.get_config(
                                        ).contractSize, "sell")

                                else:
                                    sellPriceOffset = ConfigManager.get_config(
                                    ).basePrice - order.price
                                    DatabaseManager.create_order_entry(
                                        "",
                                        ConfigManager.get_config().basePrice +
                                        sellPriceOffset,
                                        ConfigManager.get_config(
                                        ).contractSize, "sell")

                            else:

                                if ConfigManager.get_config().fcbMode:
                                    DatabaseManager.create_order_entry(
                                        "",
                                        order.price - ConfigManager.get_config(
                                        ).priceDistance,
                                        ConfigManager.get_config(
                                        ).contractSize, "buy")
                                else:
                                    # put in buy order
                                    buyPriceOffset = order.price - ConfigManager.get_config(
                                    ).basePrice
                                    DatabaseManager.create_order_entry(
                                        "",
                                        ConfigManager.get_config().basePrice +
                                        buyPriceOffset,
                                        ConfigManager.get_config(
                                        ).contractSize, "buy")
                except:
                    pass
        else:
            #We no longer update our queue until user resets
            pass
Example #2
0
    def update_order_status():

        orders = DatabaseManager.get_all_open_orders()

        client = RestClient(ConfigManager.get_config().apiKey1,
                            ConfigManager.get_config().apiSecret1,
                            ConfigManager.get_config().apiUrl)

        Util.get_logger().info("Updating orders")

        for order in orders:

            updatedOrder = client.getorderstate(order.orderId)

            if updatedOrder['state'] == "filled":

                if updatedOrder['direction'] == "buy":

                    if ConfigManager.get_config().fcbMode:

                        #Create new one
                        newOrder = TradeManager.create_new_sell_order(
                            updatedOrder["price"] +
                            ConfigManager.get_config().priceDistance,
                            updatedOrder['quantity'], False)
                        DatabaseManager.create_order_entry(
                            newOrder['order']['orderId'],
                            newOrder['order']['price'],
                            newOrder['order']['quantity'],
                            newOrder['order']['direction'])

                    else:

                        sellPriceOffset = ConfigManager.get_config(
                        ).basePrice - updatedOrder["price"]

                        #Create new one
                        newOrder = TradeManager.create_new_sell_order(
                            ConfigManager.get_config().basePrice +
                            sellPriceOffset, updatedOrder['quantity'], False)
                        DatabaseManager.create_order_entry(
                            newOrder['order']['orderId'],
                            newOrder['order']['price'],
                            newOrder['order']['quantity'],
                            newOrder['order']['direction'])

                else:

                    if ConfigManager.get_config().fcbMode:

                        newOrder = TradeManager.create_new_buy_order(
                            updatedOrder["price"] -
                            ConfigManager.get_config().priceDistance,
                            updatedOrder['quantity'], False)
                        DatabaseManager.create_order_entry(
                            newOrder['order']['orderId'],
                            newOrder['order']['price'],
                            newOrder['order']['quantity'],
                            newOrder['order']['direction'])
                    else:
                        # put in buy order
                        buyPriceOffset = updatedOrder[
                            "price"] - ConfigManager.get_config().basePrice
                        #Create new one
                        newOrder = TradeManager.create_new_buy_order(
                            ConfigManager.get_config().basePrice +
                            buyPriceOffset, updatedOrder['quantity'], False)
                        DatabaseManager.create_order_entry(
                            newOrder['order']['orderId'],
                            newOrder['order']['price'],
                            newOrder['order']['quantity'],
                            newOrder['order']['direction'])

                DatabaseManager.update_order_entry(order.orderId,
                                                   updatedOrder['state'])