The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Finance::Currency::FiatX::Role::Source - Role for FiatX sources

VERSION

This document describes version 0.006 of Finance::Currency::FiatX::Role::Source (from Perl distribution Finance-Currency-FiatX), released on 2018-06-24.

DESCRIPTION

All routines 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.

Some examples of enveloped result:

 [200, "OK", 14000]
 [404, "Not found"]

For more details about enveloped result, see Rinci::function.

REQUIRED ROUTINES

get_all_spot_rates

Usage:

 get_all_spot_rates() -> [$status, $reason, $payload [ , \%extra ] ]

Return spot rate for all currency pairs available for this sources. If the source provides a way to list all supported rates in a single API call or webpage, then this routine should return them. Otherwise, this routine should return status 412, e.g.

 [501, "Source does not offer a way to list all spot rates"]

Result payload is an array of hashes, where each hash must contain these keys: pair (str in the format of <from_currency>/<to_currency>, e.g. USD/IDR), rate (num, the rate), mtime (Unix epoch, last updated time for the rate, according to the source). type ("buy" or "sell").

get_spot_rate

Return spot (the latest) rate for a currency pair.

Usage:

 get_spot_rate($from, $to, $type) -> [$status, $reason, $payload [ , \%extra ] ]

$from and $to are currency codes, $type is either "buy" or "sell". If a source does not support the currency pair, routine must return status 501.

Result payload is hash that must contain these keys: pair (str in the format of <from_currency>/<to_currency>, e.g. USD/IDR), rate (num, the rate), mtime (Unix epoch, last updated time for the rate, according to the source). type ("buy" or "sell").

TODO: get_historical_rates

Usage:

 get_historical_rates($from, $to, $from_date, $to_date) -> [$status, $reason, $payload [ , \%extra ] ]

If source does not support historical rates, routine must return status 501.

BUGS

Please report all bug reports or feature requests to mailto:stevenharyanto@gmail.com.

AUTHOR

perlancar <perlancar@cpan.org>

COPYRIGHT AND LICENSE

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.