kalshi

Submodules

Package Contents

Classes

Session

A Kalshi session. All API requests are defined on this class.

class kalshi.Session(email=None, password=None, endpoint='https://trading-api.kalshi.com/v1')

A Kalshi session. All API requests are defined on this class.

Parameters
  • email (str) – The email you use to log in. (This can also be configured with the KALSHI_EMAIL environment variable.)

  • password (str) – The password you use to log in. (This can also be configured with the KALSHI_PASSWORD environment variable.)

  • endpoint (str) – The Kalshi API endpoint. Defaults to the public v1 API.

post(self, path, obj=None)
get(self, path, obj=None)
get_markets_cached(self)

End-point for listing / discovering markets on Kalshi with data that is cached and so slightly lagged.

get_market_history_cached(self, market_id, last_seen_ts=None)

End-point for getting the statistics history for a market with data that is cached and so slightly lagged.

The value for the market_id path parameter should match the id value of the target market. The last_seen_ts parameter is optional, and will restrict statistics to those after provided timestamp. The last_seen_ts is inclusive, which means a market history point at last_seen_ts will be returned

Parameters
  • market_id (string) – Should be filled with the id of the target market

  • last_seen_ts (integer) – If provided, restricts history to trades starting from lastSeenTs

get_exchange_status(self)

End-point for getting the exchange status

login_mfa(self)

End-point to start a rest session with Kalshi, when you have 2FA enabled.

Before calling this end-point you should call (POST /log_in) using email and password.

logout(self)

End-point to terminates your session with Kalshi.

get_markets(self)

End-point for listing / discovering markets on Kalshi.

get_market_cached(self, market_id)

End-point for getting data about a specific market with data that is cached and so slightly lagged.

The value for the market_id path parameter should match the id value of the target market.

Parameters

market_id (string) – Should be filled with the id of the target market

get_market_order_book_cached(self, market_id)

End-point for getting the orderbook for a market with data that is cached and so slightly lagged.

The value for the market_id path parameter should match the id value of the target market.

Parameters

market_id (string) – Should be filled with the id of the target market

get_market_history(self, market_id, last_seen_ts=None)

End-point for getting the statistics history for a market.

The value for the market_id path parameter should match the id value of the target market. The last_seen_ts parameter is optional, and will restrict statistics to those after provided timestamp. The last_seen_ts is inclusive, which means a market history point at last_seen_ts will be returned

Parameters
  • market_id (string) – Should be filled with the id of the target market

  • last_seen_ts (integer) – If provided, restricts history to trades starting from lastSeenTs

reset_password(self)

End-point to request a password reset email link.

To be used in case you forget your password.

reset_password_confirm(self, code)

End-point to finish the password reset flow.

The code param on the path should be filled with the verification code sent by email.

Parameters

code (string) – Should be filled with the verification code received on the sign-up email.

user_create(self)

End-point for creating an user. A call to this end-point starts the sign-up flow.

user_get_profile(self, user_id)

End-point for retrieving the logged in user’s profile.

The value for the user_id path parameter should match the user_id value returned on the response for the last login request (POST /log_in).

Parameters

user_id (string) – Should be filled with your user_id provided on log_in

user_update_profile(self, user_id)

End-point for submitting your user profile during sign-up, or updating it after sign-up is complete.

The value for the user_id path parameter should match the user_id value returned either in the response for the last login request (POST /log_in) or for the create user request (POST /users).

Parameters

user_id (string) – This parameter should be filled with your user_id provided on log_in

user_get_account_history(self, user_id, ShouldReturnDeposits=None, ShouldReturnWithdrawals=None, ShouldReturnOrders=None, ShouldReturnSettlements=None, ShouldReturnTrades=None, Limit=None)

End-point for getting the logged in user’s important past actions and events related to the user’s positions.

This contains entries for user’s explicit actions but also for market events.

There will be entries for:

submitting, editing / canceling orders requesting deposits and withdrawals trade execution (order matching) market settlements on markets where you have a position

