okex 0.2.3 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 119599f81a10e3904790ddb620ce5e73c5f8f880c542d0b1cc34e56463cc88d4
4
- data.tar.gz: a0b3c1f7f95ddfbacb37703461ffb92f3df372fa6e6f64e91c6027127d513a9a
3
+ metadata.gz: 6e79f7f281cc49fecf294441cfc91c8a0f7e065204a69fae02c968f48b5fc83a
4
+ data.tar.gz: 802b3412745cc52ed7989bf6e16d9e6e61a9d5c962446bb81b29182abcaeeab0
5
5
  SHA512:
6
- metadata.gz: e40edaca89bbfad96f815190516ba4ac2a47244a442189d54aca236c0a908b03141f4878a00c8153e2496c63a1aef9d25b747419c624bc3eea82caf89ec72efe
7
- data.tar.gz: 17d81b29e609e2a11614b214ca77c3143391654a1276eefe4d702b63fc81e415ff92cf6a554d28c9f55d2c41c0734c9409f5d3617ad46cdd5a9d167660847403
6
+ metadata.gz: 1f00ee33cb15494a908dba476c5fb1b3eaeea37b3b313bfb5d47a95237ac6117b83b6adae1790bbf62ece997b4f972eb98d77a6326dbb3899da4bb116d96cc06
7
+ data.tar.gz: 6a2ddad58a09dfdb945babd65cc78022c427bb6147df57f5c38b5e74438ebf16e75f2746287da0931abfb4e0f643077aeee984f7920ea5954ca47aa75a548783
data/lib/okex.rb CHANGED
@@ -4,8 +4,7 @@ require "okex/api_v5"
4
4
  require "okex/client"
5
5
  require "okex/coin"
6
6
  require "okex/order"
7
- require "openssl"
8
- require "faraday"
7
+ require "okex/host"
9
8
 
10
9
  module OKEX
11
10
  class Error < StandardError; end
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(::Faraday.get(HOST + path, nil, headers(ts, sig)))
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
- begin
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
@@ -0,0 +1,12 @@
1
+ class OKEX::Host
2
+ OUYI_HOST = "https://www.ouyi.cc".freeze
3
+ OKEX_HOST = "https://www.okex.com".freeze
4
+
5
+ def self.ouyi
6
+ OUYI_HOST
7
+ end
8
+
9
+ def self.okex
10
+ OKEX_HOST
11
+ end
12
+ end
data/lib/okex/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module OKEX
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.5"
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.2.3
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-23 00:00:00.000000000 Z
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