{"action":"created","comment":{"url":"https://api.github.com/repos/bitex-la/bitex-bot/pulls/comments/214752073","pull_request_review_id":151863997,"id":214752073,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxNDc1MjA3Mw==","diff_hunk":"@@ -0,0 +1,143 @@\n+# Wrapper implementation for Bitex API.\n+# https://bitex.la/developers\n+class BitexApiWrapper < ApiWrapper\n+  attr_accessor :api_key, :ssl_version, :debug, :sandbox\n+\n+  def initialize(settings)\n+    self.api_key = settings.api_key\n+    self.ssl_version = settings.ssl_version\n+    self.debug = settings.debug\n+    self.sandbox = settings.sandbox\n+  end\n+\n+  def with_session\n+    prev_key = Bitex.api_key\n+    prev_sandbox = Bitex.sandbox\n+    Bitex.api_key = api_key\n+    Bitex.sandbox = sandbox\n+    yield.tap do\n+      Bitex.api_key = prev_key\n+      Bitex.sandbox = prev_sandbox\n+    end\n+  end\n+\n+  def profile\n+    with_session { Bitex::Profile.get }\n+  end\n+\n+  def amount_and_quantity(order_id)\n+    with_session do\n+      closes = user_transactions.select { |t| t.order_id.to_s == order_id }\n+      amount = closes.map { |c| c.usd.to_d }.sum.abs\n+      quantity = closes.map { |c| c.btc.to_d }.sum.abs\n+\n+      [amount, quantity]\n+    end\n+  end\n+\n+  def balance\n+    with_session { balance_summary_parser(profile) }\n+  end\n+\n+  def find_lost(type, price, _quantity)\n+    with_session { orders.find { |o| o.type == type && o.price == price && o.timestamp >= 5.minutes.ago.to_i } }\n+  end\n+\n+  def order_book\n+    with_session { order_book_parser(Bitex::MarketData.order_book) }\n+  end\n+\n+  def orders\n+    with_session { Bitex::Order.all.map { |o| order_parser(o) } }\n+  end\n+\n+  def send_order(type, price, quantity)\n+    { sell: Bitex::Ask, buy: Bitex::Bid }[type].create!(BitexBot::Settings.maker.order_book, quantity, price)\n+  end\n+\n+  def transactions\n+    with_session { Bitex::Trade.all.map { |t| transaction_parser(t) } }\n+  end\n+\n+  def user_transactions\n+    with_session { Bitex::Trade.all.map { |trade| user_transaction_parser(trade) } }\n+  end\n+\n+  # {\n+  #   usd_balance:               10000.00, # Total USD balance.\n+  #   usd_reserved:               2000.00, # USD reserved in open orders.\n+  #   usd_available:              8000.00, # USD available for trading.\n+  #   btc_balance:            20.00000000, # Total BTC balance.\n+  #   btc_reserved:            5.00000000, # BTC reserved in open orders.\n+  #   btc_available:          15.00000000, # BTC available for trading.\n+  #   fee:                            0.5, # Your trading fee (0.5 means 0.5%).\n+  #   btc_deposit_address: \"1XXXXXXXX...\"  # Your BTC deposit address.\n+  # }\n+  def balance_summary_parser(balances)\n+    BalanceSummary.new(\n+      Balance.new(balances[:btc_balance], balances[:btc_reserved], balances[:btc_available]),\n+      Balance.new(balances[:usd_balance], balances[:usd_reserved], balances[:usd_available]),\n+      balances[:fee]\n+    )\n+  end\n+\n+  def last_order_by(price)","path":"lib/bitex_bot/models/api_wrappers/bitex/bitex_api_wrapper.rb","position":84,"original_position":84,"commit_id":"dd4c8754480fd4f79fbca120fa56f9d3d175ddc6","original_commit_id":"dd4c8754480fd4f79fbca120fa56f9d3d175ddc6","user":{"login":"tmsrjs","id":865075,"node_id":"MDQ6VXNlcjg2NTA3NQ==","avatar_url":"https://avatars1.githubusercontent.com/u/865075?v=4","gravatar_id":"","url":"https://api.github.com/users/tmsrjs","html_url":"https://github.com/tmsrjs","followers_url":"https://api.github.com/users/tmsrjs/followers","following_url":"https://api.github.com/users/tmsrjs/following{/other_user}","gists_url":"https://api.github.com/users/tmsrjs/gists{/gist_id}","starred_url":"https://api.github.com/users/tmsrjs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tmsrjs/subscriptions","organizations_url":"https://api.github.com/users/tmsrjs/orgs","repos_url":"https://api.github.com/users/tmsrjs/repos","events_url":"https://api.github.com/users/tmsrjs/events{/privacy}","received_events_url":"https://api.github.com/users/tmsrjs/received_events","type":"User","site_admin":false},"body":"It seems this method was copied over from ItBitApiWrapper but it's not needed in this one.","created_at":"2018-09-03T20:17:46Z","updated_at":"2018-09-03T20:46:25Z","html_url":"https://github.com/bitex-la/bitex-bot/pull/63#discussion_r214752073","pull_request_url":"https://api.github.com/repos/bitex-la/bitex-bot/pulls/63","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/bitex-la/bitex-bot/pulls/comments/214752073"},"html":{"href":"https://github.com/bitex-la/bitex-bot/pull/63#discussion_r214752073"},"pull_request":{"href":"https://api.github.com/repos/bitex-la/bitex-bot/pulls/63"}}},"pull_request":{"url":"https://api.github.com/repos/bitex-la/bitex-bot/pulls/63","id":200748178,"node_id":"MDExOlB1bGxSZXF1ZXN0MjAwNzQ4MTc4","html_url":"https://github.com/bitex-la/bitex-bot/pull/63","diff_url":"https://github.com/bitex-la/bitex-bot/pull/63.diff","patch_url":"https://github.com/bitex-la/bitex-bot/pull/63.patch","issue_url":"https://api.github.com/repos/bitex-la/bitex-bot/issues/63","number":63,"state":"open","locked":false,"title":"Bitex wrapper","user":{"login":"juanszymczak","id":5303383,"node_id":"MDQ6VXNlcjUzMDMzODM=","avatar_url":"https://avatars1.githubusercontent.com/u/5303383?v=4","gravatar_id":"","url":"https://api.github.com/users/juanszymczak","html_url":"https://github.com/juanszymczak","followers_url":"https://api.github.com/users/juanszymczak/followers","following_url":"https://api.github.com/users/juanszymczak/following{/other_user}","gists_url":"https://api.github.com/users/juanszymczak/gists{/gist_id}","starred_url":"https://api.github.com/users/juanszymczak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juanszymczak/subscriptions","organizations_url":"https://api.github.com/users/juanszymczak/orgs","repos_url":"https://api.github.com/users/juanszymczak/repos","events_url":"https://api.github.com/users/juanszymczak/events{/privacy}","received_events_url":"https://api.github.com/users/juanszymczak/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-07-11T15:53:39Z","updated_at":"2018-09-03T20:46:25Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7b0fb0b9b584d91e85e83b3b16d775e571f1dfaa","assignee":{"login":"tmsrjs","id":865075,"node_id":"MDQ6VXNlcjg2NTA3NQ==","avatar_url":"https://avatars1.githubusercontent.com/u/865075?v=4","gravatar_id":"","url":"https://api.github.com/users/tmsrjs","html_url":"https://github.com/tmsrjs","followers_url":"https://api.github.com/users/tmsrjs/followers","following_url":"https://api.github.com/users/tmsrjs/following{/other_user}","gists_url":"https://api.github.com/users/tmsrjs/gists{/gist_id}","starred_url":"https://api.github.com/users/tmsrjs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tmsrjs/subscriptions","organizations_url":"https://api.github.com/users/tmsrjs/orgs","repos_url":"https://api.github.com/users/tmsrjs/repos","events_url":"https://api.github.com/users/tmsrjs/events{/privacy}","received_events_url":"https://api.github.com/users/tmsrjs/received_events","type":"User","site_admin":false},"assignees":[{"login":"tmsrjs","id":865075,"node_id":"MDQ6VXNlcjg2NTA3NQ==","avatar_url":"https://avatars1.githubusercontent.com/u/865075?v=4","gravatar_id":"","url":"https://api.github.com/users/tmsrjs","html_url":"https://github.com/tmsrjs","followers_url":"https://api.github.com/users/tmsrjs/followers","following_url":"https://api.github.com/users/tmsrjs/following{/other_user}","gists_url":"https://api.github.com/users/tmsrjs/gists{/gist_id}","starred_url":"https://api.github.com/users/tmsrjs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tmsrjs/subscriptions","organizations_url":"https://api.github.com/users/tmsrjs/orgs","repos_url":"https://api.github.com/users/tmsrjs/repos","events_url":"https://api.github.com/users/tmsrjs/events{/privacy}","received_events_url":"https://api.github.com/users/tmsrjs/received_events","type":"User","site_admin":false}],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/bitex-la/bitex-bot/pulls/63/commits","review_comments_url":"https://api.github.com/repos/bitex-la/bitex-bot/pulls/63/comments","review_comment_url":"https://api.github.com/repos/bitex-la/bitex-bot/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bitex-la/bitex-bot/issues/63/comments","statuses_url":"https://api.github.com/repos/bitex-la/bitex-bot/statuses/dd4c8754480fd4f79fbca120fa56f9d3d175ddc6","head":{"label":"bitex-la:bitex-wrapper","ref":"bitex-wrapper","sha":"dd4c8754480fd4f79fbca120fa56f9d3d175ddc6","user":{"login":"bitex-la","id":8069752,"node_id":"MDEyOk9yZ2FuaXphdGlvbjgwNjk3NTI=","avatar_url":"https://avatars2.githubusercontent.com/u/8069752?v=4","gravatar_id":"","url":"https://api.github.com/users/bitex-la","html_url":"https://github.com/bitex-la","followers_url":"https://api.github.com/users/bitex-la/followers","following_url":"https://api.github.com/users/bitex-la/following{/other_user}","gists_url":"https://api.github.com/users/bitex-la/gists{/gist_id}","starred_url":"https://api.github.com/users/bitex-la/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bitex-la/subscriptions","organizations_url":"https://api.github.com/users/bitex-la/orgs","repos_url":"https://api.github.com/users/bitex-la/repos","events_url":"https://api.github.com/users/bitex-la/events{/privacy}","received_events_url":"https://api.github.com/users/bitex-la/received_events","type":"Organization","site_admin":false},"repo":{"id":21983326,"node_id":"MDEwOlJlcG9zaXRvcnkyMTk4MzMyNg==","name":"bitex-bot","full_name":"bitex-la/bitex-bot","owner":{"login":"bitex-la","id":8069752,"node_id":"MDEyOk9yZ2FuaXphdGlvbjgwNjk3NTI=","avatar_url":"https://avatars2.githubusercontent.com/u/8069752?v=4","gravatar_id":"","url":"https://api.github.com/users/bitex-la","html_url":"https://github.com/bitex-la","followers_url":"https://api.github.com/users/bitex-la/followers","following_url":"https://api.github.com/users/bitex-la/following{/other_user}","gists_url":"https://api.github.com/users/bitex-la/gists{/gist_id}","starred_url":"https://api.github.com/users/bitex-la/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bitex-la/subscriptions","organizations_url":"https://api.github.com/users/bitex-la/orgs","repos_url":"https://api.github.com/users/bitex-la/repos","events_url":"https://api.github.com/users/bitex-la/events{/privacy}","received_events_url":"https://api.github.com/users/bitex-la/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bitex-la/bitex-bot","description":"Robot using bitex.la API ","fork":false,"url":"https://api.github.com/repos/bitex-la/bitex-bot","forks_url":"https://api.github.com/repos/bitex-la/bitex-bot/forks","keys_url":"https://api.github.com/repos/bitex-la/bitex-bot/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bitex-la/bitex-bot/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bitex-la/bitex-bot/teams","hooks_url":"https://api.github.com/repos/bitex-la/bitex-bot/hooks","issue_events_url":"https://api.github.com/repos/bitex-la/bitex-bot/issues/events{/number}","events_url":"https://api.github.com/repos/bitex-la/bitex-bot/events","assignees_url":"https://api.github.com/repos/bitex-la/bitex-bot/assignees{/user}","branches_url":"https://api.github.com/repos/bitex-la/bitex-bot/branches{/branch}","tags_url":"https://api.github.com/repos/bitex-la/bitex-bot/tags","blobs_url":"https://api.github.com/repos/bitex-la/bitex-bot/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bitex-la/bitex-bot/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bitex-la/bitex-bot/git/refs{/sha}","trees_url":"https://api.github.com/repos/bitex-la/bitex-bot/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bitex-la/bitex-bot/statuses/{sha}","languages_url":"https://api.github.com/repos/bitex-la/bitex-bot/languages","stargazers_url":"https://api.github.com/repos/bitex-la/bitex-bot/stargazers","contributors_url":"https://api.github.com/repos/bitex-la/bitex-bot/contributors","subscribers_url":"https://api.github.com/repos/bitex-la/bitex-bot/subscribers","subscription_url":"https://api.github.com/repos/bitex-la/bitex-bot/subscription","commits_url":"https://api.github.com/repos/bitex-la/bitex-bot/commits{/sha}","git_commits_url":"https://api.github.com/repos/bitex-la/bitex-bot/git/commits{/sha}","comments_url":"https://api.github.com/repos/bitex-la/bitex-bot/comments{/number}","issue_comment_url":"https://api.github.com/repos/bitex-la/bitex-bot/issues/comments{/number}","contents_url":"https://api.github.com/repos/bitex-la/bitex-bot/contents/{+path}","compare_url":"https://api.github.com/repos/bitex-la/bitex-bot/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bitex-la/bitex-bot/merges","archive_url":"https://api.github.com/repos/bitex-la/bitex-bot/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bitex-la/bitex-bot/downloads","issues_url":"https://api.github.com/repos/bitex-la/bitex-bot/issues{/number}","pulls_url":"https://api.github.com/repos/bitex-la/bitex-bot/pulls{/number}","milestones_url":"https://api.github.com/repos/bitex-la/bitex-bot/milestones{/number}","notifications_url":"https://api.github.com/repos/bitex-la/bitex-bot/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bitex-la/bitex-bot/labels{/name}","releases_url":"https://api.github.com/repos/bitex-la/bitex-bot/releases{/id}","deployments_url":"https://api.github.com/repos/bitex-la/bitex-bot/deployments","created_at":"2014-07-18T14:40:14Z","updated_at":"2018-08-29T13:05:27Z","pushed_at":"2018-08-31T20:51:28Z","git_url":"git://github.com/bitex-la/bitex-bot.git","ssh_url":"git@github.com:bitex-la/bitex-bot.git","clone_url":"https://github.com/bitex-la/bitex-bot.git","svn_url":"https://github.com/bitex-la/bitex-bot","homepage":"","size":757,"stargazers_count":4,"watchers_count":4,"language":"Ruby","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"archived":false,"open_issues_count":5,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":5,"open_issues":5,"watchers":4,"default_branch":"master"}},"base":{"label":"bitex-la:master","ref":"master","sha":"9280782d250c7f40633f731bf779ca64f0db6b14","user":{"login":"bitex-la","id":8069752,"node_id":"MDEyOk9yZ2FuaXphdGlvbjgwNjk3NTI=","avatar_url":"https://avatars2.githubusercontent.com/u/8069752?v=4","gravatar_id":"","url":"https://api.github.com/users/bitex-la","html_url":"https://github.com/bitex-la","followers_url":"https://api.github.com/users/bitex-la/followers","following_url":"https://api.github.com/users/bitex-la/following{/other_user}","gists_url":"https://api.github.com/users/bitex-la/gists{/gist_id}","starred_url":"https://api.github.com/users/bitex-la/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bitex-la/subscriptions","organizations_url":"https://api.github.com/users/bitex-la/orgs","repos_url":"https://api.github.com/users/bitex-la/repos","events_url":"https://api.github.com/users/bitex-la/events{/privacy}","received_events_url":"https://api.github.com/users/bitex-la/received_events","type":"Organization","site_admin":false},"repo":{"id":21983326,"node_id":"MDEwOlJlcG9zaXRvcnkyMTk4MzMyNg==","name":"bitex-bot","full_name":"bitex-la/bitex-bot","owner":{"login":"bitex-la","id":8069752,"node_id":"MDEyOk9yZ2FuaXphdGlvbjgwNjk3NTI=","avatar_url":"https://avatars2.githubusercontent.com/u/8069752?v=4","gravatar_id":"","url":"https://api.github.com/users/bitex-la","html_url":"https://github.com/bitex-la","followers_url":"https://api.github.com/users/bitex-la/followers","following_url":"https://api.github.com/users/bitex-la/following{/other_user}","gists_url":"https://api.github.com/users/bitex-la/gists{/gist_id}","starred_url":"https://api.github.com/users/bitex-la/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bitex-la/subscriptions","organizations_url":"https://api.github.com/users/bitex-la/orgs","repos_url":"https://api.github.com/users/bitex-la/repos","events_url":"https://api.github.com/users/bitex-la/events{/privacy}","received_events_url":"https://api.github.com/users/bitex-la/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bitex-la/bitex-bot","description":"Robot using bitex.la API ","fork":false,"url":"https://api.github.com/repos/bitex-la/bitex-bot","forks_url":"https://api.github.com/repos/bitex-la/bitex-bot/forks","keys_url":"https://api.github.com/repos/bitex-la/bitex-bot/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bitex-la/bitex-bot/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bitex-la/bitex-bot/teams","hooks_url":"https://api.github.com/repos/bitex-la/bitex-bot/hooks","issue_events_url":"https://api.github.com/repos/bitex-la/bitex-bot/issues/events{/number}","events_url":"https://api.github.com/repos/bitex-la/bitex-bot/events","assignees_url":"https://api.github.com/repos/bitex-la/bitex-bot/assignees{/user}","branches_url":"https://api.github.com/repos/bitex-la/bitex-bot/branches{/branch}","tags_url":"https://api.github.com/repos/bitex-la/bitex-bot/tags","blobs_url":"https://api.github.com/repos/bitex-la/bitex-bot/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bitex-la/bitex-bot/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bitex-la/bitex-bot/git/refs{/sha}","trees_url":"https://api.github.com/repos/bitex-la/bitex-bot/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bitex-la/bitex-bot/statuses/{sha}","languages_url":"https://api.github.com/repos/bitex-la/bitex-bot/languages","stargazers_url":"https://api.github.com/repos/bitex-la/bitex-bot/stargazers","contributors_url":"https://api.github.com/repos/bitex-la/bitex-bot/contributors","subscribers_url":"https://api.github.com/repos/bitex-la/bitex-bot/subscribers","subscription_url":"https://api.github.com/repos/bitex-la/bitex-bot/subscription","commits_url":"https://api.github.com/repos/bitex-la/bitex-bot/commits{/sha}","git_commits_url":"https://api.github.com/repos/bitex-la/bitex-bot/git/commits{/sha}","comments_url":"https://api.github.com/repos/bitex-la/bitex-bot/comments{/number}","issue_comment_url":"https://api.github.com/repos/bitex-la/bitex-bot/issues/comments{/number}","contents_url":"https://api.github.com/repos/bitex-la/bitex-bot/contents/{+path}","compare_url":"https://api.github.com/repos/bitex-la/bitex-bot/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bitex-la/bitex-bot/merges","archive_url":"https://api.github.com/repos/bitex-la/bitex-bot/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bitex-la/bitex-bot/downloads","issues_url":"https://api.github.com/repos/bitex-la/bitex-bot/issues{/number}","pulls_url":"https://api.github.com/repos/bitex-la/bitex-bot/pulls{/number}","milestones_url":"https://api.github.com/repos/bitex-la/bitex-bot/milestones{/number}","notifications_url":"https://api.github.com/repos/bitex-la/bitex-bot/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bitex-la/bitex-bot/labels{/name}","releases_url":"https://api.github.com/repos/bitex-la/bitex-bot/releases{/id}","deployments_url":"https://api.github.com/repos/bitex-la/bitex-bot/deployments","created_at":"2014-07-18T14:40:14Z","updated_at":"2018-08-29T13:05:27Z","pushed_at":"2018-08-31T20:51:28Z","git_url":"git://github.com/bitex-la/bitex-bot.git","ssh_url":"git@github.com:bitex-la/bitex-bot.git","clone_url":"https://github.com/bitex-la/bitex-bot.git","svn_url":"https://github.com/bitex-la/bitex-bot","homepage":"","size":757,"stargazers_count":4,"watchers_count":4,"language":"Ruby","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"archived":false,"open_issues_count":5,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":5,"open_issues":5,"watchers":4,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bitex-la/bitex-bot/pulls/63"},"html":{"href":"https://github.com/bitex-la/bitex-bot/pull/63"},"issue":{"href":"https://api.github.com/repos/bitex-la/bitex-bot/issues/63"},"comments":{"href":"https://api.github.com/repos/bitex-la/bitex-bot/issues/63/comments"},"review_comments":{"href":"https://api.github.com/repos/bitex-la/bitex-bot/pulls/63/comments"},"review_comment":{"href":"https://api.github.com/repos/bitex-la/bitex-bot/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bitex-la/bitex-bot/pulls/63/commits"},"statuses":{"href":"https://api.github.com/repos/bitex-la/bitex-bot/statuses/dd4c8754480fd4f79fbca120fa56f9d3d175ddc6"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"tmsrjs"}}