MAX Exchange API Ruby SDK
A ruby implementation of MAX exchange API
- REST API V2
- Websocket API
Documentations
Supports
- Ruby 2.2 ~ 2.7, 3.0 ~ 3.3
Table of contents
- MAX Exchange API Ruby SDK
- Documentations
- Supports
- Table of contents
- Installation
- Usage
- Configuration
- Set timeout time
- Logging
- Public Api Examples
- GET /api/v2/vip_levels
- GET /api/v2/vip_levels/{level}
- GET /api/v2/currencies
- GET /api/v2/k
- GET /api/v2/depth
- GET /api/v2/trades
- GET /api/v2/markets
- GET /api/v2/summary
- GET /api/v2/tickers/{path_market}
- GET /api/v2/tickers
- GET /api/v2/timestamp
- GET /api/v3/wallet/m/limits
- Private Api Examples
- User
- GET /api/v2/members/profile
- GET /api/v2/members/me
- GET /api/v2/members/vip_level
- Account
- GET /api/v2/members/accounts
- GET /api/v2/members/accounts/{path_currency}
- Order
- GET /api/v2/orders
- GET /api/v2/order
- POST /api/v2/orders/clear
- POST /api/v2/order/delete
- POST /api/v2/orders
- POST /api/v2/orders/multi/onebyone
- Trade
- GET /api/v2/trades/my/of_order
- GET /api/v2/trades/my
- Deposit
- GET /api/v2/deposits
- GET /api/v2/deposit
- GET /api/v2/deposit_addresses
- POST /api/v2/deposit_addresses
- Withdrawal
- GET /api/v2/withdrawals
- GET /api/v2/withdrawal
- POST /api/v2/withdrawal
- GET /api/v2/withdraw_addresses
- Internal Transfer
- GET /api/v2/internal_transfers
- GET /api/v2/internal_transfer
- Reward
- GET /api/v2/rewards
- GET /api/v2/rewards/{path_reward_type}
- GET /api/v2/max_rewards/yesterday
- GET /api/v2/yields
- User
- Development
- Contributing
- License
Installation
gem 'max_exchange_api'And then execute:
$ bundle
Or install it yourself as:
$ gem install max_exchange_api
Usage
@public_api = MaxExchangeApi::PublicV2Api.new
@public_api.depth('usdttwd')
access_key, secret_key = File.read('secret').split(',')
@private_api = MaxExchangeApi::PrivateV2Api.new(access_key, secret_key)
@private_api.create_order!('usdttwd', 'sell', 1000, price: 31.35)
@private_api.create_order!('usdttwd', 'buy', 1000, price: 31.15)Configuration
Set timeout time
# Set default timeout time
MaxExchangeApi.default_config.timeout = 3 # seconds
# Create an api instance with custom timeout time
api = MaxExchangeApi::PublicV3Api.new(config: { timeout: 12 })
api = MaxExchangeApi::PrivateV3Api.new(access_key, secret_key, config: { timeout: 12 })Logging
require 'logger'
# Print log to standard output
MaxExchangeApi.default_config.logger = Logger.new(STDOUT)
# Print log to file
MaxExchangeApi.default_config.logger = Logger.new('log/api.log')
# Create an api instance with custom logger
api = MaxExchangeApi::PublicV3Api.new(config: { logger: Logger.new(STDOUT) })
api = MaxExchangeApi::PrivateV3Api.new(access_key, secret_key, config: { logger: Logger.new(STDOUT) })Public Api Examples
@api_v2 = MaxExchangeApi::PublicV2Api.new
@api_v3 = MaxExchangeApi::PublicV3Api.newGet all VIP level fees.
@api_v2.vip_levelsGet VIP level fee by level.
@api_v2.vip_levels(2)Get all available currencies.
@api_v2.currenciesGet OHLC(k line) of a specific market.
# use default parameters
@api_v2.k('btctwd')
# provide all possible parameters
@api_v2.k('btctwd', limit: 30, period: 1, timestamp: 1624705402)Get depth of a specified market.
# use default parameters
@api_v2.depth('maxtwd')
# provide all possible parameters
@api_v2.depth('maxtwd', limit: 10, sort_by_price: true)Get recent trades on market, sorted in reverse creation order.
# use default parameters
@api_v2.trades('btctwd')
# provide all possible parameters
@api_v2.trades(
'maxtwd',
timestamp: 1624705402,
from: 68444,
to: 69444,
order_by: 'asc',
pagination: true,
page: 3,
limit: 15,
offset: 5,
)Get all available markets.
@api_v2.marketsOverview of market data for all tickers.
@api_v2.summaryGet ticker of specific market.
@api_v2.tickers('btctwd')Get ticker of all markets.
@api_v2.tickersGet server current time, in seconds since Unix epoch.
@api_v2.timestampGet total available loan amount
@api_v3.available_loan_amountPrivate Api Examples
access_key = 'YOUR_ACCESS_KEY'
secret_key = 'YOUR_SECRET_KEY'
@api_v2 = MaxExchangeApi::PrivateV2Api.new(access_key, secret_key)
@api_v3 = MaxExchangeApi::PrivateV3Api.new(access_key, secret_key)User
get personal profile information
@api_v2.member_profileget your profile and accounts information
@api_v2.meget VIP level info
@api_v2.vip_levelAccount
get personal accounts information
@api_v2.accountsget personal accounts information of a currency
@api_v2.account(currnecy)Order
get your orders, results is paginated.
# use default parameters
@api_v2.orders('maxtwd')
# provide all possible parameters
@api.orders(
'maxtwd',
state: 'done',
order_by: 'desc',
group_id: 12345,
pagination: true,
page: 3,
limit: 15,
offset: 5,
)get a specific order.
# use max unique order id
@api.order(123456)
# use user specified order id
@api.order('MY_ORDER_123456', use_client_id: true)cancel all your orders with given market and side
# use default parameters
@api.cancel_orders!
# provide all possible parameters
@api.cancel_orders!(market: 'maxtwd', side: 'sell', group_id: '123456')cancel an order
# use max unique order id
@api.cancel_order!(123456)
# use user specified order id
@api.cancel_order!('MY_ORDER_123456', use_client_id: true)create a sell/buy order
# use default parameters
@api.create_order!('maxtwd', 'buy', 1000, price: 7.5)
# provide all possible parameters
@api.create_order!(
'maxtwd',
'buy',
1000,
price: 7.5,
client_oid: 'MY_ORDER_ID_12345',
stop_price: 8,
ord_type: 'limit',
group_id: 12345678,
)Create multiple sell/buy orders, orders may be partially accepted, please put your orders as an array in json body.
# use default parameters
@api.create_orders!('maxtwd', [
{ side: 'buy', volume: '1000', price: '7.5' },
{ side: 'buy', volume: '1500', price: '7.2' },
])
# provide all possible parameters
@api.create_orders!('maxtwd', [
{ side: 'buy', volume: '1000', price: '7.5', client_oid: 'MY_ORDER_ID_12345', stop_price: '8', ord_type: 'limit' },
{ side: 'buy', volume: '1500', price: '7.2', client_oid: 'MY_ORDER_ID_12346', stop_price: '8', ord_type: 'limit' },
], group_id: 12345)Trade
get your executed trades related to a order
# use max unique order id
@api_v2.my_trades_of_order(123456)
# use user specified order id
@api_v2.my_trades_of_order('MY_ORDER_123456', use_client_id: true)get your executed trades, sorted in reverse creation order
# use default parameters
@api_v2.my_trades('btctwd')
# provide all possible parameters
@api_v2.my_trades(
'maxtwd',
timestamp: 1624705402,
from: 68444,
to: 69444,
order_by: 'asc',
pagination: true,
page: 3,
limit: 15,
offset: 5,
)Deposit
get your deposits history
# use default parameters
@api_v2.deposits('max')
# provide all possible parameters
@api_v2.deposits(
'max',
'confirmed',
from: 68444,
to: 69444,
state: 'accepted',
pagination: true,
page: 3,
limit: 15,
offset: 5,
)get details of a specific deposit
@api_v2.deposit('transaction_id')The addresses could be empty before generated, please call POST /deposit_addresses in that case
# use default parameters
@api_v2.deposit_addresses
# provide all possible parameters
@api_v2.deposit_addresses(currency: 'twd', pagination: true, page: 3, limit: 15, offset: 5)Address creation is asynchronous, please call GET /deposit_addresses later to get generated addresses
@api_v2.create_deposit_addresses!('twd')Withdrawal
get your external withdrawals history
# use default parameters
@api_v2.withdrawals('max')
# provide all possible parameters
@api_v2.withdrawals(
'max',
'confirmed',
from: 68444,
to: 69444,
state: 'confirmed',
pagination: true,
page: 3,
limit: 15,
offset: 5,
)get details of a specific external withdraw
@api_v2.withdrawal('withdraw_id')submit a withdrawal. IP whitelist for api token is required.
@api_v2.create_withdrawal!('twd', 'withdraw_address_id', 100000)get withdraw addresses
# use default parameters
@api_v2.withdraw_addresses('twd')
# provide all possible parameters
@api_v2.withdraw_addresses('usdt', pagination: true, page: 3, limit: 15, offset: 5)Internal Transfer
get internal transfers history
# use default parameters
@api_v2.internal_transfers
# provide all possible parameters
@api_v2.internal_transfers(
currency: 'btc',
side: 'in',
from: 68444,
to: 69444,
pagination: true,
page: 3,
limit: 15,
offset: 5,
)get details of a specific internal transfer
@api_v2.internal_transfer('internal_transfer_id')Reward
get rewards history
# use default parameters
@api_v2.rewards
# provide all possible parameters
@api_v2.rewards(
currency: 'btc',
from: 68444,
to: 69444,
pagination: true,
page: 3,
limit: 15,
offset: 5,
)get specific rewards history
# use default parameters
@api_v2.rewards(reward_type: 'airdrop_rewards')
# provide all possible parameters
@api_v2.rewards(
reward_type: 'airdrop_rewards',
currency: 'btc',
from: 68444,
to: 69444,
pagination: true,
page: 3,
limit: 15,
offset: 5,
)get max rewards yesterday
@api_v2.max_rewards_yesterdayget yields history
# use default parameters
@api_v2.yields
# provide all possible parameters
@api_v2.yields(
currency: 'usdt',
from: 68444,
to: 69444,
pagination: true,
page: 3,
limit: 15,
offset: 5,
)Development
After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/khiav223577/max_exchange_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
License
The gem is available as open source under the terms of the MIT License.