Skip to content

Commit 2fed9bd

Browse files
committed
doc: updates doc for #list methods
1 parent da3a56c commit 2fed9bd

File tree

7 files changed

+145
-9
lines changed

7 files changed

+145
-9
lines changed

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
domeapi (0.0.1)
4+
domeapi (0.0.2)
55
dry-cli
66
dry-configurable
77
dry-container
@@ -197,7 +197,7 @@ CHECKSUMS
197197
crack (1.0.1) sha256=ff4a10390cd31d66440b7524eb1841874db86201d5b70032028553130b6d4c7e
198198
declarative (0.0.20) sha256=8021dd6cb17ab2b61233c56903d3f5a259c5cf43c80ff332d447d395b17d9ff9
199199
disposable (0.6.3) sha256=7f2a3fb251bff6cd83f25b164043d4ec3531209b51b066ed476a9df9c2d384cc
200-
domeapi (0.0.1)
200+
domeapi (0.0.2)
201201
dry-cli (1.3.0) sha256=984a715f9d7f8d9bf87b6530acdd4321dcf747636bfeb3ea7fd1b81bc0226e84
202202
dry-configurable (1.3.0) sha256=882d862858567fc1210d2549d4c090f34370fc1bb7c5c1933de3fe792e18afa8
203203
dry-container (0.11.0) sha256=23be9381644d47343f3bf13b082b4255994ada0bfd88e0737eaaadc99d035229

Readme.adoc

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,22 @@ filter = Rubyists::Domeapi::Polymarket::Candlesticks::Filter.new(
8484
interval: 60
8585
)
8686
)
87-
candlesticks = client.polymarket.candlesticks.get(filter)
87+
candlesticks = client.polymarket.candlesticks.list(filter)
88+
----
89+
90+
==== Trade History
91+
92+
Get trade history:
93+
94+
[source,ruby]
95+
----
96+
filter = Rubyists::Domeapi::Polymarket::TradeHistory::Filter.new(
97+
Rubyists::Domeapi::Polymarket::TradeHistory::Filter::Properties.new(
98+
market_slug: 'market_slug',
99+
limit: 10
100+
)
101+
)
102+
trades = client.polymarket.trade_history.list(filter)
88103
----
89104

90105
== Development

lib/domeapi/polymarket/candlesticks.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Filter < Contract
4242
# @param filter [Filter] Filter options
4343
#
4444
# @return [Hash] candlestick data
45-
def get(filter = Filter.new(Filter::Properties.new))
45+
def list(filter = Filter.new(Filter::Properties.new))
4646
raise ArgumentError, filter.errors.full_messages.join(', ') unless filter.valid?
4747

4848
client.get('markets/get_candlesticks', params: filter.to_h)

lib/domeapi/polymarket/client.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ def markets
2323
def candlesticks
2424
@candlesticks ||= Candlesticks.new(client)
2525
end
26+
27+
def trade_history
28+
@trade_history ||= TradeHistory.new(client)
29+
end
2630
end
2731
end
2832
end
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# frozen_string_literal: true
2+
3+
module Rubyists
4+
module Domeapi
5+
module Polymarket
6+
# Trade History API endpoints
7+
class TradeHistory
8+
attr_reader :client
9+
10+
# @param client [Rubyists::Domeapi::Polymarket::Client]
11+
#
12+
# @return [void]
13+
def initialize(client = Rubyists::Domeapi::Polymarket::Client.new)
14+
@client = client
15+
end
16+
17+
# Filter for trade history
18+
class Filter < Contract
19+
Properties = Struct.new(
20+
:market_slug,
21+
:condition_id,
22+
:token_id,
23+
:start_time,
24+
:end_time,
25+
:limit,
26+
:offset,
27+
:user,
28+
keyword_init: true
29+
)
30+
31+
Properties.members.each { |member| property member, populator: ->(model:, **) { model || skip! } }
32+
33+
validation do
34+
params do
35+
optional(:market_slug).maybe(:string)
36+
optional(:condition_id).maybe(:string)
37+
optional(:token_id).maybe(:string)
38+
optional(:start_time).maybe(:integer)
39+
optional(:end_time).maybe(:integer)
40+
optional(:limit).maybe(:integer, gteq?: 1, lteq?: 1000)
41+
optional(:offset).maybe(:integer, gteq?: 0)
42+
optional(:user).maybe(:string)
43+
end
44+
end
45+
end
46+
47+
# Get trade history
48+
#
49+
# @param filter [Filter] Filter options
50+
#
51+
# @return [Hash] trade history data
52+
def list(filter = Filter.new(Filter::Properties.new))
53+
raise ArgumentError, filter.errors.full_messages.join(', ') unless filter.validate({})
54+
55+
client.get('markets/get_trade_history', params: filter.to_h)
56+
end
57+
end
58+
end
59+
end
60+
end

