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 +4 -4
- data/Gemfile.lock +4 -2
- data/lib/okex/api_v5.rb +38 -2
- data/lib/okex/client.rb +9 -2
- data/lib/okex/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7579882ca09b2d2555970e0387d344193b59b374fadc72f3c5146591cba329b
|
4
|
+
data.tar.gz: 149af01aaa918bab7aa5f32f3198c195f9a467d86fd2914b82941928a9a0fd04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
+
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.
|
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
|
-
|
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
|
-
|
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
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
|
+
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-
|
11
|
+
date: 2021-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|