Skip to content

khiav223577/max_exchange_api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

93 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MAX Exchange API Ruby SDK

Gem Version Build Status RubyGems Code Climate Test Coverage

A ruby implementation of MAX exchange API

  • REST API V2
  • Websocket API

Documentations

Supports

  • Ruby 2.2 ~ 2.7, 3.0

Installation

gem 'max_exchange_api'

And then execute:

$ bundle

Or install it yourself as:

$ gem install max_exchange_api

Configuration

Set timeout time

# Set default timeout time
MaxExchangeApi.default_config.timeout = 3 # seconds

# Create an api instance with custom timeout time
api = MaxExchangeApi::PublicApi.new(config: { timeout: 12 })
api = MaxExchangeApi::PrivateApi.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::PublicApi.new(config: { logger: Logger.new(STDOUT) })
api = MaxExchangeApi::PrivateApi.new(access_key, secret_key, config: { logger: Logger.new(STDOUT) })

Usage

Public Api Examples

@api = MaxExchangeApi::PublicApi.new

Get all VIP level fees.

Show code
@api.vip_levels

Get VIP level fee by level.

Show code
@api.vip_levels(2)

Get all available currencies.

Show code
@api.currencies

Get OHLC(k line) of a specific market.

Show code
# use default parameters
@api.k('btctwd')

# provide all possible parameters
@api.k('btctwd', limit: 30, period: 1, timestamp: 1624705402)

Get depth of a specified market.

Show code
# use default parameters
@api.depth('maxtwd')

# provide all possible parameters
@api.depth('maxtwd', limit: 10, sort_by_price: true)

Get recent trades on market, sorted in reverse creation order.

Show code
# use default parameters
@api.trades('btctwd')

# provide all possible parameters
@api.trades(
  'maxtwd', 
  timestamp: 1624705402,
  from: 68444,
  to: 69444,
  order_by: 'asc',
  pagination: true,
  page: 3,
  limit: 15,
  offset: 5,
)

Get all available markets.

Show code
@api.markets

Overview of market data for all tickers.

Show code
@api.summary

Get ticker of specific market.

Show code
@api.tickers('btctwd')

Get ticker of all markets.

Show code
@api.tickers

Get server current time, in seconds since Unix epoch.

Show code
@api.timestamp

Private Api Examples

access_key = 'YOUR_ACCESS_KEY'
secret_key = 'YOUR_SECRET_KEY'

@api = MaxExchangeApi::PrivateApi.new(access_key, secret_key)

Trade

get your executed trades related to a order

Show code
# use max unique order id
@api.my_trades_of_order(123456)

# use user specified order id
@api.my_trades_of_order('MY_ORDER_123456', use_client_id: true)

get your executed trades, sorted in reverse creation order

Show code
# use default parameters
@api.my_trades('btctwd')

# provide all possible parameters
@api.my_trades(
  'maxtwd',
  timestamp: 1624705402,
  from: 68444,
  to: 69444,
  order_by: 'asc',
  pagination: true,
  page: 3,
  limit: 15,
  offset: 5,
)

Withdrawal

get your external withdrawals history

Show code
# use default parameters
@api.withdrawals('max')

# provide all possible parameters
@api.withdrawals(
  'max',
  'confirmed',
  from: 68444,
  to: 69444,
  state: 'confirmed',
  pagination: true,
  page: 3,
  limit: 15,
  offset: 5,
)

get details of a specific external withdraw

Show code
@api.withdrawal('withdraw_id')

submit a withdrawal. IP whitelist for api token is required.

Show code
@api.create_withdrawal!('twd', 'withdraw_address_id', 100000)

Profile

get personal profile information

Show code
@api.member_profile

get your profile and accounts information

Show code
@api.me

get VIP level info

Show code
@api.vip_level

Account

get personal accounts information

Show code
@api.accounts

get personal accounts information of a currency

Show code
@api.account(currnecy)

Deposit

get your deposits history

Show code
# use default parameters
@api.deposits('max')

# provide all possible parameters
@api.deposits(
  'max',
  'confirmed',
  from: 68444,
  to: 69444,
  state: 'accepted',
  pagination: true,
  page: 3,
  limit: 15,
  offset: 5,
)

get details of a specific deposit

Show code
@api.deposit('transaction_id')

Address

The addresses could be empty before generated, please call POST /deposit_addresses in that case

Show code
# use default parameters
@api.deposit_addresses

# provide all possible parameters
@api.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

Show code
@api.create_deposit_addresses!('twd')

get withdraw addresses

Show code
# use default parameters
@api.withdraw_addresses('twd')

# provide all possible parameters
@api.withdraw_addresses('usdt', pagination: true, page: 3, limit: 15, offset: 5)

Internal Transfer

get internal transfers history

Show code
# use default parameters
@api.internal_transfers

# provide all possible parameters
@api.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

Show code
@api.internal_transfer('internal_transfer_id')

Reward

get rewards history

Show code
# use default parameters
@api.rewards

# provide all possible parameters
@api.rewards(
  currency: 'btc',
  from: 68444,
  to: 69444,
  pagination: true,
  page: 3,
  limit: 15,
  offset: 5,
)

get specific rewards history

Show code
# use default parameters
@api.rewards(reward_type: 'airdrop_rewards')

# provide all possible parameters
@api.rewards(
  reward_type: 'airdrop_rewards',
  currency: 'btc',
  from: 68444,
  to: 69444,
  pagination: true,
  page: 3,
  limit: 15,
  offset: 5,
)

get max rewards yesterday

Show code
@api.max_rewards_yesterday

get yields history

Show code
# use default parameters
@api.yields

# provide all possible parameters
@api.yields(
  currency: 'usdt',
  from: 68444,
  to: 69444,
  pagination: true,
  page: 3,
  limit: 15,
  offset: 5,
)

Order

get your orders, results is paginated.

Show code
# use default parameters
@api.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.

Show code
# 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

Show code
# use default parameters
@api.cancel_orders!

# provide all possible parameters
@api.cancel_orders!(market: 'maxtwd', side: 'sell', group_id: '123456')

cancel an order

Show code
# 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

Show code
# 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.

Show code
# 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)

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.