test/domeapi/polymarket/candlesticks_test.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
interval: 60
2727
)
2828
)
29-
response = candlesticks.get(filter)
29+
response = candlesticks.list(filter)
3030

3131
_(response).must_equal({ candlesticks: [] })
3232
end
@@ -43,7 +43,7 @@
4343
end_time: 200
4444
)
4545
)
46-
response = candlesticks.get(filter)
46+
response = candlesticks.list(filter)
4747

4848
_(response).must_equal({ candlesticks: [] })
4949
end
@@ -53,7 +53,7 @@
5353
Rubyists::Domeapi::Polymarket::Candlesticks::Filter::Properties.new
5454
)
5555

56-
error = _ { candlesticks.get(filter) }.must_raise ArgumentError
56+
error = _ { candlesticks.list(filter) }.must_raise ArgumentError
5757
_(error.message).must_include 'Condition Id must be filled'
5858
_(error.message).must_include 'Start Time must be filled'
5959
_(error.message).must_include 'End Time must be filled'
@@ -69,7 +69,7 @@
6969
)
7070
)
7171

72-
error = _ { candlesticks.get(filter) }.must_raise ArgumentError
72+
error = _ { candlesticks.list(filter) }.must_raise ArgumentError
7373
_(error.message).must_include 'Interval must be less than or equal to 1440'
7474

7575
filter = Rubyists::Domeapi::Polymarket::Candlesticks::Filter.new(
@@ -81,7 +81,7 @@
8181
)
8282
)
8383

84-
error = _ { candlesticks.get(filter) }.must_raise ArgumentError
84+
error = _ { candlesticks.list(filter) }.must_raise ArgumentError
8585
_(error.message).must_include 'Interval must be greater than or equal to 1'
8686
end
8787
end
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../../helper'
4+
5+
describe Rubyists::Domeapi::Client do
6+
let(:client) { Rubyists::Domeapi::Client.new }
7+
let(:trade_history) { client.polymarket.trade_history }
8+
9+
before do
10+
Rubyists::Domeapi.configure do |config|
11+
config.api_key = 'test_api_key'
12+
end
13+
end
14+
15+
describe 'Polymarket Trade History' do
16+
it 'gets trade history' do
17+
stub_request(:get, 'https://api.domeapi.io/v1/polymarket/markets/get_trade_history')
18+
.with(query: { market_slug: 'slug', limit: '10' })
19+
.to_return(status: 200, body: '{"trades": []}')
20+
21+
filter = Rubyists::Domeapi::Polymarket::TradeHistory::Filter.new(
22+
Rubyists::Domeapi::Polymarket::TradeHistory::Filter::Properties.new(
23+
market_slug: 'slug',
24+
limit: 10
25+
)
26+
)
27+
response = trade_history.list(filter)
28+
29+
_(response).must_equal({ trades: [] })
30+
end
31+
32+
it 'validates limit range' do
33+
filter = Rubyists::Domeapi::Polymarket::TradeHistory::Filter.new(
34+
Rubyists::Domeapi::Polymarket::TradeHistory::Filter::Properties.new(limit: 1001)
35+
)
36+
37+
error = _ { trade_history.list(filter) }.must_raise ArgumentError
38+
_(error.message).must_include 'Limit must be less than or equal to 1000'
39+
40+
filter = Rubyists::Domeapi::Polymarket::TradeHistory::Filter.new(
41+
Rubyists::Domeapi::Polymarket::TradeHistory::Filter::Properties.new(limit: 0)
42+
)
43+
44+
error = _ { trade_history.list(filter) }.must_raise ArgumentError
45+
_(error.message).must_include 'Limit must be greater than or equal to 1'
46+
end
47+
48+
it 'validates offset range' do
49+
filter = Rubyists::Domeapi::Polymarket::TradeHistory::Filter.new(
50+
Rubyists::Domeapi::Polymarket::TradeHistory::Filter::Properties.new(offset: -1)
51+
)
52+
53+
error = _ { trade_history.list(filter) }.must_raise ArgumentError
54+
_(error.message).must_include 'Offset must be greater than or equal to 0'
55+
end
56+
end
57+
end

0 commit comments

Comments
 (0)