def __hold_fetch_current_positions(self) -> pd.DataFrame:
        # GET ATTRIBUTES
        trading_api = self.__trading_api

        # FETCH HELD PRODUCTS
        request_list = Update.RequestList()
        request_list.values.extend([
            Update.Request(
                option=Update.Option.PORTFOLIO,
                last_updated=0,
            ),
        ])

        update_pb = trading_api.get_update(
            request_list=request_list,
            raw=False,
        )

        # CHECK EMPTINESS
        if len(update_pb.portfolio.values) == 0:
            return pd.DataFrame()
        else:
            positions_partial = self.__hold_filter_current_positions(
                portfolio=update_pb.portfolio, )

            # FETCH ADDITIONAL DATA ON PRODUCTS
            positions = self.__hold_fetch_additional_information(
                positions=positions_partial, )

            return positions
    def pending(self) -> Update.Orders:
        trading_api = self.__trading_api
        request_list = Update.RequestList()
        request_list.values.extend([
            Update.Request(option=Update.Option.ORDERS, last_updated=0),
        ])
        update = trading_api.get_update(request_list=request_list)

        return update.orders
    def update_pending_order(self, order_id: str) -> Union[None, Order]:
        trading_api = self.__trading_api
        request_list = Update.RequestList()
        request_list.values.extend([
            Update.Request(option=Update.Option.ORDERS, last_updated=0),
        ])
        update = trading_api.get_update(request_list=request_list)

        if len(update.orders.values) > 0:
            for order in update.orders.values:
                if order.id == order_id:
                    return order
            return None
        else:
            return None
def update_to_grpc(payload: dict) -> Update:
    update = Update()
    update.response_datetime.GetCurrentTime()

    # ORDERS
    setup_update_orders(update=update, payload=payload)

    # PORTFOLIO
    setup_update_portfolio(
        update=update,
        payload=payload,
    )

    # TOTALPORTFOLIO
    setup_update_total_portfolio(
        update=update,
        payload=payload,
    )

    return update
示例#5
0
# SETUP CREDENTIALS
int_account = config['int_account']
username = config['username']
password = config['password']
credentials = Credentials(int_account=int_account,
                          username=username,
                          password=password)

# SETUP TRADING API
trading_api = TradingAPI(credentials=credentials)

# CONNECT
trading_api.connect()

# SETUP REQUEST
request_list = Update.RequestList()
request_list.values.extend([
    Update.Request(option=Update.Option.ORDERS, last_updated=0),
    Update.Request(option=Update.Option.PORTFOLIO, last_updated=0),
    Update.Request(option=Update.Option.TOTALPORTFOLIO, last_updated=0),
])

update = trading_api.get_update(request_list=request_list, raw=False)
update_dict = pb_handler.message_to_dict(message=update)

if 'orders' in update_dict:
    orders_df = pd.DataFrame(update_dict['orders']['values'])
    print('orders')
    display(orders_df)

if 'portfolio' in update_dict: