php请求okx接口获取比特币价格数据、k线数据

资讯 2024-06-24 阅读:27 评论:0
美化布局示例

欧易(OKX)最新版本

【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   全球官网 大陆官网

币安(Binance)最新版本

币安交易所app【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址

火币HTX最新版本

火币老牌交易所【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址

php请求okx接口获取比特币价格数据

环境

我本地用的是thinkphp框架和guzzle

I'm using the thinkphp frame and guzzle locally.

安装guzzle

Install Guzzle

 

配置请求头、签名

我们需要准备api_key,secret_key,passphrase

We need to prepare api_key, secret_key, passphrace

api_key,secret_key,passphrase需要我们自己注册账号去申请

官方文档

这是官方的要求
发起请求
所有REST私有请求头都必须包含以下内容:

This is an official request
to initiate a request
that all REST private requesters must include the following xff1a;

OK-ACCESS-KEY字符串类型的APIKey。

OK-ACCESS-KEY string type APIKey.

OK-ACCESS-SIGN使用HMAC SHA256哈希函数获得哈希值,再使用Base-64编码(请参阅签名)。

OK-ACCESS-SIGN uses the HMAC SHA256 Hashi function to obtain Hashi xff0c; again uses the Base-64 code xff08; see signature xff09;

OK-ACCESS-TIMESTAMP发起请求的时间(UTC),如:2020-12-08T09:08:57.715Z

OK-ACCESS-TIMESTAMP launch request time xff08; UTC) xff0c; e.g. xff1a; 2020-12-08T09:08:57.715Z

OK-ACCESS-PASSPHRASE您在创建API密钥时指定的Passphrase。

OK-ACCESS-PASSPHRASE, which you specified when creating the API key.

所有请求都应该含有application/json类型内容,并且是有效的JSON。

All requests should contain application/json type & #xff0c; and are valid JSON.

签名
生成签名

Sign
Generate signature

OK-ACCESS-SIGN的请求头是对timestamp + method + requestPath + body字符串(+表示字符串连接),以及SecretKey,使用HMAC SHA256方法加密,通过Base-64编码输出而得到的。

OK-ACCESS-SIGN's request header is Timestamp & #43; method & #43; requestPath & #43; body & #xff08; & #43; for string connections & #xff09; & #xff0c; and SecretKey & #xff0c; encrypted by HMAC SHA256 method xff0c; obtained through Base-64 coded output.

如:sign=CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA256(timestamp + ‘GET’ + ‘/api/v5/account/balance?ccy=BTC’, SecretKey))

e.g. xff1a; sign= CryptoJS.enc. Base64.stringify (CryptoJS. HmacSHA256 (timestamp & #43; `GET' & #43; `api/v5/acaccount/balance?ccy= BTC', SecretKey))

其中,timestamp的值与OK-ACCESS-TIMESTAMP请求头相同,为ISO格式,如2020-12-08T09:08:57.715Z。

Of which xff0c; Timestamp has the same value as OK-ACCESS-TIMESTAMP request head xff0c; is ISO format xff0c; e.g. 2020-12-08T09:08:57.715Z.

method是请求方法,字母全部大写:GET/POST。

Method is the request method xff0c; all letters capitalise xff1a; GET/POST.

requestPath是请求接口路径。如:/api/v5/account/balance

requestPath is the path to the request interface. e.g. & #xff1a;/api/v5/account/balance

body是指请求主体的字符串,如果请求没有主体(通常为GET请求)则body可省略。如:{“instId”:“BTC-USDT”,“lever”:“5”,“mgnMode”:“isolated”}

body means the string & #xff0c of the subject of the request; if there is no subject & #xff08; usually request & #xff09 for GET; and body can be omitted. e.g. & #xff1a; {InstID: {BTC-USDT" ), "lever": 5, "mgnMode":isolated}

设置签名
 
配置代理

请求国外接口需要配置一个代理,我这边本地配置了VPN,所以用的是本地的代理

Request an external interface to configure an agent & #xff0c; I localize VPN, so use local agents

 

全部代码

Res是一个返回类
res.php

Res is a returned class
res.php

 

okx.php控制器类

kx.php controller class

 

配置路由
route/app.php

Configure route
route/app.php

 

返回结果
在这里插入图片描述

returns result
 Insert picture description here /></p> 
<p>其他的接口我们只需要在官方文档中对应即可</p><p>We just need to match the other interfaces in the official document.</p>
                								<div class= 美化布局示例

欧易(OKX)最新版本

【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   全球官网 大陆官网

币安(Binance)最新版本

币安交易所app【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址

火币HTX最新版本

火币老牌交易所【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址
文字格式和图片示例

注册有任何问题请添加 微信:MVIP619 拉你进入群

弹窗与图片大小一致 文章转载注明

分享:

扫一扫在手机阅读、分享本文

发表评论
平台列表
美化布局示例

欧易(OKX)

  全球官网 大陆官网

币安(Binance)

  官网

火币(HTX)

  官网

Gate.io

  官网

Bitget

  官网

deepcoin

  官网
随机文章
热门文章
最近发表
标签列表