Mexc 文档地址 https://mxcdevelop.github.io/APIDoc/
所有接口方法的初始化都与Mxc提供的方法相同。更多细节 src/api
大部分的接口已经完成,使用者可以根据我的设计方案继续扩展,欢迎与我一起迭代它。
QQ交流群:668421169
Exchanges 它包含以下所有交易所,强烈推荐使用该SDK。
composer require linwj/mxc
支持更多的请求设置
$mexc=new MxcSpot();
//or
$mexc=new MxcSpot($key,$secret);
//You can set special needs
$mexc->setOptions([
//Set the request timeout to 60 seconds by default
'timeout'=>10,
//https://github.com/guzzle/guzzle
'proxy'=>[],
//https://www.php.net/manual/en/book.curl.php
'curl'=>[],
//Set Demo Trading
'headers'=>['x-simulated-trading'=>1]
]);
Mxc 现货交易 API,支持现货V3接口
行情数据 More
$mexc=new MxcSpot($key,$secret);
try {
$result=$mexc->market()->getDeals([
'symbol'=>'btc_usdt',
'limit'=>2,
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$mexc->market()->getDepth([
'depth'=>2,
'symbol'=>'btc_usdt'
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$mexc->market()->getTicker([
'symbol'=>'btc_usdt',
'limit'=>2
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$mexc->market()->getKline([
'symbol'=>'btc_usdt',
'interval'=>'1h',
//'limit'=>10
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$mexc->market()->getSymbols();
print_r($result['data'][0]);
}catch (\Exception $e){
print_r($e->getMessage());
}
下单、撤单、查询订单 More
//Place an Order
try {
$result=$mexc->order()->postPlace([
'symbol'=>'EOS_USDT',
'price'=>'6',
'quantity'=>1,
'trade_type'=>'ASK',//BID=buy,ASK=sell
'order_type'=>'LIMIT_ORDER',//LIMIT_ORDER,POST_ONLY,IMMEDIATE_OR_CANCEL
//'client_order_id'=>''
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
sleep(1);
//Get order details by order ID.
try {
$result=$mexc->order()->getQuery([
'symbol'=>'EOS_USDT',
'order_ids'=>$result['data'],
//'client_order_ids'=>'',
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
sleep(1);
//Cancelling an unfilled order.
try {
$result=$mexc->order()->deleteCancel([
'symbol'=>'EOS_USDT',
'order_ids'=>$result['data'][0]['id'],
//'client_order_ids'=>'',
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
账户查询 More
try {
$result=$mexc->account()->getInfo();
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
行情数据 More
$mexc=new MxcContract();
try {
$result=$mexc->market()->getPing();
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}
try {
$result=$mexc->market()->getDetail();
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}
try {
$result=$mexc->market()->getSupportCurrencies();
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}
try {
$result=$mexc->market()->getDepth([
'symbol'=>'BTC_USDT',
'limit'=>2
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}
try {
$result=$mexc->market()->getDepthCommits([
'symbol'=>'BTC_USDT',
'limit'=>2
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}
try {
$result=$mexc->market()->getIndexPrice([
'symbol'=>'BTC_USDT',
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}
try {
$result=$mexc->market()->getFairPrice([
'symbol'=>'BTC_USDT',
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}
try {
$result=$mexc->market()->getFundingRate([
'symbol'=>'BTC_USDT',
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}
try {
$result=$mexc->market()->getKline([
'symbol'=>'BTC_USDT',
'interval'=>'Min60',
'start'=>'1616168957',
'end'=>'1616468957',
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}
下单、撤单、查询订单 More
$mexc=new MxcContract($key,$secret);
//order
try {
$result=$mexc->order()->postSubmit([
'symbol'=>'BTC_USDT',
'price'=>'5000',
'vol'=>'1',
'side'=>'1',
'type'=>'1',
'openType'=>'2',
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}
try {
$result=$mexc->order()->postCancel([
'symbol'=>'BTC_USDT',
'orderId'=>'xxxxxxxxxxx',
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}
try {
$result=$mexc->order()->postCancelAll([
'symbol'=>'BTC_USDT',
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}
//PlanOrder
try {
$result=$mexc->planorder()->getOrders([
'page_num'=>1,
'page_size'=>10,
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}
try {
$result=$mexc->planorder()->postPlace([
'symbol'=>'BTC_USDT',
'price'=>'5000',
'vol'=>'1',
'side'=>'1',
'openType'=>'2',
'triggerPrice'=>'5500',
'triggerType'=>'2',
'executeCycle'=>'1',
'orderType'=>'1',
'trend'=>'1',
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}
try {
$result=$mexc->planorder()->postCancel([
'symbol'=>'BTC_USDT',
'orderId'=>'xxxxxxxxxxx',
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}
//StopOrder
try {
$result=$mexc->stoporder()->getOrders([
'page_num'=>1,
'page_size'=>10,
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}
try {
$result=$mexc->stoporder()->postCancel([
'symbol'=>'BTC_USDT',
'orderId'=>'xxxxxxxxxxx',
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}
try {
$result=$mexc->stoporder()->postChangePrice([
'orderId'=>'xxxxxxxx',
'stopLossPrice'=>'5000',
'takeProfitPrice'=>'0',
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}
账户、仓位 More
$mexc=new MxcContract($key,$secret);
try {
$result=$mexc->position()->getHistoryPositions([
//'symbol'=>'BTC_USDT',
//'type'=>1,
'page_num'=>1,
'page_size'=>10,
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}
try {
$result=$mexc->account()->getAssets();
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}