okcoin-ruby 0.0.4 → 0.0.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
  SHA1:
3
- metadata.gz: 7fde5fbf15d7d1456c2e71b7c082d50027e61b2d
4
- data.tar.gz: e3df5c33d806fe76fe3bb2342160e14f28d83dfb
3
+ metadata.gz: 830387957a835f4427a3c83b5b9a51b540147328
4
+ data.tar.gz: 7716a827c6d2fa7d61ac8ad47cd9a9a1028d6cb4
5
5
  SHA512:
6
- metadata.gz: acf2b40dbf2faf83ebabd4aaf3a67735e19087dff98323373288b5fb0248b8dc2dd0c5dcb0443b256a87863c1f30fcf972f42f2ef4c9f3a6949de8225d724155
7
- data.tar.gz: e1439a1322dbc48dbc6395a779186aa6f6f55c28525f76c5156a90a62de929d7894230f422ba7e0cf722ea837dd0ebb865c9174ca6329ab591e436182937f365
6
+ metadata.gz: 07fbdae8dfb02cea01f431ce8f115cda92e5a445abb847eaa166ef5790f8fdf139d80cac712f5691d7fccd7ed9927580950171db6b41ce4d9d3f4c9b84982f5f
7
+ data.tar.gz: cccbd09133e4ccc261f76bb6abf459db736062540b5aa0050574b57414606c61cf48df42fcd869bee316aebb54d70d2eeb97579296f61a98b6d5a147e3bbf6fb
data/README.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Okcoin API Ruby Wrapper
2
- Supports REST and Websocket protocols
2
+ Unofficial ruby library for Okcoin Bitcoin Exchange
3
+
4
+ If you feel it's helpful and would like to donate, send coins to
5
+
6
+ ```
7
+ BTC 15y2a3FKLW89qoDniDMRwsdhrZeHJA1Det
8
+ ```
3
9
 
4
10
  ## Installation
5
11
 
@@ -17,15 +23,45 @@ And then execute:
17
23
  ## Usage
18
24
 
19
25
  ### 1. REST Example
20
- ```
26
+ Initialize client
27
+ ```ruby
21
28
  okcoin = Okcoin::Rest.new api_key: ENV['OKCOIN_APIKEY'], secret_key: ENV['OKCOIN_SECRET']
22
- puts okcoin.userinfo
23
- puts okcoin.orderbook(pair: "btcusd", items_no: 50)
24
29
  ```
25
30
 
26
- ### 2. WebSocket Example
31
+ Make requests
27
32
 
33
+ Spot Price
34
+ ```ruby
35
+ okcoin.spot_ticker(pair: "btc_usd")
36
+ okcoin.spot_orderbook(pair: "btc_usd", items_no: 50, merge: 0)
37
+ okcoin.spot_trades(pair: "btc_usd", since: nil)
38
+ okcoin.spot_kandlestick(pair: "btc_usd", type: "30min", size: 50, since: nil)
39
+ okcoin.spot_swaps_orderbook(pair: "btc_usd")
40
+ ```
41
+
42
+ Spot Trade
43
+ ```ruby
44
+ okcoin.spot_userinfo
45
+ okcoin.spot_trade(pair: "btc_usd", type: "buy", price:240, amount:1)
28
46
  ```
47
+
48
+ Futures Price
49
+ ```ruby
50
+ okcoin.futures_orderbook(pair: "btc_usd", contract: "this_week", items_no: 50)
51
+ ```
52
+
53
+ Futures Trade
54
+ ```ruby
55
+ okcoin.futures_userinfo
56
+ okcoin.futures_trade(pair: "btc_usd", amount: 1, type: 1, contract_type: "this_week", match_price: 1, price: nil, lever_rate: 10)
57
+ okcoin.futures_cancel(pair: "btc_usd", contract_type: "this_week", order_id: 12345)
58
+ okcoin.futures_order_info(order_id: 12345, symbol: "btc_usd", contract_type: "this_week", status: nil, current_page: nil, page_length: nil)
59
+ okcoin.futures_position(pair: "btc_usd", contract_type: "this_week")
60
+ ```
61
+
62
+ ### 2. WebSocket Example
63
+
64
+ ```ruby
29
65
  okcoin = Okcoin::WS.new api_key: ENV['OKCOIN_APIKEY'], secret_key: ENV['OKCOIN_SECRET']
30
66
  okcoin.userinfo
31
67
  okcoin.pingpong
data/lib/okcoin/rest.rb CHANGED
@@ -9,28 +9,63 @@ class Okcoin
9
9
  end
10
10
 
11
11
  public
12
+ # Spot Price API
13
+ def spot_ticker(pair: "btc_usd")
14
+ query = { "symbol" => pair }
15
+ get_request(url: "/v1/ticker.do", query: query)
16
+ end
12
17
 
