Struct DMBCS_KRAKEN_API::Kraken_API
source · [−]pub struct Kraken_API { /* private fields */ }
Expand description
A handle on the connection to the Kraken exchange.
This can be used multiple times, so should only be instantiated once, preferably using the connect function; due to the nature of the exchange and the REST API it does not make sense to make multiple requests in parallel, and so there should be no need for more than one of these objects to be instantiated.
This object has a method implemented on it for every end-point in the Kraken API, which will make the call to the exchange as appropriate and marshall the returned data through the method’s return object, described below.
Optional arguments
Many of the Kraken functions (end-points) can take optional extra arguments. These are set into the Kraken_API object prior to making a function call, and then those arguments which have been set and are pertinent to that function will be passed along. The documentation for the individual functions below indicates the options pertinent to that function.
The set of optional arguments persist between function calls: this may work in your favour or against you depending on your work flow. In any case, use the methods Kraken_API::set_opt, Kraken_API::clear_opt and Kraken_API::clear_all_options to manipulate the current option set.
Errors
Errors which occur at our end, such as failure to contact the Kraken
exchange, or to perform our own processing, are signalled by returns of
Result::Err(String)
in which the string is a human-readable explanation of
the problem.
Errors which occur at the Kraken exchange, such as failure to authenticate
the user, are signalled by an ‘error’ entry in the JSON string returned as a
Result::Ok(String)
.
A successful return of data from the exchange will be seen with a ‘result’
section in the JSON string returned as Result::Ok(String)
.
Implementations
sourceimpl Kraken_API
impl Kraken_API
sourcepub fn set_opt<T: Display>(&mut self, opt: API_Option, value: T)
pub fn set_opt<T: Display>(&mut self, opt: API_Option, value: T)
Give a value to the optional argument, which may be passed to the Kraken end-point if the end-point accepts this option.
sourcepub fn clear_opt(&mut self, opt: API_Option)
pub fn clear_opt(&mut self, opt: API_Option)
Clear an option; this will not be sent to any end-points which would accept such an optional argument.
sourcepub fn clear_all_options(&mut self)
pub fn clear_all_options(&mut self)
The options set in a Kraken_API object are persistent across back-end calls; it may be prudent to call this method to make sure the set of options is in a well-known state, before making settings for the next back-end call.
sourcepub fn account_balance(&mut self) -> Result<String, String>
pub fn account_balance(&mut self) -> Result<String, String>
Retrieve all cash balances.
Here is the Kraken documentation.
sourcepub fn trade_balance(&mut self) -> Result<String, String>
pub fn trade_balance(&mut self) -> Result<String, String>
Get a summary of standing with an asset.
Here is the Kraken documentation.
This function understands the API_Option::ASSET optional argument.
sourcepub fn open_orders(&mut self) -> Result<String, String>
pub fn open_orders(&mut self) -> Result<String, String>
Get detailed information about currently open orders.
The Kraken documentation is here.
The end-point is responsive to the API_Option::TRADES and API_Option::USERREF optional arguments.
sourcepub fn closed_orders(&mut self) -> Result<String, String>
pub fn closed_orders(&mut self) -> Result<String, String>
Get a detailed list of closed orders, paged to up to 50 at a time.
Here is the Kraken documentation.
This function accepts API_Option::TRADES, API_Option::USERREF, API_Option::START, API_Option::END, API_Option::OFS, and API_Option::CLOSE_TIME optional arguments.
sourcepub fn query_orders(&mut self, txid: String) -> Result<String, String>
pub fn query_orders(&mut self, txid: String) -> Result<String, String>
Get a list of order details.
This function is variously known in the Kraken documentation as ‘Query Orders Info’, ‘GetOrdersInfo’ and ‘QueryOrders’.
We see that ‘txid’ can be a comma-separated list of transaction identifiers, and that options API_Option::TRADES and API_Option::USERREF can optionally be set in the ‘self’ Kraken_API object prior to this call.
sourcepub fn trades_history(&mut self) -> Result<String, String>
pub fn trades_history(&mut self) -> Result<String, String>
Get a detailed list of past trades, paged to up to 50 at a time.
The upstream documentation is here.
The function accepts API_Option::TYPE, API_Option::TRADES, API_Option::START, API_Option::END, and API_Option::OFS optional arguments.
sourcepub fn trades_info(&mut self, txid: String) -> Result<String, String>
pub fn trades_info(&mut self, txid: String) -> Result<String, String>
Get information about specific trades.
This function is known in the Kraken documentation as ‘getTradesInfo’, ‘QueryTrades’ and ‘Query Trades Info’.
We see that ‘txid’ can be a comma-separated list of transaction IDs, and the function accepts the API_Option::TRADES option, a string holding either “true” or “false”.
sourcepub fn open_margin_positions(&mut self) -> Result<String, String>
pub fn open_margin_positions(&mut self) -> Result<String, String>
This function is for getting information about open margin positions.
The end-point documentation is at Kraken, where it is known as ‘getOpenPositions’.
The method is sensitive to the optional arguments API_Option::TXID, API_Option::DO_CALCS and API_Option::CONSOLIDATION.
sourcepub fn ledgers_info(&mut self) -> Result<String, String>
pub fn ledgers_info(&mut self) -> Result<String, String>
Retrieve information about ledger entries.
This end-point is known variously as “GetLedgersInfo”, “getLedgers” and “Ledgers” in the Kraken documentation.
The function is sensitive to the API_Option::ACLASS, API_Option::ASSET, API_Option::TYPE, API_Option::START, API_Option::END and API_Option::OFS optional arguments.
sourcepub fn query_ledgers(&mut self) -> Result<String, String>
pub fn query_ledgers(&mut self) -> Result<String, String>
Retrieve information about specific ledger entries.
Here is the Kraken documentation.
This is sensitive to the API_Option::TRADES and API_Option::ID optional arguments.
sourcepub fn trade_volume(&mut self, pair: &str) -> Result<String, String>
pub fn trade_volume(&mut self, pair: &str) -> Result<String, String>
Get trade volue.
Documented at Kraken.
The pair argument is the trading pair, e.g., “XETCXETH”, for which data are required.
The function also accepts the API_Option::FEE_INFO optional argument, to indicate that fee information should be included in the returned result set.
sourcepub fn request_export_report(
&mut self,
report_type: Report_Type,
description: &str
) -> Result<String, String>
pub fn request_export_report(
&mut self,
report_type: Report_Type,
description: &str
) -> Result<String, String>
Request export of trades or ledgers.
The upstream documentation is here.
Also uses the API_Option::FORMAT, API_Option::FIELDS, API_Option::START_TIME and API_Option::END_TIME optional arguments.
sourcepub fn get_export_report_status(
&mut self,
report_type: Report_Type
) -> Result<String, String>
pub fn get_export_report_status(
&mut self,
report_type: Report_Type
) -> Result<String, String>
Get status of requested data exports.
The Kraken documentation is here.
sourcepub fn retrieve_data_export(&mut self, id: &str) -> Result<String, String>
pub fn retrieve_data_export(&mut self, id: &str) -> Result<String, String>
Retrieve a processed data export.
The end-point documentation is here.
sourcepub fn delete_export_report(
&mut self,
id: &str,
type_: &str
) -> Result<String, String>
pub fn delete_export_report(
&mut self,
id: &str,
type_: &str
) -> Result<String, String>
Delete an exported data report.
Here is the upstream documentation.
NOTE that type MUST be one of the strings “delete” or “cancel”, or a panic may occur.
sourcepub fn add_order<V: Display>(
&mut self,
order_type: Order_Type,
direction: Instruction,
volume: V,
pair: &str
) -> Result<String, String>
pub fn add_order<V: Display>(
&mut self,
order_type: Order_Type,
direction: Instruction,
volume: V,
pair: &str
) -> Result<String, String>
Place a new order onto the exchange’s order book.
The upstream documentation is here.
The following optional arguments are considered by this end-point: API_Option::USERREF, API_Option::PRICE, API_Option::PRICE_2, API_Option::TRIGGER, API_Option::LEVERAGE, API_Option::OFLAGS, API_Option::TIME_IN_FORCE, API_Option::START_TIME, API_Option::EXPIRE_TIME, API_Option::CLOSE_TYPE, API_Option::CLOSE_PRICE_1, API_Option::CLOSE_PRICE_2, API_Option::DEADLINE, and API_Option::VALIDATE.
sourcepub fn edit_order<V: Display>(
&mut self,
tx_id: &str,
pair: &str
) -> Result<String, String>
pub fn edit_order<V: Display>(
&mut self,
tx_id: &str,
pair: &str
) -> Result<String, String>
Edit an order on the exchange’s order book.
The upstream documentation is here.
The following optional arguments are considered by this end-point: API_Option::USERREF, API_Option::PRICE, API_Option::PRICE_2, API_Option::OFLAGS, API_Option::VOLUME, API_Option::DEADLINE, API_Option::CANCEL_RESPONSE, and API_Option::VALIDATE.
sourcepub fn cancel_order(&mut self, txid: &str) -> Result<String, String>
pub fn cancel_order(&mut self, txid: &str) -> Result<String, String>
Cancel an open order.
The documentation for this end-point is at Kraken. Note that ‘txid’ can actually be a ‘userref’, in which case all open orders for that user are cancelled.
sourcepub fn cancel_all_orders(&mut self) -> Result<String, String>
pub fn cancel_all_orders(&mut self) -> Result<String, String>
Cancel all orders open on this account.
The documentation for this end-point is at Kraken.
sourcepub fn cancel_all_orders_after_x(
&mut self,
timeout: isize
) -> Result<String, String>
pub fn cancel_all_orders_after_x(
&mut self,
timeout: isize
) -> Result<String, String>
Dead man’s switch will cancel all orders after a time if not reset.
The upstream documentation is here.
sourcepub fn server_time(&mut self) -> Result<String, String>
pub fn server_time(&mut self) -> Result<String, String>
Get the server’s time. Documented upstream here.
sourcepub fn system_status(&mut self) -> Result<String, String>
pub fn system_status(&mut self) -> Result<String, String>
Get the current exchange system status.
Documented upstream here.
sourcepub fn asset_info(&mut self) -> Result<String, String>
pub fn asset_info(&mut self) -> Result<String, String>
Get information about the assets that are available at this time at this exchange.
The upstream documentation is here.
The function is responsive to the API_Option::ACLASS and API_Option::ASSET optional arguments.
sourcepub fn asset_pairs(&mut self) -> Result<String, String>
pub fn asset_pairs(&mut self) -> Result<String, String>
Get tradable asset pairs.
Documented at Kraken.
The optional arguments API_Option::INFO and API_Option::PAIR will be used if set.
sourcepub fn ticker_info(&mut self, pair: String) -> Result<String, String>
pub fn ticker_info(&mut self, pair: String) -> Result<String, String>
Get ticker information.
The upstream documentation is here.
sourcepub fn ohlc_data(&mut self, pair: String) -> Result<String, String>
pub fn ohlc_data(&mut self, pair: String) -> Result<String, String>
Get OLHC (open, low, high, close) data.
The end-point is documented upstream here.
The method respects the optional arguments API_Option::INTERVAL and API_Option::SINCE.
sourcepub fn order_book(&mut self, pair: String) -> Result<String, String>
pub fn order_book(&mut self, pair: String) -> Result<String, String>
Get live order book data.
Upstream documentation is at Kraken.
This end-point uses the optional argument API_Option::COUNT to limit the depth of data into the order book.
sourcepub fn recent_trades(&mut self, pair: String) -> Result<String, String>
pub fn recent_trades(&mut self, pair: String) -> Result<String, String>
Get recent trades made at the exchange.
Documented upstream.
Allows the optional argument API_Option::SINCE.
Trait Implementations
sourceimpl Default for Kraken_API
impl Default for Kraken_API
sourcefn default() -> Kraken_API
fn default() -> Kraken_API
Returns the “default value” for a type. Read more
Auto Trait Implementations
impl RefUnwindSafe for Kraken_API
impl Send for Kraken_API
impl Sync for Kraken_API
impl Unpin for Kraken_API
impl UnwindSafe for Kraken_API
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more