The value for the user_id path parameter should match the user_id value returned on the response for the last login request (POST /log_in).

Parameters
  • user_id (string) – This parameter should be filled with your user_id provided on log_in

  • ShouldReturnDeposits (boolean) – If true the response should include deposit entries

  • ShouldReturnWithdrawals (boolean) – If true the response should include withdrawal entries

  • ShouldReturnOrders (boolean) – If true the response should include order entries

  • ShouldReturnSettlements (boolean) – If true the response should include settlement entries

  • ShouldReturnTrades (boolean) – If true the response should include trade entries

  • Limit (integer) – Restricts the response to a return the first “limit” amount of acct history items

user_get_balance(self, user_id)

End-point for getting the balance of the logged in user.

The value for the user_id path parameter should match the user_id value returned on the response for the last login request (POST /log_in).

Parameters

user_id (string) – Should be filled with your user_id provided on log_in

user_list_ledgerx_bank_accounts(self, user_id)

End-point for getting connected accounts from the clearing house.

The value for the user_id path parameter should match the user_id value returned on the response for the last login request (POST /log_in).

Parameters

user_id (string) – Should be filled with your user_id provided on log_in

End-point for submitting to finish bank account linking.

This end-point sends the bank accounts connected by the user in the front-end to our clearing house.

The value for the user_id path parameter should match the user_id value returned on the response for the last login request (POST /log_in).

Parameters

user_id (string) – This parameter should be filled with your user_id provided on log_in

get_user_deposits(self, user_id, page_size=None, page_number=None)

End-point for getting all deposits for the logged in user.

The value for the user_id path parameter should match the user_id value returned on the response for the last login request (POST /log_in).

Parameters
  • user_id (string) – This parameter should be filled with your user_id provided on log_in

  • page_size (integer) – Number of deposits in each page.

  • page_number (integer) – Number of the page to be retrieved.

user_request_deposit(self, user_id)

End-point for starting deposits on the logged in user’s account.

The value for the user_id path parameter should match the user_id value returned on the response for the last login request (POST /log_in).

In order to request deposits you need to have connected at least one account using (POST /user/{user_id}/banks/linked_accounts).

Parameters

user_id (string) – This parameter should be filled with your user_id provided on log_in

user_send_email_confirmation(self, user_id)

End-point for re-sending email verification. To be used in case e-mail verification doesn’t arrive or verification code is expired.

The value for the user_id path parameter should match the user_id value returned on the response for the create user request (POST /users).

Parameters

user_id (string) – Should be filled with your user_id provided on log_in

user_get_kyc(self, user_id)

End-point for retrieving your user kyc profile.

The value for the user_id path parameter should match the user_id value returned on the response for the last login request (POST /log_in).

Parameters

user_id (string) – Should be filled with your user_id provided on log_in

user_update_kyc(self, user_id)

End-point for submitting / updating your user kyc profile during sign-up.

The value for the user_id path parameter should match the user_id value returned on the response for the create user request (POST /users).

Parameters

user_id (string) – This parameter should be filled with your user_id provided on log_in

user_get_notifications(self, user_id, page_size=None, page_number=None)

End-point for getting notifications for the current logged in user.

The value for the user_id path parameter should match the user_id value returned on the response for the last login request (POST /log_in).

Parameters
  • user_id (string) – This parameter should be filled with your user_id provided on log_in

  • page_size (integer) – Optional parameter to specify the number of results per page

  • page_number (integer) – Optional parameter to specify which page of the results should be retrieved

notification_mark_read(self, user_id, notification_id)

End-point for marking a notification as read.

The value for the user_id path parameter should match the user_id value returned on the response for the last login request (POST /log_in).

The value for the notification_id path parameter should match the notification_id value of the notification to be marked as read.

Parameters
  • user_id (string) – user_id should be filled with your user_id provided on log_in

  • notification_id (string) – notification_id should be filled with the id of the notification to be mark as read

get_notification_preferences(self, user_id)

End-point for getting e-mail subscription mode for the current user.

