whispertrades¶
-
class whispertrades.WTClient(token: str =
None, auto_init: bool =True, auto_refresh: bool =True, session: Session =None, endpoint: str ='https://api.whispertrades.com/v1/')[source]¶ Bases:
objectClient for the WhisperTrade API. To initialize, provide a valid API token. Endpoint can be customized if needed e.g. proxy server etc.
- Parameters:¶
- token: str =
None¶ API token obtained from Whispertrade. If not provided, will attempt to read from WHISPERTRADES_API_KEY environment variable.
- auto_init: bool =
True¶ Defaults to True. If True, will automatically query and cache all information about the account that the token has access to. This can be slow.
- auto_refresh: bool =
True¶ Defaults to True. If True, will automatically refresh the attribute on each access (excluding prints). This can be slow and may trigger rate limit. If you do not anticipate them changing often, set this to False. You can also call the respective refresh methods manually e.g. get_orders().
- session: Session =
None¶ Provide your own requests Session object if needed. Defaults to a new session. Rate limiting will be applied on this session.
- endpoint: str =
'https://api.whispertrades.com/v1/'¶ Optional, defaults to https://api.whispertrades.com/v1/, only for debugging or proxying purposes.
- token: str =
- property bots : dict[str, Bot]¶
Returns a list of Bot objects that was cached by the previous call to get_bots(). To refresh, call get_bots() again (not needed if auto_refresh was set to True). If get_bots() was never called, accessing this attribute will call get_bots() and return the result. Auth Required: Read Bots
- property brokers : dict[str, BrokerConnection]¶
Returns a list of BrokerConnection objects that was cached by the previous call to get_broker_connections(). To refresh, call get_broker_connections() again (not needed if auto_refresh was set to True). If get_broker_connections() was never called, accessing this attribute will call get_broker_connections() and return the result. Auth Required: Read Broker Connections
-
get_bot(bot_number: str, include_details: bool =
True) Bot[source]¶ Get information of a bot by number Auth Required: Read Bots
-
get_bots(statuses: list =
None, include_details: bool =False) dict[str, Bot][source]¶ Get information of all bots Auth Required: Read Bots
-
get_broker_connections(number: str =
'')[source]¶ Get a single broker connection or a list of all broker connections Auth Required: Read Broker Connections
-
get_orders(bot: Bot | str =
None, status: 'WORKING' | 'FILLED' | 'CANCELED' =None, from_date: date =None, to_date: date =None, page: int =None) dict[str, Order][source]¶ Get orders, optionally filter by bot, status, date, page. Auth Required: Read Orders
- Parameters:¶
- bot: Bot | str =
None¶ Optional, filter by bot number or Bot instance. If empty, do not filter.
- status: 'WORKING' | 'FILLED' | 'CANCELED' =
None¶ Optional, filter by status, valid values are WORKING, FILLED, CANCELED, EXPIRED, REJECTED. If empty, do not filter.
- from_date: date =
None¶ Optional, filter by date. If empty, do not filter.
- to_date: date =
None¶ Optional, filter by date. If empty, do not filter.
- page: int =
None¶ Optional, defaults to None. If provided, will return orders on that page. If empty, return all pages. Each page is 100 orders. Sorted from newest to oldest.
- bot: Bot | str =
- Returns:¶
dict of Order objects where dict key is the order number
- get_position(number: str) Position[source]¶
Get position by number Auth Required: Read Positions :param number: e.g. GZH7QT03FD :return: Position object
-
get_positions(bot: Bot | str =
None, status: 'OPEN' | 'CLOSE' =None, from_date: date =None, to_date: date =None, page: int =None) dict[str, Position][source]¶ Get positions, optionally filter by bot, status, date, page. Auth Required: Read Positions
- Parameters:¶
- bot: Bot | str =
None¶ Optional, filter by bot number or Bot instance. If empty, do not filter.
- status: 'OPEN' | 'CLOSE' =
None¶ Optional, filter by status, valid values are OPEN and CLOSE. If empty, do not filter.
- from_date: date =
None¶ Optional, filter by date. If empty, do not filter.
- to_date: date =
None¶ Optional, filter by date. If empty, do not filter.
- page: int =
None¶ Optional, defaults to None. If provided, will return positions on that page. If empty, return all pages. Each page is 100 orders. Sorted from newest to oldest.
- bot: Bot | str =
- Returns:¶
dict of Position objects where dict key is the position number
- get_report(number: str) Report[source]¶
Get report by number. Note that this will return detailed return data. Auth Required: Read Reports
-
get_reports(detailed: bool =
False) dict[str, Report][source]¶ Get all reports in this account. Optionally return detailed return data for each report. Auth Required: Read Reports
- Parameters:¶
- detailed: bool =
False¶ Optional, defaults to False. If True, will return detailed return data for each report. This can be very slow. It is recommended to use get_report() to get detailed data for a specific report if you do not need all of them at once.
- detailed: bool =
- Returns:¶
dict of Report objects where dict key is the report number
- get_variables() dict[str, Variable][source]¶
Get all variables in this account Auth Required: Read Variables
- property orders : dict[str, Order]¶
Returns a list of Order objects that was cached by the previous call to get_orders(). To refresh, call get_orders() again (not needed if auto_refresh was set to True). If get_orders() was never called, accessing this attribute will call get_orders() and return the result.
- property positions : dict[str, Position]¶
Returns a list of Position objects that was cached by the previous call to get_positions(). To refresh, call get_positions() again (not needed if auto_refresh was set to True). If get_positions() was never called, accessing this attribute will call get_positions() and return the result.
- property variables : dict[str, Variable]¶
Returns a list of Variable objects that was cached by the previous call to get_variables(). To refresh, call get_variables() again (not needed if auto_refresh was set to True). If get_variables() was never called, accessing this attribute will call get_variables() and return the result.