okex 0.2.1 → 0.2.3

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: 7a607b5cc12603ee0523d5c79d24ca3777e17b5809f0a2d1f46835bcf855fadb
4
- data.tar.gz: 1443cf42904c1567069f4aefa505b3470cb996d9c4586c10a0aacb49b2f7c82d
3
+ metadata.gz: 119599f81a10e3904790ddb620ce5e73c5f8f880c542d0b1cc34e56463cc88d4
4
+ data.tar.gz: a0b3c1f7f95ddfbacb37703461ffb92f3df372fa6e6f64e91c6027127d513a9a
5
5
  SHA512:
6
- metadata.gz: 6f1ea6535eeffa3f2dbe6e35b7b44ccd753820f51478f3ba882a854efe9e73bbf4424586d1b881679cbd8db84cd5c8f1a87d7f906d7f6fdfe9d6c78d24152a2b
7
- data.tar.gz: 9b9dc428f69094870b41cf4fe9b6a77cffdfbf979dbf04e0b72ea471e000d078d3999d06d2b1ed4a573c6485d75c7c7441911434e0a9a191e61f22703e8dcad1
6
+ metadata.gz: e40edaca89bbfad96f815190516ba4ac2a47244a442189d54aca236c0a908b03141f4878a00c8153e2496c63a1aef9d25b747419c624bc3eea82caf89ec72efe
7
+ data.tar.gz: 17d81b29e609e2a11614b214ca77c3143391654a1276eefe4d702b63fc81e415ff92cf6a554d28c9f55d2c41c0734c9409f5d3617ad46cdd5a9d167660847403
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- okex (0.2.1)
4
+ okex (0.2.3)
5
5
  faraday (~> 1.5)
6
6
 
7
7
  GEM
data/lib/okex.rb CHANGED
@@ -3,6 +3,7 @@ require "okex/api_v3"
3
3
  require "okex/api_v5"
4
4
  require "okex/client"
5
5
  require "okex/coin"
6
+ require "okex/order"
6
7
  require "openssl"
7
8
  require "faraday"
8
9
 
data/lib/okex/api_v5.rb CHANGED
@@ -8,7 +8,13 @@ class OKEX::ApiV5
8
8
  end
9
9
 
10
10
  def orders
11
- client.get("/api/v5/account/positions")
11
+ resp = client.get("/api/v5/account/positions")
12
+
13
+ if resp['code'].to_i == 0 && resp['data'].size > 0
14
+ return resp['data'].map {|params| OKEX::Order.new(params)}
15
+ end
16
+
17
+ []
12
18
  end
13
19
 
14
20
  def short_swap(instid, amount)
data/lib/okex/client.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require 'time'
2
+ require 'base64'
3
+ require 'json'
2
4
 
3
5
  module OKEX
4
6
  class Client
data/lib/okex/order.rb ADDED
@@ -0,0 +1,52 @@
1
+ module OKEX
2
+ class Order
3
+ POS_LONG = 'long'.freeze
4
+ POS_SHORT = 'short'.freeze
5
+
6
+ def initialize(params)
7
+ @params = params
8
+ end
9
+
10
+ def instrument_id
11
+ dig("instId")
12
+ end
13
+
14
+ # 杠杆倍数
15
+ def leverage
16
+ dig("lever")
17
+ end
18
+
19
+ def created_at
20
+ Time.at(dig("cTime").to_i / 1000)
21
+ end
22
+
23
+ # 平均开仓价
24
+ def avg_open_price
25
+ dig("avgPx").to_f
26
+ end
27
+
28
+ # 预估强平价
29
+ def est_liq_price
30
+ dig("liqPx").to_f
31
+ end
32
+
33
+ # 持仓方向
34
+ def position_side
35
+ side = dig("posSide")
36
+ if [POS_SHORT, POS_LONG].include?(side)
37
+ return side
38
+ end
39
+ end
40
+
41
+ # 未实现收益
42
+ def upl
43
+ dig("upl").to_f
44
+ end
45
+
46
+ private
47
+
48
+ def dig(key)
49
+ @params[key]
50
+ end
51
+ end
52
+ end
data/lib/okex/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module OKEX
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.3"
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.1
4
+ version: 0.2.3
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-22 00:00:00.000000000 Z
11
+ date: 2021-07-23 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/order.rb
93
94
  - lib/okex/version.rb
94
95
  - okex.gemspec
95
96
  homepage: https://github.com/daqing/okex