The value for the user_id path parameter should match the user_id value returned on the response for the last login request (POST /log_in).

Parameters

user_id (string) – This parameter should be filled with your user_id provided on log_in

user_orders_get(self, user_id, market_id=None, is_yes=None, min_price=None, max_price=None, min_place_count=None, max_place_count=None, min_initial_count=None, max_initial_count=None, min_remaining_count=None, max_remaining_count=None, min_date=None, max_date=None)

End-point for getting all orders for the logged in user.

The value for the user_id path parameter should match the user_id value returned on the response for the last login request (POST /log_in).

Parameters
  • user_id (string) – This parameter should be filled with your user_id provided on log_in

  • market_id (string) – Restricts the response to orders in a single market

  • is_yes (boolean) – Restricts the response to orders in a single direction (yes or no)

  • min_price (integer) – Restricts the response to orders within a minimum price

  • max_price (integer) – Restricts the response to orders within a maximum price

  • min_place_count (integer) – Restricts the response to orders within a minimum place count

  • max_place_count (integer) – Restricts the response to orders within a maximum place count

  • min_initial_count (integer) – Restricts the response to orders within a minimum initial count

  • max_initial_count (integer) – Restricts the response to orders within a maximum initial count

  • min_remaining_count (integer) – Restricts the response to orders within a minimum remaining resting contracts count

  • max_remaining_count (integer) – Restricts the response to orders within a maximum remaining resting contracts count

  • min_date (string) – Restricts the response to orders after a timestamp

  • max_date (string) – Restricts the response to orders before a timestamp

user_order_create(self, user_id)

End-point for submitting orders in a market.

The value for the user_id path parameter should match the user_id value returned on the response for the last login request (POST /log_in).

Parameters

user_id (string) – This parameter should be filled with your user_id provided on log_in

user_order_cancel(self, user_id, order_id)

End-point for canceling orders.

The value for the user_id path parameter should match the user_id value returned on the response for the last login request (POST /log_in). The value for the order_id should match the id field of the order you want to decrease. Commonly delete end-points return 204 status with no body content on success. But we can’t completely delete the order, as it may be partially filled already. So what the delete end-point does is just reducing the order completely zeroing the remaining resting contracts on it. The zeroed order is returned on the response payload, as a form of validation for the client.

Parameters
  • user_id (string) – This parameter should be filled with your user_id provided on log_in

  • order_id (string) – This order_id should be filled with the id of the order to be decrease

user_order_decrease(self, user_id, order_id)

End-point for decreasing the number of contracts on orders. This is the only kind of edit we support on orders.

The value for the user_id path parameter should match the user_id value returned on the response for the last login request (POST /log_in).

The value for the order_id should match the id field of the order you want to decrease.

Parameters
  • user_id (string) – This parameter should be filled with your user_id provided on log_in

  • order_id (string) – This order_id should be filled with the id of the order to be decrease

user_change_password(self, user_id)

End-point for updating logged-in user password.

The value for the user_id path parameter should match the user_id value returned on the response for the last login request (POST /log_in).

Parameters

user_id (string) – This parameter should be filled with your user_id provided on log_in

End-point for creating a link token. This is required to be able to connect bank accounts via Plaid.

