App::cryp::Role::Exchange - Role for interacting with an exchange
This document describes version 0.001 of App::cryp::Role::Exchange (from Perl distribution App-cryp-exchange), released on 2018-04-04.
This role describes the common API for interacting with an exchange that all App::cryp::Exchange::* modules follow.
App::cryp::Exchange::*
All methods, unless specified otherwise, must return enveloped result:
[$status, $reason, $payload, \%extra]
This result is analogous to an HTTP response; in fact $status mostly uses HTTP response codes. $reason is analogous to HTTP status message. $payload is the actual content (optional if $status is error status). %extra is optional and analogous to HTTP response headers to specify flags or attributes or other metadata.
$status
$reason
$payload
%extra
Some examples of enveloped result:
[200, "OK", ["BTC/USD", "ETH/BTC"]] [404, "Not found"]
For more details about enveloped result, see Rinci::function.
Usage:
$xchg->to_canonical_currency($cur) => str
Convert native currency code to canonical/standardized currency code. Canonical codes are listed in CryptoCurrency::Catalog.
$xchg->to_native_currency($cur) => str
Convert canonical/standardized currency code to exchange-native currency code. Canonical codes are listed in CryptoCurrency::Catalog.
$xchg->to_canonical_pair($pair) => str
$xchg->to_native_pair($pair) => str
new(%args) => obj
Constructor. Known arguments:
api_key
String. Required.
api_secret
Some specific exchanges might require more credentials or arguments; please check with the specific drivers.
Method must return object.
Should return a single-character string.
Should return a hashref, a mapping between exchange-native currency codes to canonical/standardized currency codes.
Returns hashref, a mapping of canonical/standardized currency codes to exchange native codes, which is produced by reversing the hash returned by /"data_canonical_currencies" and caching the result in the instance's _reverse_canonical_currencies key. Driver can provide its own implementation.
/"data_canonical_currencies"
_reverse_canonical_currencies
$xchg->list_pairs => [$status, $reason, $payload, \%resmeta]
List all pairs available for trading.
Method must return enveloped result. Payload must be an array containing pair names (except when detail argument is set to true, in which case method must return array of records/hashrefs).
detail
Pair names must be in the form of <currency1>/<currency2> where <currency2> is the base currency code. Currency codes must follow list in CryptoCurrency::Catalog. Some example pair names: BTC/USD, ETH/BTC.
Known options:
native
Boolean. Default 0. If set to 1, method must return pair codes in native exchange form instead of canonical/standardized form.
Boolean. Default 0. If set to 1, method must return array of records/hashrefs instead of just array of strings (pair names).
Record must contain these keys: name (pair name, str). Record can contain additional keys.
name
$xchg->get_order_book => [$status, $reason, $payload, \%resmeta]
Method should return payload as an array of hashrefs. Each hashref (record) should contain these keys: type (str, either "buy" or "sell"), price (float), amount (float). Buy (bid, purchase) records must be sorted from highest price to lowest price. Sell (ask, offer) records must be sorted from lowest price to highest.
type
price
amount
pair
String. Pair.
String. Can be set to "buy" or "sell" to filter only return buy records or sell records respectively.
Please visit the project's homepage at https://metacpan.org/release/App-cryp-exchange.
Source repository is at https://github.com/perlancar/perl-App-cryp-exchange.
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=App-cryp-exchange
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
perlancar <perlancar@cpan.org>
This software is copyright (c) 2018 by perlancar@cpan.org.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install App::cryp::exchange, copy and paste the appropriate command in to your terminal.
cpanm
cpanm App::cryp::exchange
CPAN shell
perl -MCPAN -e shell install App::cryp::exchange
For more information on module installation, please visit the detailed CPAN module installation guide.