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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/okex.rb +2 -3
- data/lib/okex/api_v3.rb +46 -0
- data/lib/okex/api_v5.rb +44 -0
- data/lib/okex/client.rb +8 -34
- data/lib/okex/version.rb +1 -1
- metadata +4 -3
- data/lib/okex/api.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dae1478814bf6ccebb68aaf3bd52c3ac834148cb90b4b8e8f6427ccc811304eb
|
4
|
+
data.tar.gz: 53bc2e5e42b90f1f60390273a82f98fa4caf19c07d238f38edac4bbf7a51a572
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0afed6eb2d1e37d817e8f172d3713a1aec653a3eb70cab406523e5e7fc21aae803f0a64d16e11fa73440d34507c37303d2f33c7669ecc5218657546f322ce295
|
7
|
+
data.tar.gz: 6bb22c3ce7cc7b3a739a975d7a7b3239edb5d2e5edb9bc5ea056229ca238ab806c25fc9c8703bedc8e969d28cea42c8119733ac603d11db359fcbad13e418594
|
data/Gemfile.lock
CHANGED
data/lib/okex.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
require "okex/version"
|
2
|
-
require "okex/
|
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
|
data/lib/okex/api_v3.rb
ADDED
@@ -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
|
data/lib/okex/api_v5.rb
ADDED
@@ -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
|
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
|
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
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.
|
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-
|
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/
|
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
|