-
Notifications
You must be signed in to change notification settings - Fork 0
feat: adds all market/ endpoints #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
bougyman
commented
Jan 5, 2026
- doc: updated Readme with a more real-world filter use case
- feat: adds all market/ endpoints
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements comprehensive support for all Kalshi market endpoints, providing a complete interface for market data operations through a new Market::Client wrapper.
- Adds Market::Client wrapper to organize market-related endpoints
- Implements four new market endpoints: Markets, Orderbook, Trades, and Candlesticks
- Updates README with practical usage examples replacing previous placeholder documentation
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| lib/kalshi/client.rb | Adds memoized market accessor method returning Market::Client |
| lib/kalshi/market/client.rb | New Market::Client wrapper providing memoized access to all market endpoints |
| lib/kalshi/market/markets.rb | Implements Markets endpoint with list and fetch methods, includes Filter contract |
| lib/kalshi/market/orderbook.rb | Implements Orderbook endpoint with optional depth parameter |
| lib/kalshi/market/trades.rb | Implements Trades endpoint with list method and Filter contract |
| lib/kalshi/market/candlesticks.rb | Implements Candlesticks endpoint with fetch and batch methods |
| test/kalshi/client_test.rb | Adds test verifying market method returns correct instance |
| test/kalshi/market/client_test.rb | Comprehensive tests for all Market::Client accessor methods with memoization verification |
| test/kalshi/market/markets_test.rb | Tests for Markets list and fetch methods with filters |
| test/kalshi/market/orderbook_test.rb | Tests for Orderbook fetch with and without depth parameter |
| test/kalshi/market/trades_test.rb | Tests for Trades list method with filters |
| test/kalshi/market/candlesticks_test.rb | Tests for Candlesticks fetch and batch methods, including array and string ticker handling |
| Readme.adoc | Updates documentation from placeholder to working examples using client.market namespace |
| describe '#list' do | ||
| it 'fetches the markets list' do | ||
| stub_request(:get, "#{base_url}/markets") | ||
| .to_return(status: 200, body: '{"markets": []}', headers: { 'Content-Type' => 'application/json' }) | ||
|
|
||
| response = markets.list | ||
|
|
||
| assert_equal({ markets: [] }, response) | ||
| end | ||
|
|
||
| it 'fetches the markets list with filters' do | ||
| stub_request(:get, "#{base_url}/markets") | ||
| .with(query: { status: 'open' }) | ||
| .to_return(status: 200, body: '{"markets": []}', headers: { 'Content-Type' => 'application/json' }) | ||
|
|
||
| response = markets.list(status: 'open') | ||
|
|
||
| assert_equal({ markets: [] }, response) | ||
| end |
Copilot
AI
Jan 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding validation tests for the Filter contract. Other similar endpoints like SeriesList include tests for invalid parameters and invalid values to ensure the contract validation is working correctly. This would improve test coverage for error cases.
| describe '#list' do | ||
| it 'fetches the trades list' do | ||
| stub_request(:get, "#{base_url}/markets/trades") | ||
| .to_return(status: 200, body: '{"trades": []}', headers: { 'Content-Type' => 'application/json' }) | ||
|
|
||
| response = trades.list | ||
|
|
||
| assert_equal({ trades: [] }, response) | ||
| end | ||
|
|
||
| it 'fetches the trades list with filters' do | ||
| stub_request(:get, "#{base_url}/markets/trades") | ||
| .with(query: { ticker: 'KX-MARKET' }) | ||
| .to_return(status: 200, body: '{"trades": []}', headers: { 'Content-Type' => 'application/json' }) | ||
|
|
||
| response = trades.list(ticker: 'KX-MARKET') | ||
|
|
||
| assert_equal({ trades: [] }, response) | ||
| end |
Copilot
AI
Jan 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding validation tests for the Filter contract. Other similar endpoints like SeriesList include tests for invalid parameters and invalid values to ensure the contract validation is working correctly. This would improve test coverage for error cases.
| describe '#market' do | ||
| it 'returns a Market::Client instance' do | ||
| client = Rubyists::Kalshi::Client.new | ||
|
|
||
| assert_instance_of Rubyists::Kalshi::Market::Client, client.market | ||
| end | ||
| end |
Copilot
AI
Jan 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a test to verify that the market method is memoized, similar to the memoization tests for series_list, series, markets, orderbook, trades, and candlesticks in the Market::Client tests. This ensures consistent caching behavior.
| describe '#fetch' do | ||
| it 'fetches a specific market by ticker' do | ||
| ticker = 'KX-MARKET' | ||
| stub_request(:get, "#{base_url}/markets/#{ticker}") | ||
| .to_return(status: 200, body: '{"market": {}}', headers: { 'Content-Type' => 'application/json' }) | ||
|
|
||
| response = markets.fetch(ticker) | ||
|
|
||
| assert_equal({ market: {} }, response) | ||
| end | ||
| end |
Copilot
AI
Jan 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a test for the class-level list method (Markets.list), similar to the test in SeriesList. The Listable module provides this functionality, and it should be tested for consistency.
| it 'fetches the trades list with filters' do | ||
| stub_request(:get, "#{base_url}/markets/trades") | ||
| .with(query: { ticker: 'KX-MARKET' }) | ||
| .to_return(status: 200, body: '{"trades": []}', headers: { 'Content-Type' => 'application/json' }) | ||
|
|
||
| response = trades.list(ticker: 'KX-MARKET') | ||
|
|
||
| assert_equal({ trades: [] }, response) | ||
| end | ||
| end |
Copilot
AI
Jan 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a test for the class-level list method (Trades.list), similar to the test in SeriesList. The Listable module provides this functionality, and it should be tested for consistency.