okex 0.2.3 → 0.2.5
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/lib/okex.rb +1 -2
- data/lib/okex/api_v5.rb +7 -6
- data/lib/okex/client.rb +5 -12
- data/lib/okex/host.rb +12 -0
- data/lib/okex/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e79f7f281cc49fecf294441cfc91c8a0f7e065204a69fae02c968f48b5fc83a
|
4
|
+
data.tar.gz: 802b3412745cc52ed7989bf6e16d9e6e61a9d5c962446bb81b29182abcaeeab0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f00ee33cb15494a908dba476c5fb1b3eaeea37b3b313bfb5d47a95237ac6117b83b6adae1790bbf62ece997b4f972eb98d77a6326dbb3899da4bb116d96cc06
|
7
|
+
data.tar.gz: 6a2ddad58a09dfdb945babd65cc78022c427bb6147df57f5c38b5e74438ebf16e75f2746287da0931abfb4e0f643077aeee984f7920ea5954ca47aa75a548783
|
data/lib/okex.rb
CHANGED
data/lib/okex/api_v5.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
class OKEX::ApiV5
|
2
|
-
def initialize(client)
|
2
|
+
def initialize(client, host)
|
3
3
|
@client = client
|
4
|
+
@host = host
|
4
5
|
end
|
5
6
|
|
6
7
|
def instruments
|
7
|
-
client.get("/api/v5/public/instruments")
|
8
|
+
client.get(host, "/api/v5/public/instruments?instType=SWAP")
|
8
9
|
end
|
9
10
|
|
10
11
|
def orders
|
11
|
-
resp = client.get("/api/v5/account/positions")
|
12
|
+
resp = client.get(host, "/api/v5/account/positions")
|
12
13
|
|
13
14
|
if resp['code'].to_i == 0 && resp['data'].size > 0
|
14
15
|
return resp['data'].map {|params| OKEX::Order.new(params)}
|
@@ -27,7 +28,7 @@ class OKEX::ApiV5
|
|
27
28
|
"sz": "1"
|
28
29
|
}
|
29
30
|
|
30
|
-
client.post("/api/v5/trade/order", params)
|
31
|
+
client.post(host, "/api/v5/trade/order", params)
|
31
32
|
end
|
32
33
|
|
33
34
|
def close_long(instid)
|
@@ -40,7 +41,7 @@ class OKEX::ApiV5
|
|
40
41
|
|
41
42
|
private
|
42
43
|
|
43
|
-
attr_reader :client
|
44
|
+
attr_reader :client, :host
|
44
45
|
|
45
46
|
def close_position(instid, direction)
|
46
47
|
params = {
|
@@ -49,6 +50,6 @@ class OKEX::ApiV5
|
|
49
50
|
"posSide": direction
|
50
51
|
}
|
51
52
|
|
52
|
-
client.post("/api/v5/trade/close-position", params)
|
53
|
+
client.post(host, "/api/v5/trade/close-position", params)
|
53
54
|
end
|
54
55
|
end
|
data/lib/okex/client.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'time'
|
2
2
|
require 'base64'
|
3
3
|
require 'json'
|
4
|
+
require 'faraday'
|
4
5
|
|
5
6
|
module OKEX
|
6
7
|
class Client
|
@@ -10,34 +11,26 @@ module OKEX
|
|
10
11
|
@passphrase = passphrase
|
11
12
|
end
|
12
13
|
|
13
|
-
def get(path)
|
14
|
+
def get(host, path)
|
14
15
|
ts = timestamp
|
15
16
|
sig = sign(ts, "GET", path)
|
16
17
|
|
17
|
-
_resp(
|
18
|
+
_resp(Faraday.get(host + path, nil, headers(ts, sig)))
|
18
19
|
end
|
19
20
|
|
20
|
-
def post(path, payload)
|
21
|
+
def post(host, path, payload)
|
21
22
|
payload_json = gen_payload(payload)
|
22
23
|
|
23
24
|
ts = timestamp
|
24
25
|
sig = sign(ts, "POST", path + payload_json)
|
25
26
|
|
26
|
-
|
27
|
-
conn = ::Faraday.new(HOST + path, :ssl => {:verify => false})
|
28
|
-
result = conn.post(HOST + path, payload_json, headers(ts, sig))
|
29
|
-
_resp(result)
|
30
|
-
rescue => e
|
31
|
-
puts "[error] #{e.inspect}"
|
32
|
-
end
|
27
|
+
_resp(Faraday.post(host + path, payload_json, headers(ts, sig)))
|
33
28
|
end
|
34
29
|
|
35
30
|
private
|
36
31
|
|
37
32
|
attr_reader :api_key, :api_secret, :passphrase
|
38
33
|
|
39
|
-
HOST = "https://www.okex.com"
|
40
|
-
|
41
34
|
def gen_payload(payload)
|
42
35
|
m = payload.map { |k, v| JSON.generate({k => v}, {space: ' '})}
|
43
36
|
m2 = m.join(", ").gsub("{", "").gsub("}", "")
|
data/lib/okex/host.rb
ADDED
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.2.
|
4
|
+
version: 0.2.5
|
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-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -90,6 +90,7 @@ files:
|
|
90
90
|
- lib/okex/client.rb
|
91
91
|
- lib/okex/coin.rb
|
92
92
|
- lib/okex/coin/bitcoin.rb
|
93
|
+
- lib/okex/host.rb
|
93
94
|
- lib/okex/order.rb
|
94
95
|
- lib/okex/version.rb
|
95
96
|
- okex.gemspec
|