Class: Cryptomarket::Websocket::TradingClient
- Inherits:
-
AuthClient
- Object
- ClientBase
- AuthClient
- Cryptomarket::Websocket::TradingClient
- Includes:
- Utils
- Defined in:
- lib/cryptomarket/websocket/tradingClient.rb
Overview
TradingClient connects via websocket to cryptomarket to enable the user to manage orders. uses SHA256 as auth method and authenticates automatically.
string
apiKey
-
the user api key
string
apiSecret
-
the user api secret
Proc
callback
-
Optional. A
Proc
to call with the client once the connection is established and the authentication is successful. if an error ocurrs is return as the fist parameter of the callback: callback(err, client)
Constant Summary
Constants included from Methods
Methods::CANDLES, Methods::MAP, Methods::ORDERBOOK, Methods::REPORTS, Methods::TICKERS, Methods::TRADES
Instance Method Summary collapse
-
#cancelOrder(clientOrderId, callback: nil) ⇒ Object
Cancel the order with ClientOrderId.
-
#createOrder(clientOrderId:, symbol:, side:, quantity:, type: nil, timeInForce: nil, price: nil, stopPrice: nil, expireTime: nil, strictValidate: nil, postOnly: nil, callback: nil) ⇒ Object
Create a new order.
-
#getActiveOrders(callback) ⇒ Object
Get the account active orders.
-
#getTradingBalance(callback) ⇒ Object
Get the user trading balance.
-
#initialize(apiKey:, apiSecret:) ⇒ TradingClient
constructor
Creates a new client.
-
#replaceOrder(clientOrderId:, requestClientId:, quantity:, price:, strictValidate: nil, callback: nil) ⇒ Object
Rewrites an order, canceling it or replacing it.
-
#subscribeToReports(callback, resultCallback = nil) ⇒ Object
Subscribe to a feed of trading events of the account.
Methods included from Utils
#extend_hash_with_order_params!, #extend_hash_with_pagination!
Methods inherited from AuthClient
#authenticate, #connect, #connected?
Methods inherited from ClientBase
#buildKey, #close, #connect, #connected?, #handle, #handleNotification, #handleResponse, #on_open, #onclose, #onclose=, #onconnect, #onconnect=, #onerror, #onerror=, #sendById, #sendSubscription, #sendUnsubscription, #storeAndSend
Methods included from Methods
#candlesFeed, #mapping, #orderbookFeed, #reportsFeed, #tradesFeed
Constructor Details
#initialize(apiKey:, apiSecret:) ⇒ TradingClient
Creates a new client
16 17 18 |
# File 'lib/cryptomarket/websocket/tradingClient.rb', line 16 def initialize(apiKey:, apiSecret:) super(url:"wss://api.exchange.cryptomkt.com/api/2/ws/trading", apiKey:apiKey, apiSecret:apiSecret) end |
Instance Method Details
#cancelOrder(clientOrderId, callback: nil) ⇒ Object
Cancel the order with ClientOrderId
Requires authentication
api.exchange.cryptomkt.com/#cancel-order
String
clientOrderId
-
The client order id of the order to cancel
Proc
callback
-
Optional. A
Proc
to call with the result data. It takes two arguments, err and result. err is None for successful calls, result is None for calls with error: Proc.new {|err, result| …}
67 68 69 |
# File 'lib/cryptomarket/websocket/tradingClient.rb', line 67 def cancelOrder(clientOrderId, callback:nil) sendById('cancelOrder', callback, {'clientOrderId' => clientOrderId}) end |
#createOrder(clientOrderId:, symbol:, side:, quantity:, type: nil, timeInForce: nil, price: nil, stopPrice: nil, expireTime: nil, strictValidate: nil, postOnly: nil, callback: nil) ⇒ Object
Create a new order
Requires authentication
api.exchange.cryptomkt.com/#place-new-order
String
clientOrderId
-
If given must be unique within the trading day, including all active orders. If not given, is generated by the server
String
symbol
-
Trading symbol
String
side
-
‘buy’ or ‘sell’
String
quantity
-
Order quantity
String
type
-
Optional. ‘limit’, ‘market’, ‘stopLimit’ or ‘stopMarket’. Default is ‘limit’
String
timeInForce
-
Optional. ‘GTC’, ‘IOC’, ‘FOK’, ‘Day’, ‘GTD’
String
price
-
Required for ‘limit’ and ‘stopLimit’. limit price of the order
String
stopPrice
-
Required for ‘stopLimit’ and ‘stopMarket’ orders. stop price of the order
String
expireTime
-
Required for orders with timeInForce = ‘GDT’
bool
strictValidate
-
Optional. If False, the server rounds half down for tickerSize and quantityIncrement. Example of ETHBTC: tickSize = ‘0.000001’, then price ‘0.046016’ is valid, ‘0.0460165’ is invalid
bool
postOnly
-
Optional. If True, your postOnly order causes a match with a pre-existing order as a taker, then the order will be cancelled
Proc
callback
-
Optional. A
Proc
to call with the result data. It takes two arguments, err and result. err is None for successful calls, result is None for calls with error: Proc.new {|err, result| …}
52 53 54 55 56 |
# File 'lib/cryptomarket/websocket/tradingClient.rb', line 52 def createOrder(clientOrderId:, symbol:, side:, quantity:, type:nil, timeInForce:nil, price:nil, stopPrice:nil, expireTime:nil, strictValidate:nil, postOnly:nil, callback:nil) params = {'symbol' => symbol, 'side' => side, 'quantity' => quantity, 'clientOrderId' => clientOrderId} extend_hash_with_order_params! params, type:type, timeInForce:timeInForce, price:price, stopPrice:stopPrice, expireTime:expireTime, strictValidate:strictValidate, postOnly:postOnly sendById('newOrder', callback, params) end |
#getActiveOrders(callback) ⇒ Object
Get the account active orders
Requires authentication
api.exchange.cryptomkt.com/#get-active-orders-2
Proc
callback
-
A
Proc
to call with the result data. It takes two arguments, err and result. err is None for successful calls, result is None for calls with error: Proc.new {|err, result| …}
106 107 108 |
# File 'lib/cryptomarket/websocket/tradingClient.rb', line 106 def getActiveOrders(callback) sendById('getOrders', callback) end |
#getTradingBalance(callback) ⇒ Object
Get the user trading balance
Requires authentication
api.exchange.cryptomkt.com/#get-trading-balance
Proc
callback
-
A
Proc
to call with the result data. It takes two arguments, err and result. err is None for successful calls, result is None for calls with error: Proc.new {|err, result| …}
118 119 120 |
# File 'lib/cryptomarket/websocket/tradingClient.rb', line 118 def getTradingBalance(callback) sendById('getTradingBalance', callback) end |
#replaceOrder(clientOrderId:, requestClientId:, quantity:, price:, strictValidate: nil, callback: nil) ⇒ Object
Rewrites an order, canceling it or replacing it
The Cancel/Replace request is used to change the parameters of an existing order and to change the quantity or price attribute of an open order
Do not use this request to cancel the quantity remaining in an outstanding order. Use the cancel_order for this purpose
It is stipulated that a newly entered order cancels a prior order that has been entered, but not yet executed
Requires authentication
api.exchange.cryptomkt.com/#cancel-replace-order
String
clientOrderId
-
The client id of the order to modify
String
requestClientId
-
The new id for the modified order
String
quantity
-
The new quantity of the order
String
price
-
The new price of the order
bool
strictValidate
-
Optional. If False, the server rounds half down for tickerSize and quantityIncrement. Example of ETHBTC: tickSize = ‘0.000001’, then price ‘0.046016’ is valid, ‘0.0460165’ is invalid
Proc
callback
-
Optional. A
Proc
to call with the result data. It takes two arguments, err and result. err is None for successful calls, result is None for calls with error: Proc.new {|err, result| …}
90 91 92 93 94 95 96 |
# File 'lib/cryptomarket/websocket/tradingClient.rb', line 90 def replaceOrder(clientOrderId:, requestClientId:, quantity:, price:, strictValidate:nil, callback:nil) params = {'clientOrderId' => clientOrderId, 'requestClientId' => requestClientId, 'quantity' => quantity, 'price' => price} if not strictValidate.nil? params['strictValidate'] = strictValidate end sendById('cancelReplaceOrder', callback, params) end |
#subscribeToReports(callback, resultCallback = nil) ⇒ Object
Subscribe to a feed of trading events of the account
Requires authentication
api.exchange.cryptomkt.com/#subscribe-to-reports
Proc
callback
-
A
Proc
to call with the result data. It takes one argument. a feed of reports Proc
resultCallback
-
Optional. A
Proc
to call with the result data. It takes two arguments, err and result. err is None for successful calls, result is None for calls with error: Proc.new {|err, result| …}
29 30 31 |
# File 'lib/cryptomarket/websocket/tradingClient.rb', line 29 def subscribeToReports(callback, resultCallback=nil) sendSubscription('subscribeReports', callback, {}, resultCallback) end |