coin-market 0.1.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c9be0ef5ce58c0040b1440851a69f245cb612e4b
4
- data.tar.gz: e49e6b1f8b10bd4a9f1c07fadbed2f8b6444a7cf
3
+ metadata.gz: 0ff1e42ac06a874df93f4bd2cf40b6eb0663cc03
4
+ data.tar.gz: 594415f9d72f6706c481a548c9ab51298291caf6
5
5
  SHA512:
6
- metadata.gz: c4049b1bd97d675cba02081748a6c8054d88035e54d415ae238c23a0d91b47172a9702217ad94073e6227048b5f2731bf297a37de9657a8d094b70e519a374ef
7
- data.tar.gz: 9d2e438cfac8c061c569d4380bfcc0fcc9584b189fc1807915d64eedb8532723f62981094b0aac4e1306d6764e512d198eb3fb30af078be968e33cdca678880a
6
+ metadata.gz: 53c576528f25bc90d4312f6fe9dbc963bbb973f050219a17c80637de58e80fed37349af9c519d75552a4db69a1b0b9d2988f32f4cc5651819b699233b1864487
7
+ data.tar.gz: 0e11716c23d6f3e8710ba46391a47ee4f6f45194671e5e41d54184f087aaab9ab8f33f64ac9cbf36b2e4b2c98ef4343a9930dbd61f66a9446f6807b9fd89cae4
data/README.md CHANGED
@@ -22,9 +22,13 @@ Or install it yourself as:
22
22
  ## Usage
23
23
 
24
24
  ### Korbit
25
+
26
+ https://apidocs.korbit.co.kr/
27
+
25
28
  ```ruby
26
29
  require 'coin-market'
27
30
 
31
+ # ticker
28
32
  korbit = Coin::Market::Korbit.new
29
33
  response = korbit.get_ticker_btc_krw
30
34
  => {"timestamp"=>1512415955593, "last"=>"13357500"}
@@ -38,6 +42,31 @@ response = korbit.get_ticker_eth_krw
38
42
  response = korbit.get_ticker_xrp_krw
39
43
  => {"timestamp"=>1512415720622, "last"=>"286"}
40
44
 
45
+
46
+ # ticker detail
47
+ korbit.get_ticker_detailed_btc_krw
48
+ => {"timestamp"=>1512419385635,
49
+ "last"=>"13410000",
50
+ "bid"=>"13410000",
51
+ "ask"=>"13410500",
52
+ "low"=>"12833000",
53
+ "high"=>"13500000",
54
+ "volume"=>"4690.751945329017480177",
55
+ "change"=>"43500",
56
+ "changePercent"=>"0.33"}
57
+
58
+ korbit.get_ticker_detailed_eth_krw
59
+ => {"timestamp"=>1512418570222,
60
+ "last"=>"542900",
61
+ "bid"=>"542450",
62
+ "ask"=>"542950",
63
+ "low"=>"532400",
64
+ "high"=>"549800",
65
+ "volume"=>"23443.919674902796768231",
66
+ "change"=>"-50",
67
+ "changePercent"=>"-0.01"}
68
+
69
+
41
70
  ```
42
71
 
43
72
  ### Coinone
@@ -26,6 +26,6 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency "rake", "~> 10.0"
27
27
  spec.add_development_dependency "rspec", "~> 3.2"
28
28
 
29
- spec.add_dependency "rest-client", "~> 2.1"
29
+ spec.add_dependency "rest-client", "~> 2.0"
30
30
  spec.required_ruby_version = ">= 2.0.0"
31
31
  end
@@ -6,47 +6,77 @@ require 'json'
6
6
  module Coin
7
7
  module Market
8
8
  BTC_KRW = "btc_krw"
9
+ ETH_KRW = "eth_krw"
9
10
  ETC_KRW = "etc_krw"
10
11
  XRP_KRW = "xrp_krw"
11
12
  BCH_KRW = "bch_krw"