13
- def orderbook(pair:, items_no: 50)
14
- query = { "ok" => 1, "symbol" => pair, "size" => items_no }
15
- get_request(url: "/depth.do", query: query)
18
+ def spot_orderbook(pair: "btc_usd", items_no: 50, merge: 0)
19
+ query = { "symbol" => pair, "size" => items_no, "merge" => merge }
20
+ get_request(url: "/v1/depth.do", query: query)
16
21
  end
17
22
 
18
- def futures_userinfo
23
+ def spot_trades(pair: "btc_usd", since: nil)
24
+ query = { "symbol" => pair, "since" => since }
25
+ get_request(url: "/v1/trades.do", query: query)
26
+ end
27
+
28
+ def spot_kandlestick(pair: "btc_usd", type: "30min", size: 50, since: nil)
29
+ query = { "symbol" => pair, "type" => type, "size" => size, "since" => since }
30
+ get_request(url: "/v1/kline.do", query: query)
31
+ end
32
+
33
+ def spot_swaps_orderbook(pair: "btc_usd")
34
+ query = { "symbol" => pair }
35
+ get_request(url: "/v1/lend_depth.do", query: query)
36
+ end
37
+
38
+ # Spot Trading API
39
+
40
+ def spot_userinfo
19
41
  post_data = initial_post_data
20
- post_request post_data: post_data, action: "/v1/future_userinfo.do"
42
+ post_request post_data: post_data, action: "/v1/userinfo.do"
21
43
  end
22
44
 
23
- def equity
45
+ def spot_trade(pair:, type:, price:, amount:)
24
46
  post_data = initial_post_data
25
- post_request(post_data: post_data, action: "/v1/future_userinfo.do")["info"]["btc"]["account_rights"]
47
+
48
+ post_data["symbol"] = pair
49
+ post_data["type"] = type
50
+ post_data["amount"] = amount
51
+ post_data["price"] = price
52
+
53
+ post_request post_data: post_data, action: "/v1/trade.do"
26
54
  end
27
55
 
56
+ # Futures Price API
28
57
  def futures_orderbook(pair:, contract:, items_no: 50)
29
58
  query = { "symbol" => pair, "contractType" => contract, "size" => items_no }
30
59
  get_request(url: "/future_depth.do", query: query)
31
60
  end
32
61
 
33
- def trade_futures(pair:, amount:, type:, contract_type:, match_price:, price: nil, lever_rate: 10)
62
+ # Futures Trading API
63
+ def futures_userinfo
64
+ post_data = initial_post_data
65
+ post_request post_data: post_data, action: "/v1/future_userinfo.do"
66
+ end
67
+
68
+ def futures_trade(pair:, amount:, type:, contract_type:, match_price:, price: nil, lever_rate: 10)
34
69
  post_data = initial_post_data
35
70
 
36
71
  post_data["symbol"] = pair
@@ -45,7 +80,7 @@ class Okcoin
45
80
  post_request post_data: post_data, action: "/v1/future_trade.do"
46
81
  end
47
82
 
48
- def future_cancel(pair:, contract_type:, order_id:)
83
+ def futures_cancel(pair:, contract_type:, order_id:)
49
84
  post_data = initial_post_data
50
85
 
51
86
  post_data["symbol"] = pair
@@ -55,13 +90,16 @@ class Okcoin
55
90
  post_request post_data: post_data, action: "/v1/future_cancel.do"
56
91
  end
57
92
 
58
- def futures_orders_info(order_id:, symbol:, contract_type:)
93
+ def futures_order_info(order_id:, symbol:, contract_type:, status: nil, current_page: nil, page_length: nil)
59
94
  post_data = initial_post_data
60
95
  post_data["symbol"] = symbol
61
96
  post_data["contract_type"] = contract_type
62
97
  post_data["order_id"] = order_id
98
+ post_data["status"] = status
99
+ post_data["current_page"] = current_page
100
+ post_data["page_length"] = page_length
63
101
 
64
- post_request post_data: post_data, action: "/v1/future_orders_info.do"
102
+ post_request post_data: post_data, action: "/v1/future_order_info.do"
65
103
  end
66
104
 
67
105
  def futures_position(pair:, contract_type:)
@@ -71,12 +109,6 @@ class Okcoin
71
109
  post_request post_data: post_data, action: "/v1/future_position.do"
72
110
  end
73
111
 
74
-
75
- def userinfo
76
- post_data = initial_post_data
77
- post_request post_data: post_data, action: "/v1/userinfo.do"
78
- end
79
-
80
112
  private
81
113
 
82
114
  def handle_timeouts
@@ -1,3 +1,3 @@
1
1
  class Okcoin
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: okcoin-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Cherevkov