ftx-api 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 798edaba47ec4e363488fe462aafc23a07600270944492e0df2de61bb3a0df39
4
- data.tar.gz: 76bf0b23ced4ce5dd444d83dba36a8703481b859f16f05501c52750ec9928522
3
+ metadata.gz: 58c15096ba4fb95095c38eb810ce23e70066ae3e462cd96d25b4793be3ed0457
4
+ data.tar.gz: 44f47071c91cb4d76a3bf075ae3c4b9e3ad656833936ad7b4cb8e3671908bb33
5
5
  SHA512:
6
- metadata.gz: f7ca004638de0447346204c8be75d8368c1d7208c70bcdaf02b35127e7d863c477abb03deb2a1b04c853ac28c7d229ba6a681a66afd9b978364134525379d254
7
- data.tar.gz: 94fa7cc56036cd1911d2a7faa93043359749e46c6be75975128dbc3342fcce4225babebcf98d5ba3260361bd499f2dd51e9c17c780edfe850c35ae74e6f000dd
6
+ metadata.gz: 687383de76c7e9b00e8cc385cc73a32537d45392253881a56b00d70336021e356cd87a6a3804357a18a1933c6be2a9b69fed2969f6817558a7acf0adbffdede3
7
+ data.tar.gz: 25a2ea5c354a87a36074759790b3b28af98aae58f3c9109e7bf7489acaebaa969d3e26c4a49005e18788dc246175340a4b532b8666b1e6b12a761c7106810d87
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ftx-api (0.2.4)
4
+ ftx-api (0.2.5)
5
5
  httparty (~> 0.19)
6
6
  openssl (~> 2.2)
7
7
 
data/README.md CHANGED
@@ -154,6 +154,39 @@ Note: the create order method is not included as a test, because I have not been
154
154
 
155
155
  *Check the [FTX API docs](https://docs.ftx.com/#orders) for all parameters*
156
156
 
157
+ ### Convert Coins
158
+
159
+ Initialize an convert session:
160
+ ```ruby
161
+ convert = FXT::API::Convert.new(key: 'YOUR FTX KEY', secret: 'YOUR FTX SECRET')
162
+ ```
163
+
164
+ Create a new quote:
165
+ ```ruby
166
+ args = {
167
+ size: 0.01, # 0.01 is the smallest increment
168
+ fromCoin: "USD",
169
+ toCoin: "BTC",
170
+ }
171
+
172
+ convert.new_quote(args)
173
+ ```
174
+
175
+ Response:
176
+ ```ruby
177
+ {:quoteId=>2*******3}
178
+ ```
179
+
180
+ Fetch a quote:
181
+ ```ruby
182
+ convert.get_quote('quoteId')
183
+ ```
184
+
185
+ Accept a quote:
186
+ ```ruby
187
+ convert.accept_quote('quoteId')
188
+ ```
189
+
157
190
  ## Development
158
191
 
159
192
  After checking out the repo, run `bin/setup` to install dependencies.
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
@@ -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
 
@@ -26,12 +28,12 @@ class FTX::API::Private < FTX::API::Base
26
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.4"
5
+ VERSION = "0.2.5"
6
6
  end
7
7
  end
data/lib/ftx/api.rb CHANGED
@@ -6,4 +6,5 @@ require_relative "api/markets"
6
6
  require_relative "api/account"
7
7
  require_relative "api/wallet"
8
8
  require_relative "api/orders"
9
- require_relative "api/futures"
9
+ require_relative "api/futures"
10
+ 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.4
4
+ version: 0.2.5
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,7 @@ 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
66
67
  - lib/ftx/api/futures.rb
67
68
  - lib/ftx/api/markets.rb
68
69
  - lib/ftx/api/orders.rb