Skip to content

Commit d6deb3e

Browse files
authored
feat: adds the rest of the polymarket endpoints (#2)
* feat: adds Orderbook endpoint * refactor: added Listable module to dry up the #list methods * feat: adds the rest of the polymarket endpoints * test: gets everything to 100% branch coverage * ci: updates workflow to include simplecov check * test: corrected Endpoint spec to ensure Polymarket::Client is used * ci: moves simplecov into validations * ci: makes coverage.yaml its own job * ci: trying to get coverage right * ci: corrects coverage conditional * ci: uses hashFiles to check file existence * ci: adds tmate action to debug coverage problems * ci: puts coverage files in the correct directory * ci: include-hidden-files to get the .last_run.json to upload/download * ci: removes tmate debugging step
1 parent e1e6c67 commit d6deb3e

36 files changed

+835
-102
lines changed

.github/workflows/coverage.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Test Coverage
2+
3+
on:
4+
workflow_call:
5+
6+
workflow_dispatch:
7+
8+
jobs:
9+
SimpleCov:
10+
runs-on: ubuntu-latest
11+
steps:
12+
# Only download these artifacts if they don't already exist
13+
- if: ${{ hashFiles('coverage/.last_run.json') == '' }}
14+
uses: actions/download-artifact@v4
15+
with:
16+
name: coverage-last-run
17+
path: coverage/
18+
19+
- name: Check SimpleCov coverage
20+
uses: joshmfrankel/simplecov-check-action@main
21+
with:
22+
minimum_suite_coverage: 97
23+
minimum_file_coverage: 90
24+
github_token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/main.yaml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,25 @@ jobs:
1515
- '4.0.0'
1616
steps:
1717
- uses: actions/checkout@v4
18+
name: Checkout code
19+
1820
- name: Set up Ruby
1921
uses: ruby/setup-ruby@v1
2022
with:
2123
ruby-version: ${{ matrix.ruby }}
22-
bundler-cache: false
24+
bundler-cache: true
25+
2326
- name: Install dependencies
2427
run: bundle install --jobs 4 --retry 3
25-
- name: Run the default task
28+
29+
- name: Run the default rake task
2630
run: bundle exec rake
31+
env:
32+
COVERAGE: "true"
33+
34+
- name: Upload coverage
35+
uses: actions/upload-artifact@v4
36+
with:
37+
name: coverage-last-run
38+
path: coverage/
39+
include-hidden-files: true

.github/workflows/validations.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@ jobs:
1010
validate_ruby:
1111
name: Ruby Tests
1212
uses: ./.github/workflows/main.yaml
13+
14+
ensure_coverage:
15+
needs: validate_ruby
16+
name: Check SimpleCov coverage
17+
uses: ./.github/workflows/coverage.yaml

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ gem 'rubocop'
1313
gem 'rubocop-minitest'
1414
gem 'rubocop-performance'
1515
gem 'rubocop-rake'
16+
gem 'shoulda-context'
17+
gem 'simplecov'
18+
gem 'simplecov-json'

Gemfile.lock

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ GEM
2929
disposable (0.6.3)
3030
declarative (>= 0.0.9, < 1.0.0)
3131
representable (>= 3.1.1, < 4)
32+
docile (1.4.1)
3233
dry-cli (1.3.0)
3334
dry-configurable (1.3.0)
3435
dry-core (~> 1.1)
@@ -135,6 +136,16 @@ GEM
135136
ruby-progressbar (1.13.0)
136137
semantic_logger (4.17.0)
137138
concurrent-ruby (~> 1.0)
139+
shoulda-context (2.0.0)
140+
simplecov (0.22.0)
141+
docile (~> 1.1)
142+
simplecov-html (~> 0.11)
143+
simplecov_json_formatter (~> 0.1)
144+
simplecov-html (0.13.2)
145+
simplecov-json (0.2.3)
146+
json
147+
simplecov
148+
simplecov_json_formatter (0.1.4)
138149
trailblazer (2.1.3)
139150
trailblazer-activity-dsl-linear (>= 1.2.3, < 1.3.0)
140151
trailblazer-developer (>= 0.1.0, < 0.2.0)
@@ -187,6 +198,9 @@ DEPENDENCIES
187198
rubocop-minitest
188199
rubocop-performance
189200
rubocop-rake
201+
shoulda-context
202+
simplecov
203+
simplecov-json
190204

191205
CHECKSUMS
192206
addressable (2.8.8) sha256=7c13b8f9536cf6364c03b9d417c19986019e28f7c00ac8132da4eb0fe393b057
@@ -197,6 +211,7 @@ CHECKSUMS
197211
crack (1.0.1) sha256=ff4a10390cd31d66440b7524eb1841874db86201d5b70032028553130b6d4c7e
198212
declarative (0.0.20) sha256=8021dd6cb17ab2b61233c56903d3f5a259c5cf43c80ff332d447d395b17d9ff9
199213
disposable (0.6.3) sha256=7f2a3fb251bff6cd83f25b164043d4ec3531209b51b066ed476a9df9c2d384cc
214+
docile (1.4.1) sha256=96159be799bfa73cdb721b840e9802126e4e03dfc26863db73647204c727f21e
200215
domeapi (0.0.2)
201216
dry-cli (1.3.0) sha256=984a715f9d7f8d9bf87b6530acdd4321dcf747636bfeb3ea7fd1b81bc0226e84
202217
dry-configurable (1.3.0) sha256=882d862858567fc1210d2549d4c090f34370fc1bb7c5c1933de3fe792e18afa8
@@ -241,6 +256,11 @@ CHECKSUMS
241256
rubocop-rake (0.7.1) sha256=3797f2b6810c3e9df7376c26d5f44f3475eda59eb1adc38e6f62ecf027cbae4d
242257
ruby-progressbar (1.13.0) sha256=80fc9c47a9b640d6834e0dc7b3c94c9df37f08cb072b7761e4a71e22cff29b33
243258
semantic_logger (4.17.0) sha256=c54b60d8596abe2e22bd4f20648d4f6c46e4287fba357779c7932335c8d130e9
259+
shoulda-context (2.0.0) sha256=7adf45342cd800f507d2a053658cb1cce2884b616b26004d39684b912ea32c34
260+
simplecov (0.22.0) sha256=fe2622c7834ff23b98066bb0a854284b2729a569ac659f82621fc22ef36213a5
261+
simplecov-html (0.13.2) sha256=bd0b8e54e7c2d7685927e8d6286466359b6f16b18cb0df47b508e8d73c777246
262+
simplecov-json (0.2.3) sha256=c63823b5dfc95c85ff4cb94251765f08a166bdd68098f259368cbfe738e281f7
263+
simplecov_json_formatter (0.1.4) sha256=529418fbe8de1713ac2b2d612aa3daa56d316975d307244399fa4838c601b428
244264
trailblazer (2.1.3) sha256=8adf157f552a4843de51456f7e70e28422799e5d060b265814d145774b8845b7
245265
trailblazer-activity (0.17.0) sha256=2166bc8b3410b808ad2bfe00efaf559533d1b9a6fb0d704cf3bdad02cd6c0b88
246266
trailblazer-activity-dsl-linear (1.2.6) sha256=42e4d3c9bd9469b65f9265fba74c703cf1a4117ea7f42a0a78112ebb3bab986f

Rakefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
# frozen_string_literal: true
22

33
require 'bundler/gem_tasks'
4-
require 'minitest/test_task'
4+
require 'rake/testtask'
55

6-
Minitest::TestTask.create
6+
Rake::TestTask.new do |t|
7+
t.libs << 'test'
8+
t.test_files = FileList['test/**/*_test.rb']
9+
t.ruby_opts = %w[-rhelper]
10+
end
711

812
require 'rubocop/rake_task'
913

Readme.adoc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,22 @@ filter = Rubyists::Domeapi::Polymarket::TradeHistory::Filter.new(
102102
trades = client.polymarket.trade_history.list(filter)
103103
----
104104

105+
==== Orderbook
106+
107+
Get orderbook history:
108+
109+
[source,ruby]
110+
----
111+
filter = Rubyists::Domeapi::Polymarket::Orderbook::Filter.new(
112+
Rubyists::Domeapi::Polymarket::Orderbook::Filter::Properties.new(
113+
token_id: 'token_id',
114+
start_time: 1625097600000,
115+
end_time: 1625184000000
116+
)
117+
)
118+
snapshots = client.polymarket.orderbook.list(filter)
119+
----
120+
105121
== Development
106122

107123
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.

lib/domeapi/client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def get(path, params: {})
2525
end
2626

2727
def polymarket
28-
@polymarket ||= Polymarket::Client.new(self)
28+
@polymarket ||= Polymarket::Client.new(clone)
2929
end
3030

3131
private

lib/domeapi/contract.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@ module Domeapi
99
class Contract < Reform::Form
1010
feature Reform::Form::Dry
1111

12+
# Custom class methods can be defined here
13+
module ClassMethods
14+
def propertize(*names)
15+
# names is always an array because of the splat
16+
names = names.flatten
17+
const_set(:Properties, Struct.new(*custom_definitions, *names, keyword_init: true))
18+
names.each { |name| property name, populator: ->(value:, **) { value || skip! } }
19+
end
20+
end
21+
22+
def self.inherited(subclass)
23+
subclass.extend ClassMethods
24+
super
25+
end
26+
1227
def self.custom_definitions = instance_variable_get(:@definitions)&.keys&.map(&:to_sym) || []
1328

1429
def to_h

lib/domeapi/polymarket.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,14 @@ module Polymarket
77
end
88
end
99
end
10+
11+
require_relative 'polymarket/endpoint'
12+
require_relative 'polymarket/listable'
13+
require_relative 'polymarket/markets'
14+
require_relative 'polymarket/candlesticks'
15+
require_relative 'polymarket/trade_history'
16+
require_relative 'polymarket/orderbook'
17+
require_relative 'polymarket/activity'
18+
require_relative 'polymarket/market_price'
19+
require_relative 'polymarket/wallet'
20+
require_relative 'polymarket/wallet_profit_and_loss'

0 commit comments

Comments
 (0)