App-cryp-exchange

 view release on metacpan or  search on metacpan

lib/App/cryp/Role/Exchange.pm  view on Meta::CPAN


 $xchg->create_limit_order(%args) => [$status, $reason, $payload, \%resmeta]

Create a buy/sell order at a specified price.

B<Specifying size (amount)>. When creating a buy order, some exchanges require
specifying size (amount) in quote currency, e.g. in BTC/USD pair when buying USD
we specify how much in USD we want to buy bitcoin. Some other exchanges require
specifying size in base currency, i.e. how many bitcoins we want to buy.
Similarly, when creating a sell order, some exchanges require specifying base
currency while others want size in quote currency. B<For flexibility, this role
method requires drivers to accept either base_size or quote_size.>

B<Minimum_size>. Exchanges have a minimum order size (amount) either in the
quote currency or base currency or both. Check the C<min_base_size> and
C<min_quote_size> field returned by L</"list_pairs">. The API server typically
will reject order when size is less than the minimum.

B<Maximum precision>. Exchanges also have restriction on the maximum precision
of price (see the C<quote_increment> field returned by L</"list_pairs">. For
example, if C<quote_increment> for C<BTC/USD> pair is 0.01 then the price
7000.51 is okay but 7000.526 is too precise. Some exchanges will reject
overprecise price, but some exchanges will simply round the price to the nearest
precision (e.g. 7000.524 to 7000.52) and some exchanges might round up or down
or truncate etc. B<For more consistent behavior, this role method requires
drivers to round down the overprecise price to the nearest quote increment.>

Known arguments (C<*> marks required arguments):

=over

=item * pair*

String. Pair.

=item * type*

String. Either "buy" or "sell".

=item * price*

Number. Price in the quote currency. If price is too precise, will be rounded
down to the nearest precision (see method description above for details).

=item * base_size

Specify amount to buy/sell in base currency. For example, in BTC/USD pair, we
specify how many bitcoins to buy or sell.

You have to specify one of base_size or quote_size, but not both.

=item * quote_size

Specify amount to buy/sell in quote currency. For example, in BTC/USD pair, we
specify how many USD to buy or sell bitcoins.

You have to specify one of base_size or quote_size, but not both.

=back

Some specific exchanges might require more credentials or arguments (e.g.
C<api_passphrase> on Coinbase Pro); please check with the specific drivers.

When successful, payload in response must be a hashref which contains at least
these keys: C<type> ("buy" or "sell"), C<pair>, C<order_id> (str, usually a
number, can also be a UUID, etc), C<price> (number, actual price of the order),
C<base_size> (actual size of the order, specified in base currency),
C<quote_size> (actual size of the order, specified in quote currency), C<status>
(current status of the order).

=head2 get_ticker

Usage:

 $xchg->get_ticker(%args) => [$status, $reason, $payload, \%resmeta]

Get a pair's last 24h price and volume information.

Known arguments (C<*> marks required arguments):

=over

=item * pair*

=back

When successful, payload in response must be a hashref which contains at least
these keys: C<high> (last 24h highest price), C<low> (last 24h lowest price),
C<last> (last trade's price), C<volume> (last 24h volume, in base currency),
C<buy> (last buy price), C<sell> (last sell price). Optional keys: C<open> (last
24h opening/first price), , C<quote_volume> (last 24h volume in quote currency).
Hash may contain additional keys. All prices are in quote currency, all volumes
(except C>quote_volume>) are in base currency.

=head2 data_canonical_currencies

Should return a hashref, a mapping between exchange-native currency codes to
canonical/standardized currency codes. All codes must be in uppercase. Used to
convert native pair/currency to canonical or vice versa. See also:
L</"data_reverse_canonical_currencies">.

=head2 data_native_pair_is_uppercase

Should return an integer value, 1 if native pair is in uppercase, 0 if native
pair is in lowercase. Used to convert native pair/currency to canonical or vice
versa.

=head2 data_native_pair_separator

Should return a single-character string. Used to convert native pair/currency to
canonical or vice versa.

=head2 data_reverse_canonical_currencies

Returns hashref, a mapping of canonical/standardized currency codes to exchange
native codes. All codes must be in uppercase. Used to convert native
pair/currency to canonical or vice versa.

This role already provides an implementation, which calculates the hashref by
reversing the hash returned by C</"data_canonical_currencies"> and caching the
result in the instance's C<_reverse_canonical_currencies> key. Driver can

lib/App/cryp/Role/Exchange.pm  view on Meta::CPAN


=item * detail

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:

=over

=item * name

str, pair name. Affected by the L</"native"> option.

=item * base_currency

str. Affected by the L</"native"> option.

=item * quote_currency

str. Affected by the L</"native"> option.

=item * min_base_size

Num, minimum order amount in the base currency.

=item * min_quote_size

Num, minimum order amount in the quote currency.

=item * quote_increment

Num, minimum increment in the quote currency.

=back

Record can contain additional keys.

=back

=head2 new

Usage:

 new(%args) => obj

Constructor. Known arguments (C<*> marks required arguments):

=over

=item * api_key

String. Required.

=item * api_secret

String. Required.

=back

Some specific exchanges might require more credentials or arguments (e.g.
C<api_passphrase> on GDAX); please check with the specific drivers.

Method must return object.

=head1 HOMEPAGE

Please visit the project's homepage at L<https://metacpan.org/release/App-cryp-exchange>.

=head1 SOURCE

Source repository is at L<https://github.com/perlancar/perl-App-cryp-exchange>.

=head1 BUGS

Please report any bugs or feature requests on the bugtracker website L<https://github.com/perlancar/perl-App-cryp-exchange/issues>

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.

=head1 SEE ALSO

=head1 AUTHOR

perlancar <perlancar@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2021, 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.

=cut



( run in 1.412 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )