CCXT bitMEXでRateLimitチェック

BitMEXのAPIエラーにお悩みの方へ

#なにかAPIコール
bitmex.hogehoge()

#rate_limit は5分間にアクセス可能な回数
rate_limit = bitmex.last_response_headers['X-RateLimit-Limit']
#rate_remain はその残りの回数、
rate_remain = bitmex.last_response_headers['X-RateLimit-Remaining']
#rate_reset は、この時刻以降ならアクセスできることを示すunixtime
#制限を超えていない場合、この値は常に現在のタイムスタンプとなります
rate_reset = bitmex.last_response_headers['X-RateLimit-Reset']

rate_resetの時間過ぎたからrate_limit 回復した!とおもいきや
あくまで1回分回復するだけなので、使うとすぐ制限入り。
なので、余裕を持って待たないとあんま意味ない。

疑問:APIによって150回MAXのと300回MAXのとある?

疑問:開発環境と本番環境ではrate_limit 回復速度が違う!?

pythonで小数の比較するにはDecimalが必要

普通に比較したんじゃ、意図しない結果になる

import decimal

...

rate5MIN_10MA = 0.123

if decimal.Decimal(str(rate5MIN_10MA)) < decimal.Decimal(str(1.23)) :
        print('きたよ')

ポイント

  • decimalをインポートする
  • Decimalの引数文字列で指定する
  • 比較はDecimal型同士で行う

ファイルサイズの計算に fseek() および ftell() を使用しない

fseek() からのftell()は推奨されないそうです。

fstatを使うといいよ。

#include <io.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>  
#include <share.h>

FILE *fp;
long file_size;
char *buffer;
struct stat stbuf;
int fd;

fd = open("foo.bin", O_RDONLY);
if (fd == -1) {
  /* エラー処理 */
}

if (fstat(fd, &stbuf) == -1) {
  /* エラー処理 */
}

file_size = stbuf.st_size;

_close(fd);