Class: BittraderBot::BotLogic
- Inherits:
-
Object
- Object
- BittraderBot::BotLogic
- Defined in:
- lib/bittrader-bot/bot_logic.rb
Instance Attribute Summary collapse
-
#exchange ⇒ Object
readonly
Returns the value of attribute exchange.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#secret ⇒ Object
readonly
Returns the value of attribute secret.
-
#telegram_token ⇒ Object
readonly
Returns the value of attribute telegram_token.
Instance Method Summary collapse
-
#initialize(config) ⇒ BotLogic
constructor
Initializes a BotLogic object.
-
#send_get_request(host, request) ⇒ Object
Send GET request to exchange.
-
#send_post_request(data) ⇒ Object
Sends POST request to exchange.
-
#sign_post_data(data) ⇒ Object
Signs POST data using HMAC-SHA512 method.
-
#start_connection(host) ⇒ Object
Starts the connection to the server and provides identification.
Constructor Details
#initialize(config) ⇒ BotLogic
Initializes a BotLogic object
36 37 38 39 40 |
# File 'lib/bittrader-bot/bot_logic.rb', line 36 def initialize config @exchange = config['exchange'] @telegram_token = config['telegram_token'] @key = config['key'] end |
Instance Attribute Details
#exchange ⇒ Object (readonly)
Returns the value of attribute exchange.
32 33 34 |
# File 'lib/bittrader-bot/bot_logic.rb', line 32 def exchange @exchange end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
32 33 34 |
# File 'lib/bittrader-bot/bot_logic.rb', line 32 def key @key end |
#secret ⇒ Object (readonly)
Returns the value of attribute secret.
32 33 34 |
# File 'lib/bittrader-bot/bot_logic.rb', line 32 def secret @secret end |
#telegram_token ⇒ Object (readonly)
Returns the value of attribute telegram_token.
32 33 34 |
# File 'lib/bittrader-bot/bot_logic.rb', line 32 def telegram_token @telegram_token end |
Instance Method Details
#send_get_request(host, request) ⇒ Object
Send GET request to exchange
53 54 55 56 57 |
# File 'lib/bittrader-bot/bot_logic.rb', line 53 def send_get_request host, request https = start_connection host req = Net::HTTP::Get.new(request) https.request(req) end |
#send_post_request(data) ⇒ Object
Sends POST request to exchange
61 62 63 64 65 66 67 68 |
# File 'lib/bittrader-bot/bot_logic.rb', line 61 def send_post_request data request = Net::HTTP::Post.new(uri.path, initheader: {'Content-Type' =>'application/json'}) request['key'] = @key request['sign'] = sign_post_data(data.to_json) request.body = data.to_json response = https.request(request) puts "Response #{response.code} #{response.message}: #{response.body}" end |
#sign_post_data(data) ⇒ Object
Signs POST data using HMAC-SHA512 method
72 73 74 75 |
# File 'lib/bittrader-bot/bot_logic.rb', line 72 def sign_post_data data digest = OpenSSL::Digest.new('sha512') OpenSSL::HMAC.digest(digest, @secret, data) end |
#start_connection(host) ⇒ Object
Starts the connection to the server and provides identification
44 45 46 47 48 49 |
# File 'lib/bittrader-bot/bot_logic.rb', line 44 def start_connection host uri = URI.parse(host) https = Net::HTTP.new(uri.host, 443) https.use_ssl = true return https end |