App-cryp-arbit
view release on metacpan or search on metacpan
t/strategy-merge_order_book.t view on Meta::CPAN
gross_price => 491.1,
gross_price_orig => 491.1,
net_price => 491.9,
net_price_orig => 491.9,
quote_currency => "USD",
},
];
my $account_balances = {
indodax => {
ETH => [{account=>'i1', available=>0.15}, {account=>'i2', available=>0.03}],
},
'coinbase-pro' => {
USD => [{account=>'g1', available=>9999}],
},
};
my $correct_order_pairs = [
{
base_size => 0.15,
buy => {
account => "g1",
exchange => "coinbase-pro",
gross_price => 491.1,
gross_price_orig => 491.1,
net_price => 491.9,
net_price_orig => 491.9,
pair => "ETH/USD",
},
gross_profit_margin => 1.83262064752596,
gross_profit => 1.35,
trading_profit_margin => 1.62634681845904,
trading_profit => 1.2,
forex_spread => 0,
net_profit_margin => 1.62634681845904,
net_profit => 1.2,
sell => {
account => "i1",
exchange => "indodax",
gross_price => 500.1,
gross_price_orig => 5001000,
net_price => 499.9,
net_price_orig => 4999000,
pair => "ETH/IDR",
},
},
{
base_size => 0.03,
buy => {
account => "g1",
exchange => "coinbase-pro",
gross_price => 491.1,
gross_price_orig => 491.1,
net_price => 491.9,
net_price_orig => 491.9,
pair => "ETH/USD",
},
gross_profit_margin => 1.83262064752596,
gross_profit => 0.27,
trading_profit_margin => 1.62634681845904,
trading_profit => 0.24,
forex_spread => 0,
net_profit_margin => 1.62634681845904,
net_profit => 0.24,
sell => {
account => "i2",
exchange => "indodax",
gross_price => 500.1,
gross_price_orig => 5001000,
net_price => 499.9,
net_price_orig => 4999000,
pair => "ETH/IDR",
},
},
];
my ($order_pairs, $opp) = App::cryp::arbit::Strategy::merge_order_book::_calculate_order_pairs_for_base_currency(
base_currency => "ETH",
all_buy_orders => $all_buy_orders,
all_sell_orders => $all_sell_orders,
account_balances => $account_balances,
min_net_profit_margin => 0,
forex_spreads => {"USD/IDR"=>0},
);
is_deeply_float($order_pairs, $correct_order_pairs)
or diag explain $order_pairs;
};
subtest 'selling account balance (3: re-sorting)' => sub {
my $all_buy_orders = [
{
base_size => 0.2,
exchange => "indodax",
gross_price => 500.1,
gross_price_orig => 5001_000,
net_price => 499.9,
net_price_orig => 4999_000,
quote_currency => "IDR",
},
{
base_size => 0.9,
exchange => "indodax",
gross_price => 500.0,
gross_price_orig => 5000_000,
net_price => 499.8,
net_price_orig => 4998_000,
quote_currency => "IDR",
},
];
my $all_sell_orders = [
{
base_size => 1,
exchange => "coinbase-pro",
gross_price => 491.1,
gross_price_orig => 491.1,
net_price => 491.9,
net_price_orig => 491.9,
quote_currency => "USD",
},
];
my $account_balances = {
( run in 0.618 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )