GithubHelp home page GithubHelp logo

zhouaini528 / mxc-php Goto Github PK

View Code? Open in Web Editor NEW
16.0 2.0 10.0 52 KB

Mxc API Like the official document interface, Support for arbitrary extension.

License: MIT License

PHP 100.00%
mxc bitmex binance okex huobi exchanges mexc

mxc-php's Introduction

It is recommended that you read the official document first

Mexc docs https://mxcdevelop.github.io/APIDoc/

All interface methods are initialized the same as those provided by Mxc. See details src/api

Most of the interface is now complete, and the user can continue to extend it based on my design, working with me to improve it.

中文文档

Other exchanges API

Exchanges It includes all of the following exchanges and is highly recommended.

Bitmex Support Websocket

Okex Support Websocket

Huobi Support Websocket

Binance Support Websocket

Kucoin

Mexc

Coinbase

ZB

Bitfinex

Bittrex

Kraken

Gate

Bigone

Crex24

Bybit

Coinbene

Bitget

Poloniex

Installation

composer require linwj/mxc

Support for more request Settings

$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 Spot API,Support Spot V3

Order Book 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());
}

Order related API 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());
}

Accounts related API More

try {
    $result=$mexc->account()->getInfo();
    print_r($result);
}catch (\Exception $e){
    print_r($e->getMessage());
}

More Test

More Api

Mxc Contract API

Market 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));
}

Order 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));
}

Account and Position 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));
}

More Test

More Api

mxc-php's People

Contributors

zhouaini528 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

mxc-php's Issues

classs error

To keep track of composer installation, $mxc=new has bug in MxcSpot() operation.

Uncaught Error: Class 'MxcSpot' not found

'network' issue when has special character

I perform a withdrawal with MxcSpotV3 ->privates()->withdraw($data) and everything work fine except if I try to do anything with $data = ['network' => 'BEP20(BSC)'] or any network that contains special characters, like SPACE, or ' - '.

It made the query URL to be differ than expected:

API server expected: /api/v3/capital/withdraw/apply?coin=USDT&address=zzqqqqqqqqqq&amount=10&network=BEP20(BSC)&memo=MX10086&timestamp={{timestamp}}&signature={{signature}}

The real one with the mxc repo: /api/v3/capital/withdraw/apply?coin=USDT&address=zzqqqqqqqqqq&amount=10&network=BEP20%28BSC%29&memo=MX10086&timestamp={{timestamp}}&signature={{signature}}

It seems it can't convert these characters correct when pushing to the API servers. If I use the 'network' with simple type, such as ERC20, OP, MATIC, then there is no issue at all.

Can you take a look at this?

fatal error

what is wrong?

Fatal error:  Uncaught Error: Call to undefined method Lin\Mxc\MxcSpot::privates() in /www/exchanges/index2.php:8
Stack trace:
#0 {main}
  thrown in /www/exchanges/index2.php on line 8

code:

<pre>
<?php
require_once("vendor/autoload.php");
function br(){ echo "<br>"; }
use Lin\Mxc\MxcSpot;
$mexc=new MxcSpot("mx0vglbB9yc2Kg8KPD", "d7d377b9b66c42b4bff6a801eb62014b");
try {
    $result=$mexc->privates()->getAccount();
    print_r($result);
}catch (\Exception $e){
    echo "account:<br>";
    print_r(json_decode($e->getMessage(),true));
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.