Look at plaid docs (https://plaid.com/docs/api/tokens/#linktokencreate) for more information on the token and how plaid works.

The value for the user_id path parameter should match the user_id value returned on the response for the last login request (POST /log_in).

Parameters

user_id (string) – This parameter should be filled with your user_id provided on log_in

user_get_portfolio_history(self, user_id)

End-point for getting the logged in user’s portfolio historical track.

The value for the user_id path parameter should match the user_id value returned on the response for the last login request (POST /log_in).

Parameters

user_id (string) – This parameter should be filled with your user_id provided on log_in

user_get_market_positions(self, user_id)

End-point for getting all market positions for the logged in user.

The value for the user_id path parameter should match the user_id value returned on the response for the last login request (POST /log_in).

Parameters

user_id (string) – Should be filled with your user_id provided on log_in

user_get_market_position(self, user_id, market_id)

End-point for getting the market positions for the logged in user, in a specific market.

The value for the user_id path parameter should match the user_id value returned on the response for the last login request (POST /log_in).

The value for the market_id path parameter should match the id value of the target market.

Parameters
  • user_id (string) – Should be filled with your user_id provided on log_in

  • market_id (string) – Should be filled with the id of the target market

change_subscription(self, user_id)

End-point for changing e-mail subscription mode for the current user.

This end-point is very useful for users that have a large volume of orders and don’t want to be email notified whenever an order is submitted / edited / canceled or matches.

This is specially useful for Market Makers.

The value for the user_id path parameter should match the user_id value returned on the response for the last login request (POST /log_in).

Parameters

user_id (string) – Should be filled with your user_id provided on log_in

user_trades_get(self, user_id, market_id=None, order_id=None, MinPrice=None, MaxPrice=None, MinCount=None, max_count=None, min_date=None, max_date=None)

End-point for getting all trades for the logged in user.

The value for the user_id path parameter should match the user_id value returned on the response for the last login request (POST /log_in).

Parameters
  • user_id (string) – This parameter should be filled with your user_id provided on log_in

  • market_id (string) – Restricts the response to trades in a specific market.

  • order_id (string) – Restricts the response to trades related to a specific order.

  • MinPrice (integer) – Restricts the response to trades within a minimum price.

  • MaxPrice (integer) – Restricts the response to trades within a maximum price.

  • MinCount (integer) – Restricts the response to trades within a minimum contracts count.

  • max_count (integer) – Restricts the response to trades within a maximum contracts count.

  • min_date (string) – Restricts the response to trades after a timestamp.

  • max_date (string) – Restricts the response to trades before a timestamp.

user_verify(self, user_id)

End-point for completing email verification during sign-up.

The value for the user_id path parameter should match the user_id value returned on the email verification link query param.

Parameters

user_id (string) – This parameter should be filled with your user_id provided on log_in

user_get_watchlist(self, user_id)

End-point for getting the market watchlist for the logged in user.

The value for the user_id path parameter should match the user_id value returned on the response for the last login request (POST /log_in).

Parameters

user_id (string) – Should be filled with your user_id provided on log_in

user_remove_watchlist(self, user_id, market_id)

End-point for removing a market from the logged in user’s watchlist.

The value for the user_id path parameter should match the user_id value returned on the response for the last login request (POST /log_in).

The value for the market_id path parameter should match the id value of the market to be added.

Parameters
  • user_id (string) – Should be filled with your user_id provided on log_in

  • market_id (string) – Should be filled with the id of the target market

user_add_watchlist(self, user_id, market_id)

End-point for adding a market to the logged in user’s watchlist.

The value for the user_id path parameter should match the user_id value returned on the response for the last login request (POST /log_in).

The value for the market_id path parameter should match the id value of the market to be added.

Parameters
  • user_id (string) – user_id should be filled with your user_id provided on log_in

  • market_id (string) – market_id should be filled with the id of the market to be added to the watchlist

get_user_withdrawals(self, user_id, page_size=None, page_number=None)

End-point for getting all withdrawals for the logged in user.

The value for the user_id path parameter should match the user_id value returned on the response for the last login request (POST /log_in).

Parameters
  • user_id (string) – This parameter should be filled with your user_id provided on log_in

  • page_size (integer) – Number of withdrawals in each page.

  • page_number (integer) – Number of the page to be retrieved.

user_request_withdrawal(self, user_id)

End-point for starting deposits on the logged in user’s account.

The value for the user_id path parameter should match the user_id value returned on the response for the last login request (POST /log_in).

In order to request deposits you need to have connected at least one account using (POST /user/{user_id}/banks/linked_accounts).

Parameters

user_id (string) – This parameter should be filled with your user_id provided on log_in

End-point for sending a link to resume sign-up. To be used in case the user verification e-mail is lost.