ftx-api 0.2.3 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 720fabc9ebb722b1831297bd96d66576c65e6b5b8dcd94214e23ba24017e4d02
4
- data.tar.gz: 8fe4038ce8e62028216d0b594e5a45e26684642a33682bec42358589ad31b706
3
+ metadata.gz: be471f1211cee30497ce74db4b05da88d05345bc8ada1966d26495db15f18890
4
+ data.tar.gz: e7ee23d92d2cf4782b2fcdbdf2c09232460ccafaeb0de6b09bf686bdb3cf4e55
5
5
  SHA512:
6
- metadata.gz: a538f6f23ca72be51f7a0c833ba757f939c66d32089badcc69f4c9e2fbd03f4725e799a7e07b0419c1af13c2c1d7d296024f349b59d2ea78647463dfe199c406
7
- data.tar.gz: 9ad931c775665f6084ed7f37fc2377fe49d38edd17f5872142d1b2a95b8e7a7b3f57212c78866c5563e496260814c3a0fc039674d6eb51b6b04c7ab30b55b3ad
6
+ metadata.gz: 552a6ed552f1b7ac7fa6063feb2698dd06d6693f38b20cee6fb07cf9bd6eb9b45ac8b3a7db2b1c5210c9dbc5eda695e638508785dce980045f8eadd57d337f68
7
+ data.tar.gz: 4c4f43ce73556ef89af1139f665ba24cb39d83837db32e4461054d8fef9aba8bfa2c6a0801827e92c3dba303814d5aab359443dd37e22df18acccf20b8adb8c4
data/CHANGELOG.md CHANGED
@@ -4,4 +4,25 @@
4
4
  - Initial release
5
5
 
6
6
  ## [0.2.0] - 2021-09-23
7
- - Implement public API covering Markets and Futures only
7
+ - Implement public API covering Markets and Futures only
8
+
9
+ ## [0.2.1] - 2021-09-23
10
+ - Empty
11
+
12
+ ## [0.2.2] - 2021-10-05
13
+ - Include private API endpoints with tests
14
+
15
+ ## [0.2.3] - 2021-10-05
16
+ - Include private API endpoints with tests - further updates
17
+
18
+ ## [0.2.4] - 2021-10-05
19
+ - Fix error compact_blank creates for rails db:migrate
20
+
21
+ ## [0.2.5] - 2021-10-06
22
+ - Fix issues with post methods and add Convert endpoint
23
+
24
+ ## [0.2.6] - 2021-10-06
25
+ - Implement Fills endpoint including tests
26
+
27
+ ## [0.2.7] - 2021-10-06
28
+ - Implement orders get_by_client_id endpoint
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ftx-api (0.2.3)
4
+ ftx-api (0.2.7)
5
5
  httparty (~> 0.19)
6
6
  openssl (~> 2.2)
7
7
 
data/README.md CHANGED
@@ -4,8 +4,6 @@ This gem is a ruby SDK for the FTX crypto exchange REST API.
4
4
 
