コード例 #1
0
    def do_set_num_orders(self, line):
        arguments = Util.safe_str_split_on_space(line)

        if len(arguments) >= 1:
            config = ConfigManager.get_config()
            config.numOfOrders = int(arguments[0])
            ConfigManager.update_config(config)
            Util.get_logger().info("Updated number of orders to: " + str(config.numOfOrders))
        else:
            Util.get_logger().info("Not enough parameters. Ex. set_num_orders 5")
コード例 #2
0
    def cancel_all_current_orders():

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

        for order in orders:
            client.cancel(order.orderId)
            DatabaseManager.update_order_entry(order.orderId, "cancelled")
            Util.get_logger().info("Cancelled order: " + str(order.orderId))
コード例 #3
0
ファイル: main.py プロジェクト: bhageshvar/derishell
    def do_set_price_distance(self, line):

        arguments = Util.safe_str_split_on_space(line)

        if len(arguments) >= 1:
            config = ConfigManager.get_config()
            config.priceDistance = float(arguments[0])
            ConfigManager.update_config(config)
            Util.get_logger().info("Upddated price difference to: " + str(config.priceDistance))
        else:
            Util.get_logger().info("Not enough parameters. Ex. set_price_distance 1(in USD)")    
コード例 #4
0
ファイル: main.py プロジェクト: bhageshvar/derishell
    def do_set_contract_amount(self, line):

        arguments = Util.safe_str_split_on_space(line)

        if len(arguments) >= 1:
            config = ConfigManager.get_config()
            config.contractSize = int(arguments[0])
            ConfigManager.update_config(config)
            Util.get_logger().info("Upddated number of contracts to: " + str(config.contractSize))
        else:
            Util.get_logger().info("Not enough parameters. Ex. set_contract_amount 100")       
コード例 #5
0
ファイル: main.py プロジェクト: bhageshvar/derishell
    def do_set_base_price(self, line):

        arguments = Util.safe_str_split_on_space(line)

        if len(arguments) >= 1:
            config = ConfigManager.get_config()
            config.basePrice = float(arguments[0])
            ConfigManager.update_config(config)
            Util.get_logger().info("Upddated base price to: " + str(config.basePrice))
        else:
            Util.get_logger().info("Not enough parameters. Ex. set_base_price 6000")
コード例 #6
0
    def close_all_positions():
        client = RestClient(ConfigManager.get_config().apiKey1,
                            ConfigManager.get_config().apiSecret1,
                            ConfigManager.get_config().apiUrl)
        positions = client.positions()

        for x in positions:
            if x['direction'] == 'buy':
                client.sell(ConfigManager.get_config().tradeInsturment,
                            x['size'], 1, False, "")
            else:
                client.buy(ConfigManager.get_config().tradeInsturment,
                           x['size'], 99999, False, "")
コード例 #7
0
    def setup_inital_ladder():
        Util.get_logger().info("Setup initial ladder")

        for x in range(ConfigManager.get_config().numOfOrders):
            order = TradeManager.create_new_buy_order(
                (ConfigManager.get_config().basePrice -
                 ConfigManager.get_config().priceDistance) -
                (ConfigManager.get_config().priceDistance * x),
                ConfigManager.get_config().contractSize, True)

            DatabaseManager.create_order_entry(order['order']['orderId'],
                                               order['order']['price'],
                                               order['order']['amount'],
                                               order['order']['direction'])
コード例 #8
0
    def show_current_orders():

        openOrders = DatabaseManager.get_all_open_orders(
        ) + DatabaseManager.get_all_pending_orders()

        print()

        table_data = []

        table_data.append(
            [ColorText.yellow(ConfigManager.get_config().basePrice)])
        table = AsciiTable(table_data, "Base")
        print(table.table)

        print()

        TradeManager.show_sells_table(openOrders)

        print()

        TradeManager.show_buys_table(openOrders)

        print()
コード例 #9
0
    def setup_inital_ladder():
        Util.get_logger().info("Setup initial ladder")

        for x in range(ConfigManager.get_config().numOfOrders):
            DatabaseManager.create_order_entry(
                "", (ConfigManager.get_config().basePrice -
                     ConfigManager.get_config().priceDistance) -
                (ConfigManager.get_config().priceDistance * x),
                ConfigManager.get_config().contractSize, "buy")

        TradeManager.update_pending_orders()

        # Create the stop loss order
        order = TradeManager.create_sl_sell_order(
            ConfigManager.get_config().stopLossPrice,
            ConfigManager.get_config().numOfOrders *
            ConfigManager.get_config().contractSize)
        DatabaseManager.create_sl_order_entry(
            order['order']['orderId'],
            ConfigManager.get_config().stopLossPrice,
            ConfigManager.get_config().numOfOrders *
            ConfigManager.get_config().contractSize)
コード例 #10
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
コード例 #11
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'])
コード例 #12
0
ファイル: main.py プロジェクト: bhageshvar/derishell
 def do_get_summary(self,line):
     if self.client1 != None:
         print(self.client1.getsummary(ConfigManager.get_config().tradeInsturment))