okex 0.3.4 → 0.3.8

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: 463b9adff7eb98e1fa712f06153edbc29b80870aede2cd2913681da84f0e5b66
4
- data.tar.gz: 428d38ce826c5e3e01ddcd43c3a9e8e4e5b2de1d4f41139497ad5beee818b452
3
+ metadata.gz: f7579882ca09b2d2555970e0387d344193b59b374fadc72f3c5146591cba329b
4
+ data.tar.gz: 149af01aaa918bab7aa5f32f3198c195f9a467d86fd2914b82941928a9a0fd04
5
5
  SHA512:
6
- metadata.gz: 615e679ffb2f370020af864cdc753bcf7cb836a83e73a127046f09712b1a81a4d20dcbe94643e19177f1c61578fb8e3bfd44f752673fed56ab4208d4eeda7ee0
7
- data.tar.gz: dc96eacc3985d1889eac587fee049b2c174eca9e245d03e66a4bfb3f1cb8c1871c99cb73ef70f5b418703883f4e6927888c7806492841fb76a71f9b4b43a332a
6
+ metadata.gz: a94f5d2e91c1d5021a2b528514d9159a81b3da12112c5ca05f1431f498f625b93379bf51e2cddb898b6ec2f151bd77a506cd2c8ff8190b18d00c46def1d77738
7
+ data.tar.gz: 448c8cbbcd164b29d9fdc6e2a4a044cb48dd2d0a7802502f13105631453b8bba4730f08855907eb314c49349bb7a4b893eeeacea0020a77ade0f9e2c78e16766
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- okex (0.3.4)
4
+ okex (0.3.8)
5
5
  faraday (~> 1.5)
6
6
 
7
7
  GEM
@@ -9,7 +9,7 @@ GEM
9
9
  specs:
10
10
  byebug (11.1.3)
11
11
  diff-lcs (1.4.4)
12
- faraday (1.5.1)
12
+ faraday (1.7.1)
13
13
  faraday-em_http (~> 1.0)
14
14
  faraday-em_synchrony (~> 1.0)
15
15
  faraday-excon (~> 1.1)
@@ -17,6 +17,7 @@ GEM
17
17
  faraday-net_http (~> 1.0)
18
18
  faraday-net_http_persistent (~> 1.1)
19
19
  faraday-patron (~> 1.0)
20
+ faraday-rack (~> 1.0)
20
21
  multipart-post (>= 1.2, < 3)
21
22
  ruby2_keywords (>= 0.0.4)
22
23
  faraday-em_http (1.0.0)
@@ -26,6 +27,7 @@ GEM
26
27
  faraday-net_http (1.0.1)
27
28
  faraday-net_http_persistent (1.2.0)
28
29
  faraday-patron (1.0.0)
30
+ faraday-rack (1.0.0)
29
31
  multipart-post (2.1.1)
30
32
  rake (10.5.0)
31
33
  rspec (3.10.0)
data/lib/okex/api_v5.rb CHANGED
@@ -69,7 +69,7 @@ class OKEX::ApiV5
69
69
 
70
70
  def max_size(instrument_id)
71
71
  data = client.get(host, "/api/v5/account/max-size?instId=#{instrument_id}&tdMode=cross")
72
-
72
+
73
73
  ret = OKEX::MaxSize.new(-1, -1)
74
74
 
75
75
  el = data[0]
@@ -85,6 +85,16 @@ class OKEX::ApiV5
85
85
 
86
86
  data[0]['lever'].to_i
87
87
  end
88
+
89
+ def set_leverage(inst_id, leverage)
90
+ params = {
91
+ "instId": inst_id,
92
+ "lever": leverage,
93
+ "mgnMode": "cross"
94
+ }
95
+
96
+ client.post(host, "/api/v5/account/set-leverage", params)
97
+ end
88
98
 
89
99
  # 设置止损价格
90
100
  # @param inst_id [String] 合约名称
@@ -112,11 +122,37 @@ class OKEX::ApiV5
112
122
  # @param inst_id [String] 合约名称
113
123
  def stop_loss_price(inst_id)
114
124
  result = client.get(host, "/api/v5/trade/orders-algo-pending?instId=#{inst_id}&instType=SWAP&ordType=conditional")
115
- return result[0]["slTriggerPx"].to_i if result.size == 1
125
+
126
+ return -1 if result.empty?
127
+ return result[0]["slTriggerPx"].to_f if result.size == 1
116
128
 
117
129
  raise "invalid result: #{result.inspect}"
118
130
  end
119
131
 
132
+ # 查询当前止损订单的ID
133
+ # 可用于后续取消止损订单
134
+ # @param inst_id [String] 合约名称
135
+ def algo_order_id(inst_id)
136
+ result = client.get(host, "/api/v5/trade/orders-algo-pending?instId=#{inst_id}&instType=SWAP&ordType=conditional")
137
+
138
+ return "" if result.empty?
139
+ return result[0]["algoId"] if result.size == 1
140
+
141
+ raise "invalid result: #{result.inspect}"
142
+ end
143
+
144
+ # 撤销委托单
145
+ # @param algo_id [String] 策略委托单ID
146
+ # @param inst_id [String] 合约ID
147
+ def cancel_algo_order(algo_id, inst_id)
148
+ params = {
149
+ "algoId": algo_id,
150
+ "instId": inst_id
151
+ }
152
+
153
+ client.post(host, "/api/v5/trade/cancel-algos", [params])
154
+ end
155
+
120
156
  private
121
157
 
122
158
  attr_reader :client, :host
data/lib/okex/client.rb CHANGED
@@ -23,8 +23,15 @@ module OKEX
23
23
  end
24
24
 
25
25
  def post(host, path, payload)
26
- payload_json = gen_payload(payload)
27
-
26
+ if payload.is_a?(Array)
27
+ _json = payload.map do |hx|
28
+ gen_payload(hx)
29
+ end
30
+ payload_json = "[#{_json.join(",")}]"
31
+ else
32
+ payload_json = gen_payload(payload)
33
+ end
34
+
28
35
  url = host + path
29
36
  ts = timestamp
30
37
  sig = sign(ts, "POST", path + payload_json)
data/lib/okex/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module OKEX
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.8"
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.3.4
4
+ version: 0.3.8
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-29 00:00:00.000000000 Z
11
+ date: 2021-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler