📘
binance futures apiで過去のfunding rateを取る
ここでも Funding Rateの履歴は見れるけど
もっと長期の推移を見たかったので、メモ
この通りリクエストすればOK
例としてBTCドミナンスの履歴を取得
#!/usr/bin/perl
use strict;
use warnings;
use feature qw(:5.10);
use utf8;
use HTTP::Tiny;
use JSON;
use Time::Piece;
use Time::Seconds;
my $API_URL = "https://fapi.binance.com/fapi/v1/fundingRate";
my $SYMBOL = "BTCDOMUSDT";
my $start_time = (time() - ONE_YEAR)*1000;
say "unixtime_ms, funding_rate";
while(1){
my $json = decode_json(get_rate_history($start_time));
for (@{$json}){
say "$_->{fundingTime}, $_->{fundingRate}";
}
if (@{$json} == 0){
last;
}
$start_time = ${$json}[-1]->{fundingTime} + 1000;
}
sub get_rate_history {
my $time = shift;
my $http = HTTP::Tiny->new();
my $params = $http->www_form_urlencode({
symbol => $SYMBOL,
startTime => $time,
limit => 1000,
});
my $response = $http->get("$API_URL?$params");
if ($response->{success}){
return $response->{content};
}
else {
die "response error";
}
}
平均と標準偏差はこんな感じ
hist(history$funding_rate,breaks = 100)
summary(history$funding_rate)
sd(history$funding_rate)
> summary(history$funding_rate)
Min. 1st Qu. Median Mean 3rd Qu. Max.
-0.0022544 0.0001000 0.0001000 0.0002508 0.0003838 0.0069291
> sd(history$funding_rate)
[1] 0.0004453912
Discussion