okex 0.1.20 → 0.2.0

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: 75fda5af2580d3fa8aa86fef858ce7ab31872d73a7b2819e9ab8f6e0991760ac
4
- data.tar.gz: 924019880495be349930339802e0dc7c8e2a6876f16653ae605ead7c63389c8e
3
+ metadata.gz: dae1478814bf6ccebb68aaf3bd52c3ac834148cb90b4b8e8f6427ccc811304eb
4
+ data.tar.gz: 53bc2e5e42b90f1f60390273a82f98fa4caf19c07d238f38edac4bbf7a51a572
5
5
  SHA512:
6
- metadata.gz: 174b2e94fb591fd9bf89a2c0c08b19f8932c414c6be66488010320bacf751438310feac5bf3fe005e4a12287474a3a8b4c2465840b6aa40c6cd8cb4eae34883e
7
- data.tar.gz: cbc2d4163fd749e194325afbf8cc1e9386cef004b50e19a3ab1d90fe31c96a97f0c80928f7d833342826f0c8db4bdc6f8096d7d5f1b84757e88a965a1cece606
6
+ metadata.gz: 0afed6eb2d1e37d817e8f172d3713a1aec653a3eb70cab406523e5e7fc21aae803f0a64d16e11fa73440d34507c37303d2f33c7669ecc5218657546f322ce295
7
+ data.tar.gz: 6bb22c3ce7cc7b3a739a975d7a7b3239edb5d2e5edb9bc5ea056229ca238ab806c25fc9c8703bedc8e969d28cea42c8119733ac603d11db359fcbad13e418594
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- okex (0.1.20)
4
+ okex (0.1.21)
5
5
  faraday (~> 1.5)
6
6
 
7
7
  GEM
data/lib/okex.rb CHANGED
@@ -1,12 +1,11 @@
1
1
  require "okex/version"
2
- require "okex/api"
2
+ require "okex/api_v3"
3
+ require "okex/api_v5"
3
4
  require "okex/client"
4
5
  require "okex/coin"
5
6
  require "openssl"
6
7
  require "faraday"
7
8
 
8
- OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
9
-
10
9
  module OKEX
11
10
  class Error < StandardError; end
12
11
  end
@@ -0,0 +1,46 @@
1
+ class OKEX::ApiV3
2
+ def initialize(client)
3
+ @client = client
4
+ end
5
+
6
+ def balance(coin)
7
+ client.get("/api/account/v3/wallet/#{coin.code}")
8
+ end
9
+
10
+ def instruments
11
+ client.get("/api/swap/v3/instruments")
12
+ end
13
+
14
+ # 市价做空永续合约
15
+ # amount: 仓位开多少张
16
+ def short_swap(instrument_id, amount)
17
+ param = {
18
+ instrument_id: instrument_id.to_s,
19
+ size: amount.to_s,
20
+ type: "2",
21
+ order_type: "4",
22
+ }
23
+
24
+ client.post("/api/swap/v3/order", param)
25
+ end
26
+
27
+ # 市价平多
28
+ def close_long(instrument_id)
29
+ close_position(instrument_id, "long")
30
+ end
31
+
32
+ # 市价平空
33
+ def close_short(instrument_id)
34
+ close_position(instrument_id, "short")
35
+ end
36
+
37
+ private
38
+
39
+ attr_reader :client
40
+
41
+ def close_position(instrument_id, direction)
42
+ param = {"instrument_id": instrument_id, "direction": direction}
43
+
44
+ client.post("/api/swap/v3/close_position", param)
45
+ end
46
+ end
@@ -0,0 +1,44 @@
1
+ class OKEX::ApiV5
2
+ def initialize(client)
3
+ @client = client
4
+ end
5
+
6
+ def instruments
7
+ client.get("/api/v5/public/instruments")
8
+ end
9
+
10
+ def short_swap(instid, amount)
11
+ params = {
12
+ "instId": instid,
13
+ "tdMode": "cross",
14
+ "side": "sell",
15
+ "posSide": "short",
16
+ "ordType": "market",
17
+ "sz": "1"
18
+ }
19
+
20
+ client.post("/api/v5/trade/order", params)
21
+ end
22
+
23
+ def close_long(instid)
24
+ close_position(instid, "long")
25
+ end
26
+
27
+ def close_short(instid)
28
+ close_position(instid, "short")
29
+ end
30
+
31
+ private
32
+
33
+ attr_reader :client
34
+
35
+ def close_position(instid, direction)
36
+ params = {
37
+ "instId": instid,
38
+ "mgnMode": "cross",
39
+ "posSide": direction
40
+ }
41
+
42
+ client.post("/api/v5/trade/close-position", params)
43
+ end
44
+ end
data/lib/okex/client.rb CHANGED
@@ -8,46 +8,14 @@ module OKEX
8
8
  @passphrase = passphrase
9
9
  end
10
10
 
11
- def balance(coin)
12
- _get("/api/account/v3/wallet/#{coin.code}")
13
- end
14
-
15
- # name: sub account name
16
- def sub_account(name)
17
- _get("/api/account/v3/sub-account?sub-account=#{name}")
18
- end
19
-
20
- def instruments
21
- _get("/api/swap/v3/instruments")
22
- end
23
-
24
- # 市价做空永续合约
25
- # amount: 仓位开多少张
26
- def short_swap(instrument_id, amount)
27
- param = {
28
- instrument_id: instrument_id.to_s,
29
- size: amount.to_s,
30
- type: "2",
31
- order_type: "4",
32
- }
33
-
34
- _post("/api/swap/v3/order", param)
35
- end
36
-
37
- private
38
-
39
- attr_reader :api_key, :api_secret, :passphrase
40
-
41
- HOST = "https://www.okex.com"
42
-
43
- def _get(path)
11
+ def get(path)
44
12
  ts = timestamp
45
13
  sig = sign(ts, "GET", path)
46
14
 
47
15
  _resp(::Faraday.get(HOST + path, nil, headers(ts, sig)))
48
16
  end
49
17
 
50
- def _post(path, payload)
18
+ def post(path, payload)
51
19
  payload_json = gen_payload(payload)
52
20
 
53
21
  ts = timestamp
@@ -62,6 +30,12 @@ module OKEX
62
30
  end
63
31
  end
64
32
 
33
+ private
34
+
35
+ attr_reader :api_key, :api_secret, :passphrase
36
+
37
+ HOST = "https://www.okex.com"
38
+
65
39
  def gen_payload(payload)
66
40
  m = payload.map { |k, v| JSON.generate({k => v}, {space: ' '})}
67
41
  m2 = m.join(", ").gsub("{", "").gsub("}", "")
data/lib/okex/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module OKEX
2
- VERSION = "0.1.20"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: okex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.20
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Zhang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-07 00:00:00.000000000 Z
11
+ date: 2021-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -85,7 +85,8 @@ files:
85
85
  - bin/console
86
86
  - bin/setup
87
87
  - lib/okex.rb
88
- - lib/okex/api.rb
88
+ - lib/okex/api_v3.rb
89
+ - lib/okex/api_v5.rb
89
90
  - lib/okex/client.rb
90
91
  - lib/okex/coin.rb
91
92
  - lib/okex/coin/bitcoin.rb
data/lib/okex/api.rb DELETED
@@ -1,15 +0,0 @@
1
- module OKEX
2
- class API
3
- def initialize(client)
4
- @client = client
5
- end
6
-
7
- def method_missing(m, *args, &block)
8
- client.send(m, *args)
9
- end
10
-
11
- private
12
-
13
- attr_reader :client
14
- end
15
- end