Skip to content

itima/hitbtc_ruby

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

16 Commits

Repository files navigation

Summary

This document provides the complete reference for hitbtc API in the wrapper.

The following symbols are traded on hitbtc exchange.

SymbolLot sizePrice step
BTCUSD0.01 BTC0.01
BTCEUR0.01 BTC0.01
LTCBTC0.1 LTC0.00001
LTCUSD0.1 LTC0.001
LTCEUR0.1 LTC0.001
EURUSD1 EUR0.0001

Size representation:

  • Size values in streaming messages are represented in lots.
  • Size values in RESTful market data are represented in money (e.g. in coins or in USD).
  • Size values in RESTful trade are represented in lots (e.g. 1 means 0.01 BTC for BTCUSD)

Pending Future Updates

  • Solid trade execution functionality
  • payment api

Don't hesitate to contribute. If you liked it: BTC: 1PizgAWLJbwEsNWG9Cf27skcbgbgZGgeyK LTC: LQtM1t6BRd64scsdSBk8nnCLJuc8Qfhm53

Installation

Add this line to your application's Gemfile:

gem 'hitbtc' 

And then execute:

$ bundle 

Or install it yourself as:

$ gem install hitbtc 

Usage

Create a Kraken client:

API_KEY='3bH+M/nLp......'API_SECRET='wQG+7Lr9b.....'hitbtc=Hitbtc::Client.new(API_KEY,API_SECRET)time=hitbtc.server_timetime#=> 1393056191

Public Data Methods

Server Time

time=hitbtc.server_time

Symbol info

symbol=hitbtc.symbols("BTCEUR")symbols=hitbtc.symbols(["BTCEUR","BTCUSD"])all_symbols=hitbtc.symbols

Ticker

ticker_data=hitbtc.ticker('BTCEUR')
  • 24h means last 24h + last incomplete minute
  • high - highest trade price / 24 h
  • low - lowest trade price / 24 h
  • volume - volume / 24h

Order Book

order_book=hitbtc.order_book('BTCEUR')order_book=hitbtc.order_book('BTCEUR',{format_amount_unit: "lot"})
ParameterTypeDescription
format_priceoptional, "string" (default) or "number"
format_amountoptional, "string" (default) or "number"
format_amount_unitoptional, "currency" (default) or "lot"

Trades

trades=hitbtc.trades"BTCEUR"(defaultfrom1dayago,bytimestamp,index0,max_result1000)trades=hitbtc.trades'BTCEUR',(Time.now - 1.day).to_i,"ts",0,1000)trades=hitbtc.trades'BTCEUR',(Time.now - 1.day).to_i,"ts",0,1000,{format_amount_unit: "lot"})

Parameters:

ParameterTypeDescription
fromrequired, int, trade_id or timestampreturns trades with trade_id > specified trade_id
returns trades with timestamp >= specified timestamp
tilloptional, int, trade_id or timestampreturns trades with trade_id < specified trade_id
returns trades with timestamp < specified timestamp
byrequired, filter and sort by trade_id or ts (timestamp)
sortoptional, asc (default) or desc
start_indexrequired, intzero-based
max_resultsrequired, int, max value = 1000
format_itemoptional, "array" (default) or "object"
format_priceoptional, "string" (default) or "number"
format_amountoptional, "string" (default) or "number"
format_amount_unitoptional, "currency" (default) or "lot"
format_tidoptional, "string" or "number" (default)
format_timestampoptional, "millisecond" (default) or "second"
format_wrapoptional, "true" (default) or "false"

Private Data Methods

Error codes

RESTful Trading API can return the following errors:

HTTP codeTextDescription
403Invalid apikeyAPI key doesn't exist or API key is currently used on another endpoint (max last 15 min)
403Nonce has been usednonce is not monotonous
403Nonce is not validtoo big number or not a number
403Wrong signature

Execution reports

The API uses ExecutionReport as an object that represents change of order status.

The following fields are used in this object:

FieldDescriptionType / EnumRequired
orderIdOrder ID on the Exchangestringrequired
clientOrderIdclientOrderId sent in NewOrder messagestringrequired
execReportTypeexecution report typenew
canceled
rejected
expired
trade
status
required
orderStatusorder statusnew
partiallyFilled
filled
canceled
rejected
expired
required
orderRejectReasonRelevant only for the orders in rejected stateunknownSymbol
exchangeClosed
orderExceedsLimit
unknownOrder
duplicateOrder
unsupportedOrder
unknownAccount
other
for rejects
symbolstring, e.g. BTCUSDrequired
sidebuy or sellrequired
timestampUTC timestamp in milliseconds
pricedecimal
quantityintegerrequired
typeonly limit orders are currently supportedrequired
timeInForcetime in forceGTC - Good-Til-Canceled
IOK - Immediate-Or-Cancel
FOK - Fill-Or-Kill
DAY - day orders<
required
tradeIdTrade ID on the exchangefor trades
lastQuantityintegerfor trades
lastPricedecimalfor trades
leavesQuantityinteger
cumQuantityinteger
averagePricedecimal, will be 0 if 'cumQuantity'=0

Balance

all_balance=hitbtc.balanceone_balance=hitbtc.balance("BTC")many_balances=hitbtc.balance(["BTC","EUR"])

List of active orders

all_active_orders=hitbtc.active_orderssymbol_specific_orders=hitbtc.active_orders({symbols: "BTCEUR"})symbols_specific_orders=hitbtc.active_orders({symbols: "BTCEUR,BTCUSD"})

Parameters:

ParameterTypeDescription
symbolsstring, comma-delimeted list of symbols, optional, default - all symbols

Create Order

price should be specified even for market execution (haven't tested on a real order yet)

hitbtc.create_order({symbol: "BTCEUR",side: "buy",quantity: 1,type: "market",timeInForce: "GTC",price: 320.000})

Parameters:

ParameterTypeDescription
symbolstring, requirede.g. BTCUSD
sidebuy or sell, required
pricedecimal, requiredorder price, required for limit orders
quantityintorder quantity in lots
typelimit or marketorder type
timeInForceGTC - Good-Til-Canceled
IOK - Immediate-Or-Cancel
FOK - Fill-Or-Kill
DAY - day
use GTC by default

Cancel Order

You only need your order id (haven't been tested on real order yet)

hitbtc.cancel_order("1398804347")

Trades History

default=hitbtc.trade_historycustom=hitbtc.trade_history({by: "ts",start_index: 0,max_results: 10,symbols: "BTCEUR,BTCUSD"})

Parameters:

ParameterTypeDescription
bytrade_id or ts (timestamp)
start_indexint, optional, default(0)zero-based index
max_resultsint, required, <=1000
symbolsstring, comma-delimited
sortasc (default) or desc
fromoptionalstart trade_id or ts, see by
tilloptionalend trade_id or ts, see by

Recent Orders

default=hitbtc.recent_orderscustom=hitbtc.trade_history({start_index: 0,max_results: 10,symbols: "BTCEUR,BTCUSD",statuses: "new,filled"})

Parameters:

ParameterTypeDescription
start_indexint, optional, default(0)zero-based index
max_resultsint, required, <=1000
symbolsstring, comma-delimited
statusesstring, comma-delimited, new, partiallyFilled, filled, canceled, expired, rejected

About

ruby gem: api Wrapper for hitbtc

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby100.0%