Module: Cryptum::WebSock::Coinbase

Defined in:
lib/cryptum/web_sock/coinbase.rb

Overview

This module is used to Establish a Web Socket Connection with Coinbase

Class Method Summary collapse

Class Method Details

.connect(opts = {}) ⇒ Object

Supported Method Parameters

Cryptum::WebSock.connect( )



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/cryptum/web_sock/coinbase.rb', line 13

public_class_method def self.connect(opts = {})
  option_choice = opts[:option_choice]
  env = opts[:env]

  # cb_pro_ws_feed = 'wss://ws-feed.pro.coinbase.com'
  # cb_pro_ws_feed = 'wss://ws-feed-public.sandbox.pro.coinbase.com' if env[:env] == :sandbox
  cb_pro_ws_feed = 'wss://ws-feed.exchange.coinbase.com'
  cb_pro_ws_feed = 'wss://ws-feed-public.sandbox.exchange.coinbase.com' if env[:env] == :sandbox

  extensions = [PermessageDeflate]

  if option_choice.proxy
    tls_opts = {
      verify_peer: false
    }

    proxy_opts = {
      origin: option_choice.proxy
    }

    ws = Faye::WebSocket::Client.new(
      cb_pro_ws_feed,
      [],
      tls: tls_opts,
      proxy: proxy_opts,
      extensions: extensions,
      ping: 9
    )
  else
    ws = Faye::WebSocket::Client.new(
      cb_pro_ws_feed,
      [],
      extensions: extensions,
      ping: 9
    )
  end

  ws
rescue Interrupt, StandardError => e
  Cryptum::Log.append(level: :error, msg: e, which_self: self)
end

.helpObject

Display Usage for this Module



90
91
92
93
# File 'lib/cryptum/web_sock/coinbase.rb', line 90

public_class_method def self.help
  puts "USAGE:
  "
end

.subscribe_message(opts = {}) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/cryptum/web_sock/coinbase.rb', line 55

public_class_method def self.subscribe_message(opts = {})
  option_choice = opts[:option_choice]
  env = opts[:env]
  product_id = option_choice.symbol.to_s.gsub('_', '-').upcase

  api_secret = env[:api_secret]
  api_signature_response = Cryptum::API::Signature.generate(
    api_secret: api_secret
  )
  api_key = env[:api_key]
  api_passphrase = env[:api_passphrase]
  api_timestamp = api_signature_response[:api_timestamp]
  api_signature = api_signature_response[:api_signature]

  "{
    \"type\": \"subscribe\",
    \"product_ids\": [
      \"#{product_id}\"
    ],
    \"channels\": [
      \"level2_batch\",
      \"ticker\",
      \"user\"
    ],
    \"key\": \"#{api_key}\",
    \"passphrase\": \"#{api_passphrase}\",
    \"timestamp\": \"#{api_timestamp}\",
    \"signature\": \"#{api_signature}\"
  }"
rescue Interrupt, StandardError => e
  Cryptum::Log.append(level: :error, msg: e, which_self: self)
end