<commit_before>use v6;
use WebService::Justcoin;

constant $API-KEY = "replaceme";
constant $SPEND-AMOUNT = 10.0; # NOK

# OK price for one definition of OK
sub find-ok-price(WebService::Justcoin $j) {

    my %btcnok = $j.markets(:id("BTCNOK"));
    
    die "didn't get BTCNOK market"
        unless %btcnok;

    my Rat $bid = +%btcnok{"bid"};
    my Rat $ask = +%btcnok{"ask"};

    my Rat $ok-price = ($bid + $ask) / 2;
    say "Bid is at $bid, ask is at $ask, our price: $ok-price";

    return $ok-price;
}

my $key = "2352ac37573e32915542af0f1a257061c78407332b2f98602724990ce562f9ff";
my $j = WebService::Justcoin.new(
        :url-get(&ugly-curl-get),
        :url-post(&ugly-curl-post),
        :api-key($key));

my $ok-price = find-ok-price($j);
my $btcamount = $SPEND-AMOUNT / $ok-price;

say "$SPEND-AMOUNT NOK should buy you $btcamount BTC";

my $order = $j.create-order(
        :market("BTCNOK"),
        :amount($btcamount),
        :type("bid"),
        :price($ok-price));
say "Order created, #", $order{"id"};

say "All orders: ";
say $j.orders().perl;

<commit_msg>removed my API key from sample...<commit_after>use v6;
use WebService::Justcoin;

constant $API-KEY = "replaceme";
constant $SPEND-AMOUNT = 10.0; # NOK

# OK price for one definition of OK
sub find-ok-price(WebService::Justcoin $j) {

    my %btcnok = $j.markets(:id("BTCNOK"));
    
    die "didn't get BTCNOK market"
        unless %btcnok;

    my Rat $bid = +%btcnok{"bid"};
    my Rat $ask = +%btcnok{"ask"};

    my Rat $ok-price = ($bid + $ask) / 2;
    say "Bid is at $bid, ask is at $ask, our price: $ok-price";

    return $ok-price;
}

my $j = WebService::Justcoin.new(
        :url-get(&ugly-curl-get),
        :url-post(&ugly-curl-post),
        :api-key($API-KEY));

my $ok-price = find-ok-price($j);
my $btcamount = $SPEND-AMOUNT / $ok-price;

say "$SPEND-AMOUNT NOK should buy you $btcamount BTC";

my $order = $j.create-order(
        :market("BTCNOK"),
        :amount($btcamount),
        :type("bid"),
        :price($ok-price));
say "Order created, #", $order{"id"};

say "All orders: ";
say $j.orders().perl;


{'fraction_non_alphanumeric': 0.18366383380547688, 'fraction_numerical': 0.02785646836638338, 'mean_word_length': 3.0593869731800765, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3697470', 'n_tokens_mistral': 892, 'n_tokens_neox': 824, 'n_words': 200}