diff --git a/app/api/v2/account/withdraws.rb b/app/api/v2/account/withdraws.rb index eae682285b..ac34044cca 100644 --- a/app/api/v2/account/withdraws.rb +++ b/app/api/v2/account/withdraws.rb @@ -47,7 +47,7 @@ class Withdraws < Grape::API desc: 'Wallet address on the Blockchain.' requires :currency, type: String, - values: { value: -> { Currency.coins.codes(bothcase: true) }, message: 'account.withdraw.currency_doesnt_exist'}, + values: { value: -> { Currency.coins.codes(bothcase: true) }, message: 'account.currency.doesnt_exist'}, desc: 'The currency code.' requires :amount, type: { value: BigDecimal, message: 'account.withdraw.non_decimal_amount' }, diff --git a/app/api/v2/helpers.rb b/app/api/v2/helpers.rb index 71af0267fd..5c5bd26f86 100644 --- a/app/api/v2/helpers.rb +++ b/app/api/v2/helpers.rb @@ -30,7 +30,7 @@ def trading_must_be_permitted! def withdraw_api_must_be_enabled! if ENV.false?('ENABLE_ACCOUNT_WITHDRAWAL_API') - error!({ errors: ['withdraw.status.disabled'] }, 422) + error!({ errors: ['account.withdraw.disabled_api'] }, 422) end end diff --git a/app/api/v2/market/named_params.rb b/app/api/v2/market/named_params.rb index 8130c0823f..3056bca647 100644 --- a/app/api/v2/market/named_params.rb +++ b/app/api/v2/market/named_params.rb @@ -7,13 +7,6 @@ module Market module NamedParams extend ::Grape::API::Helpers - params :currency do - requires :currency, - type: String, - values: { value: -> { Currency.enabled.pluck(:id) }, message: 'account.currency.doesnt_exist' }, - desc: 'The currency code.' - end - params :market do requires :market, type: String, diff --git a/docs/api/errors.md b/docs/api/errors.md new file mode 100644 index 0000000000..cca6953549 --- /dev/null +++ b/docs/api/errors.md @@ -0,0 +1,95 @@ +# Peatio Member API Errors + +## Shared errors + +| Code | Description | +| ----------------------- | ----------------------------------- | +| `jwt.decode_and_verify` | Impossible to decode and verify JWT | +| `record.not_found` | Record Not found | +| `server.internal_error` | Internal Server Error | + +## Account module + +| Code | Description | +| --------------------------------------- | ---------------------------------------------- | +| `account.currency.doesnt_exist` | **Currency** doesn't exist in database | +| `account.deposit.invalid_state` | Deposit **state** is not valid | +| `account.deposit.non_integer_limit` | Parameter **limit** should be integer | +| `account.deposit.invalid_limit` | Parameter **limit** is not valid | +| `account.deposit.non_positive_page` | Parameter **page** should be positive number | +| `account.deposit.empty_txid` | Parameter **txid** is missing or empty | +| `account.deposit.not_permitted` | Pass the corresponding verification steps to **deposit funds** | +| `account.withdraw.non_integer_limit` | Parameter **limit** should be integer | +| `account.withdraw.invalid_limit` | Parameter **limit** is not valid | +| `account.withdraw.non_positive_page` | Parameter **page** should be positive number | +| `account.withdraw.non_integer_otp` | Parameter **otp** should be integer | +| `account.withdraw.empty_otp` | Parameter **otp** is missing or empty | +| `account.withdraw.empty_rid` | Parameter **rid** is missing or empty | +| `account.withdraw.non_decimal_amount` | Parameter **amount** should be decimal | +| `account.withdraw.non_positive_amount` | Parameter **amount** should be positive number | +| `account.withdraw.insufficient_balance` | Account **balance** is insufficient | +| `account.withdraw.invalid_amount` | Parameter **amount** is not valid | +| `account.withdraw.create_error` | Failed to create withdraw | +| `account.withdraw.invalid_otp` | Parameter **otp** is not valid | +| `account.withdraw.disabled_api` | Withdrawal API is disabled | +| `account.withdraw.not_permitted` | Pass the corresponding verification steps to **withdraw funds** | +| `account.deposit_address.invalid_address_format` | Invalid parameter for deposit address format | +| `account.deposit_address.doesnt_support_cash_address_format` | Currency doesn't support cash address format | + +## Market module + +| Code | Description | +| -------------------------------------------- | ----------------------------------------------------------------| +| `market.account.insufficient_balance` | Account balance is insufficient | +| `market.market.doesnt_exist` | **Market** doesn't exist in database | +| `market.order.insufficient_market_liquidity` | Insufficient market liquidity | +| `market.order.invalid_volume_or_price` | Order **volume** or **price** is invalid for selected market | +| `market.order.create_error` | Failed to create order | +| `market.order.cancel_error` | Failed to cancel order | +| `market.order.market_order_price` | Market order doesn't have **price** | +| `market.order.invalid_state` | Parameter **state** is not valid | +| `market.order.invalid_limit` | Parameter **limit** is not valid | +| `market.order.non_integer_limit` | Parameter **limit** should be integer | +| `market.order.invalid_order_by` | Parameter **order_by** is not valid | +| `market.order.invalid_side` | Parameter **side** is not valid | +| `market.order.non_decimal_volume` | Parameter **volume** should be decimal | +| `market.order.non_positive_volume` | Parameter **volume** should be positive number | +| `market.order.invalid_type` | Parameter **type** is not valid | +| `market.order.non_decimal_price` | Parameter **price** should be decimal | +| `market.order.non_positive_price` | Parameter **price** should be positive number | +| `market.order.non_integer_id` | Parameter **id** should be integer | +| `market.order.empty_id` | Parameter **id** is missing or empty | +| `market.trade.non_integer_limit` | Parameter **limit** should be integer | +| `market.trade.invalid_limit` | Parameter **limit** is not valid | +| `market.trade.empty_page` | Parameter **page** is missing or empty | +| `market.trade.non_integer_timestamp` | Parameter **timestamp** should be integer | +| `market.trade.empty_timestamp` | Parameter **timestamp** is missing or empty | +| `market.trade.invalid_order_by` | Parameter **order_by** is not valid | +| `market.trade.not_permitted` | Pass the corresponding verification steps to **enable trading** | + +## Public module + +| Code | Description | +| ----------------------------------------- | ---------------------------------------------| +| `public.currency.doesnt_exist` | **Currency** doesn't exist in database | +| `public.currency.invalid_type` | **Currency** type is not valid | +| `public.market.doesnt_exist` | **Market** doesn't exist in database | +| `public.order_book.non_integer_ask_limit` | Parameter **ask_limit** should be integer | +| `public.order_book.invalid_ask_limit` | Parameter **ask_limit** is not valid | +| `public.order_book.non_integer_bid_limit` | Parameter **bid_limit** should be integer | +| `public.order_book.invalid_bid_limit` | Parameter **bid_limit** is not valid | +| `public.trade.invalid_limit` | Parameter **limit** is not valid | +| `public.trade.non_integer_limit` | Parameter **limit** should be integer | +| `public.trade.non_positive_page` | Parameter **page** should be positive number | +| `public.trade.non_integer_timestamp` | Parameter **timestamp** should be integer | +| `public.trade.invalid_order_by` | Parameter **order_by** is not valid | +| `public.market_depth.non_integer_limit` | Parameter **limit** should be integer | +| `public.market_depth.invalid_limit` | Parameter **limit** is not valid | +| `public.k_line.non_integer_period` | Parameter **period** should be integer | +| `public.k_line.invalid_period` | Parameter **period** is not valid | +| `public.k_line.non_integer_time_from` | Parameter **time_from** should be integer | +| `public.k_line.empty_time_from` | Parameter **time_from** is missing or empty | +| `public.k_line.non_integer_time_to` | Parameter **time_to** should be integer | +| `public.k_line.empty_time_to` | Parameter **time_to** is missing or empty | +| `public.k_line.non_integer_limit` | Parameter **limit** should be integer | +| `public.k_line.invalid_limit` | Parameter **limit** is not valid | diff --git a/spec/api/v2/account/withdraws_spec.rb b/spec/api/v2/account/withdraws_spec.rb index 206b29d76b..ce009619e7 100644 --- a/spec/api/v2/account/withdraws_spec.rb +++ b/spec/api/v2/account/withdraws_spec.rb @@ -109,7 +109,7 @@ it 'doesn\'t allow fiat' do api_post '/api/v2/account/withdraws', params: data, token: token expect(response).to have_http_status(422) - expect(response).to include_api_error('account.withdraw.currency_doesnt_exist') + expect(response).to include_api_error('account.currency.doesnt_exist') end end @@ -120,7 +120,7 @@ it 'doesn\'t allow account withdrawal API call' do api_post '/api/v2/account/withdraws', params: data, token: token expect(response).to have_http_status(422) - expect(JSON.parse(response.body)).to eq('errors' => ["withdraw.status.disabled"]) + expect(response).to include_api_error('account.withdraw.disabled_api') end end @@ -196,7 +196,7 @@ data[:currency] = nil api_post '/api/v2/account/withdraws', params: data, token: token expect(response).to have_http_status(422) - expect(response).to include_api_error('account.withdraw.currency_doesnt_exist') + expect(response).to include_api_error('account.currency.doesnt_exist') end it 'creates new withdraw and immediately submits it' do