13
+
14
+ SUPPORT_CURRENCY = [BTC_KRW, ETH_KRW, ETC_KRW, XRP_KRW, BCH_KRW]
12
15
 
13
16
  class Korbit
14
17
  GET_TICKER = "https://api.korbit.co.kr/v1/ticker"
18
+ GET_TICKER_DETAILED = "https://api.korbit.co.kr/v1/ticker/detailed"
15
19
 
16
- def get_ticker_btc_krw()
17
- get_ticker(BTC_KRW)
18
- end
20
+ def self.create_method(currency)
21
+ define_method "get_ticker_#{currency}" do
22
+ get_ticker(currency)
23
+ end
19
24
 
20
- def get_ticker_eth_krw()
21
- get_ticker(ETC_KRW)
25
+ define_method "get_ticker_detailed_#{currency}" do
26
+ get_ticker_detailed(currency)
27
+ end
22
28
  end
23
29
 
24
- def get_ticker_xrp_krw()
25
- get_ticker(XRP_KRW)
30
+ create_method(BTC_KRW)
31
+ create_method(ETH_KRW)
32
+ create_method(ETC_KRW)
33
+ create_method(XRP_KRW)
34
+ create_method(BCH_KRW)
35
+
36
+
37
+ def get_ticker_detailed(currency_pair)
38
+ unless is_supported_ticker(currency_pair)
39
+ raise Exceptions::CannotSupportException, __method__ + currency_pair
40
+ end
41
+
42
+ ticker = _process_api(get_ticker_detailed_with_currency_pair(currency_pair))
43
+
44
+ if ticker.nil?
45
+ raise Exceptions::NetworkException, __method__ + currency_pair
46
+ end
47
+ ticker
26
48
  end
27
49
 
28
- def get_ticker_bch_krw()
29
- get_ticker(BCH_KRW)
50
+ def _process_api(url)
51
+ http_response = RestClient.get(url)
52
+ JSON.parse(http_response.body)
30
53
  end
31
-
54
+
32
55
  def get_ticker(currency_pair)
33
56
  unless is_supported_ticker(currency_pair)
34
- raise Exceptions::CannotSupportException, 'get_ticker_' + currency_pair
57
+ raise Exceptions::CannotSupportException, __method__ + currency_pair
35
58
  end
36
- http_response = RestClient.get(make_currency_pair(currency_pair))
37
- ticker = JSON.parse(http_response.body)
59
+
60
+ ticker = _process_api(get_ticker_with_currency_pair(currency_pair))
61
+
38
62
  if ticker.nil?
39
- raise Exceptions::NetworkException, 'get_ticker_' + currency_pair
63
+ raise Exceptions::NetworkException, __method__ + currency_pair
40
64
  end
41
65
  ticker
42
66
  end
43
67
 
44
- def make_currency_pair(currency_pair)
68
+ private
69
+
70
+ def get_ticker_with_currency_pair(currency_pair)
45
71
  GET_TICKER + "?=currency_pair=" + currency_pair
46
72
  end
47
73
 
74
+ def get_ticker_detailed_with_currency_pair(currency_pair)
75
+ GET_TICKER_DETAILED + "?=currency_pair=" + currency_pair
76
+ end
77
+
48
78
  def is_supported_ticker(currency_pair)
49
- currency_pair == BTC_KRW || currency_pair == ETC_KRW || currency_pair == XRP_KRW || currency_pair == BCH_KRW
79
+ SUPPORT_CURRENCY.include?(currency_pair)
50
80
  end
51
81
 
52
82
  end
@@ -1,5 +1,5 @@
1
1
  module Coin
2
2
  module Market
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coin-market
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - suhanlee
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '2.1'
61
+ version: '2.0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '2.1'
68
+ version: '2.0'
69
69
  description: Coin Marekts API Libary including korbit, bitthumb, coinone, coinnest
70
70
  email:
71
71
  - suhan.lee.k@gmail.com