Class: Bitmex::Trade

Inherits:
Base
  • Object
show all
Defined in:
lib/bitmex/trade.rb

Overview

Individual and bucketed trades

Author:

  • Iulian Costan

Instance Attribute Summary

Attributes inherited from Base

#rest, #websocket

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Bitmex::Base

Instance Method Details

#all(filters = {}) {|Hash| ... } ⇒ Array

Get all trades

Examples:

Get first 10 traders starting Jan 1st for XBTUSD

client.trades.all symbol: 'XBTUSD', startTime: '2019-01-01', count: 10

Listen to all XBTUSD trades

client.trades.all symbol: 'XBTUSD' do |trade|
  puts trade.inspect
end

Parameters:

  • filters (Hash) (defaults to: {})

    the filters to apply to mostly REST API requests with a few exceptions

Options Hash (filters):

  • :symbol (String)

    the instrument symbol, this filter works in both REST and Websocket APIs

  • :filter (String)

    generic table filter, send key/value pairs Timestamp Filters

  • :columns (String)

    array of column names to fetch; if omitted, will return all columns.

  • :count (Double) — default: 100

    number of results to fetch.

  • :start (Double)

    Starting point for results.

  • :reverse (Boolean) — default: false

    if true, will sort results newest first.

  • :startTime (Datetime, String)

    Starting date filter for results.

  • :endTime (Datetime, String)

    Ending date filter for results

Yields:

  • (Hash)

    the trade

Returns:

  • (Array)

    the trades



15
16
17
18
19
20
21
# File 'lib/bitmex/trade.rb', line 15

def all(filters = {}, &ablock)
  if block_given?
    websocket.listen trade: filters[:symbol], &ablock
  else
    rest.get trade_path, params: filters
  end
end

#bucketed(bin_size = '1h', filters = {}) {|trade| ... } ⇒ Array

Get previous trades in time buckets

Examples:

Get last hour in 2018 and first hour in 2019 in reverse order

client.trades.bucketed '1h', symbol: 'XBTUSD', endTime: Date.new(2019, 1, 1), count: 2, reverse: true

Listen to bucketed trades

client.trades.bucketed '1h', symbol: 'XBTUSD' do |bucket|
  puts bucket.inspect
end

Parameters:

  • bin_size ('1m', '5m', '1h', '1d') (defaults to: '1h')

    the interval to bucket by

  • filters (Hash) (defaults to: {})

    the filters to apply to mostly REST API requests with a few exceptions

Options Hash (filters):

  • :symbol (String)

    the instrument symbol, this filter works in both REST and Websocket APIs

  • :filter (String)

    generic table filter, send key/value pairs Timestamp Filters

  • :columns (String)

    array of column names to fetch; if omitted, will return all columns.

  • :count (Double) — default: 100

    number of results to fetch.

  • :start (Double)

    Starting point for results.

  • :reverse (Boolean) — default: false

    if true, will sort results newest first.

  • :startTime (Datetime, String)

    Starting date filter for results.

  • :endTime (Datetime, String)

    Ending date filter for results

Yields:

  • (trade)

    the bucketed trade

Returns:

  • (Array)

    the trades by bucket



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/bitmex/trade.rb', line 34

def bucketed(bin_size = '1h', filters = {}, &ablock)
  check_binsize bin_size

  if block_given?
    topic = { "tradeBin#{bin_size}": filters[:symbol] }
    websocket.listen topic, &ablock
  else
    params = filters.merge binSize: bin_size
    rest.get trade_path(:bucketed), params: params
  end
end