5
5
  API docs can be found on the [FTX developer site](https://docs.ftx.com/)
6
6
 
7
- It is still under development and currently only covers the markets and futures endpoints.
8
-
9
7
 
10
8
  ## Installation
11
9
 
@@ -128,9 +126,14 @@ Query for all historical orders:
128
126
  orders.history
129
127
  ```
130
128
 
131
- Fetch a specific order:
129
+ Fetch a specific order by FTX `orderId`:
132
130
  ```ruby
133
- orders.get
131
+ orders.get(order_id)
132
+ ```
133
+
134
+ Fetch a specific order by `clientId`:
135
+ ```ruby
136
+ orders.get_by_client_id(clientId)
134
137
  ```
135
138
 
136
139
  Create a new order:
@@ -154,9 +157,65 @@ Note: the create order method is not included as a test, because I have not been
154
157
 
155
158
  *Check the [FTX API docs](https://docs.ftx.com/#orders) for all parameters*
156
159
 
160
+ ### Fills
161
+
162
+ Initialize an fills session:
163
+ ```ruby
164
+ fills = FXT::API::Orders.new(key: 'YOUR FTX KEY', secret: 'YOUR FTX SECRET')
165
+ ```
166
+
167
+ Query for all fills:
168
+ ```ruby
169
+ fills.list
170
+ ```
171
+ or
172
+
173
+ ```ruby
174
+ fills.list(market: 'BTC/USD')
175
+ ```
176
+
177
+ Note: market is optional
178
+
179
+ ### Convert Coins
180
+
181
+ Initialize an convert session:
182
+ ```ruby
183
+ convert = FXT::API::Convert.new(key: 'YOUR FTX KEY', secret: 'YOUR FTX SECRET')
184
+ ```
185
+
186
+ Create a new quote:
187
+ ```ruby
188
+ args = {
189
+ size: 0.01, # 0.01 is the smallest increment
190
+ fromCoin: "USD",
191
+ toCoin: "BTC",
192
+ }
193
+
194
+ convert.new_quote(args)
195
+ ```
196
+
197
+ Response:
198
+ ```ruby
199
+ {:quoteId=>2*******3}
200
+ ```
201
+
202
+ Fetch a quote:
203
+ ```ruby
204
+ convert.get_quote('quoteId')
205
+ ```
206
+
207
+ Accept a quote:
208
+ ```ruby
209
+ convert.accept_quote('quoteId')
210
+ ```
211
+
157
212
  ## Development
158
213
 
159
- After checking out the repo, run `bin/setup` to install dependencies. You'll need to add environment variables ENV['FTX_KEY'] and ENV['FTX_SECRET']. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
214
+ After checking out the repo, run `bin/setup` to install dependencies.
215
+
216
+ You'll then need to add environment variables `ENV['FTX_KEY']` and `ENV['FTX_SECRET']`. API keys can be created in your [FTX settings page](https://ftx.com/profile).
217
+
218
+ Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
160
219
 
161
220
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
162
221
 
data/lib/ext/array.rb CHANGED
@@ -4,7 +4,7 @@ class Array
4
4
  map(&:symbolize_keys)
5
5
  end
6
6
 
7
- def compact_blank
7
+ def compact_empty
8
8
  delete_if {|i| i.respond_to?(:empty?) ? !!i.empty? : !i }
9
9
  end
10
10
 
data/lib/ftx/api/base.rb CHANGED
@@ -4,11 +4,11 @@ require 'httparty'
4
4
 
5
5
  class FTX::API::Base
6
6
 
7
+ attr_reader :config, :key, :secret
8
+
7
9
  include HTTParty
8
10
  base_uri 'https://ftx.com/api'
9
11
 
10
- attr_reader :config, :key, :secret
11
-
12
12
  def initialize(args = {})
13
13
  @config = FTX::API::Config.new(args.dig(:config))
14
14
  @key = args.dig(:key)
@@ -21,16 +21,21 @@ class FTX::API::Base
21
21
  uuid = SecureRandom.uuid
22
22
  print_log(:info, "[API] #{uuid} #{method.upcase} '#{path}' query = #{query}")
23
23
 
24
- body_or_query = method == :get ? :query : :body
24
+ if method == :get
25
+ body_or_query = :query
26
+ else
27
+ body_or_query = :body
28
+ query = query.to_json
29
+ end
25
30
 
26
31
  begin
27
32
  response = self.class.send(
28
- method,
29
- path,
33
+ method,
34
+ path,
30
35
  headers: headers,
31
36
  timeout: @config.timeout,
32
- body_or_query => query,
33
- ).parsed_response
37
+ body_or_query.to_sym => query
38
+ )
34
39
 
35
40
  print_log(:info, "[API] #{uuid} response #{response}")
36
41
  return parse_response(response)
@@ -43,6 +48,7 @@ class FTX::API::Base
43
48
  private
44
49
 
45
50
  def parse_response(response)
51
+ response = response.parsed_response
46
52
  if response.dig("success")
47
53
  response.dig("result").symbolize_keys
48
54
  else
@@ -54,7 +60,6 @@ class FTX::API::Base
54
60
  logger = @config.logger
55
61
  if logger
56
62
  puts "#{method}: #{message}"
57
- # logger[method] = message
58
63
  end
59
64
  end
60
65
 
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'private'
4
+
5
+ class FTX::API::Convert < FTX::API::Private
6
+
7
+ def new_quote(query = {})
8
+ raise ArgumentError.new(
9
+ "Size, fromCoin, toCoin params required"
10
+ ) unless [:fromCoin, :toCoin, :size].all? { |i| query.include? i }
11
+
12
+ send_request(:post, "/otc/quotes", query)
13
+ end
14
+
15
+ def get_quote(quote_id)
16
+ send_request(:get, "/otc/quotes/#{quote_id}", {})
17
+ end
18
+
19
+ def accept_quote(quote_id)
20
+ send_request(:post, "/otc/quotes/#{quote_id}/accept", {})
21
+ end
22
+
23
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'private'
4
+
5
+ class FTX::API::Fills < FTX::API::Private
6
+
7
+ def list(query = {})
8
+ send_request(:get, "/fills", query)
9
+ end
10
+
11
+ end
@@ -16,6 +16,10 @@ class FTX::API::Orders < FTX::API::Private
16
16
  send_request(:get, "/orders/#{order_id}", {})
17
17
  end
18
18
 
19
+ def get_by_client_id(client_id)
20
+ send_request(:get, "/orders/by_client_id/#{client_id}", {})
21
+ end
22
+
19
23
  def create(query = {})
20
24
  raise ArgumentError.new(
21
25
  "Market, side, price (can be nil), tupe and size params required"
@@ -15,6 +15,8 @@ class FTX::API::Private < FTX::API::Base
15
15
  'FTX-KEY' => key,
16
16
  'FTX-SIGN' => signature(*args),
17
17
  'FTX-TS' => ts.to_s,
18
+ 'Content-Type' => 'application/json',
19
+ 'Accepts' => 'application/json',
18
20
  }
19
21
  end
20
22
 
@@ -23,15 +25,15 @@ class FTX::API::Private < FTX::API::Base
23
25
  end
24
26
 
25
27
  def signature_payload(method, path, query)
26
- payload = [ts, method.to_s.upcase, "/api", path].compact_blank
28
+ payload = [ts, method.to_s.upcase, "/api", path].compact_empty
27
29
 
28
30
  if method==:post
29
- payload.push(query.to_json)
31
+ payload << query.to_json
30
32
  elsif method==:get
31
- payload.push("?" + URI.encode_www_form(query))
33
+ payload << ("?" + URI.encode_www_form(query))
32
34
  end unless query.empty?
33
35
 
34
- "#{payload.join}".encode("UTF-8")
36
+ payload.join.encode("UTF-8")
35
37
  end
36
38
 
37
39
  def ts
@@ -2,6 +2,6 @@
2
2
 
3
3
  module FTX
4
4
  module API
5
- VERSION = "0.2.3"
5
+ VERSION = "0.2.7"
6
6
  end
7
7
  end
data/lib/ftx/api.rb CHANGED
@@ -3,7 +3,9 @@ require_relative "../ext/base"
3
3
  require_relative "api/version"
4
4
  require_relative "api/config"
5
5
  require_relative "api/markets"
6
+ require_relative "api/futures"
6
7
  require_relative "api/account"
7
8
  require_relative "api/wallet"
8
9
  require_relative "api/orders"
9
- require_relative "api/futures"
10
+ require_relative "api/fills"
11
+ require_relative "api/convert"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ftx-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - benrs44
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-05 00:00:00.000000000 Z
11
+ date: 2021-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -63,6 +63,8 @@ files:
63
63
  - lib/ftx/api/account.rb
64
64
  - lib/ftx/api/base.rb
65
65
  - lib/ftx/api/config.rb
66
+ - lib/ftx/api/convert.rb
67
+ - lib/ftx/api/fills.rb
66
68
  - lib/ftx/api/futures.rb
67
69
  - lib/ftx/api/markets.rb
68
70
  - lib/ftx/api/orders.rb