flutter_bx_exchange 1.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 61

Flutter BX Exchange #

Flutter BX Exchange is a Flutter's library for calling API of the https://bx.in.th. package on Pub.dev

Installation #

Add dependencies in pubspec.yaml

flutter_bx_exchange: 1.0.0

Usage #

Import the package to your project.

import 'package:flutter_bx_exchange/bx_exchange_service.dart';

Using Public API #

Create instance without API Key.

var bx = BxExchangeService();

Market Data (Ticker) #

Returns a list of all currency pairings including symbol currency, current price, volume in 24 hr, change in 24 hr.

This is a public API. you can access JSON in https://bx.in.th/api/ directly.


Using in Flutter.

List<BxPairCurrencyBxDao> list = await bx.fetchMarketData();
for(var currency in list){
    //    currency.pairingId;
    //    currency.primaryCurrency;
    //    currency.secondaryCurrency;
    //    currency.lastPrice;
    //    currency.volume24hours;
    //    currency.orderbook;

Current Pairing Currency #

Returns a list of all available currency pairings, including their "pairing_id" which is required for some API calls. Will also include the minimum order amount for primary and secondary currency in each pairing market.

This is a public API. you can access JSON in https://bx.in.th/api/pairing/ directly.


Using in Flutter.

List<BxPairCurrencyMetaDao> list = await bx.fetchCurrentPairings();
for(var currency in list){
    //    currency.pairingId;
    //    currency.primaryCurrency;
    //    currency.secondaryCurrency;
    //    currency.active;
    //    currency.primaryMin;

Order Book Summary #

Returns a list of all buy and sell orders in the order book for the selected pairing market.

This is a public API. you can access JSON in https://bx.in.th/api/orderbook/?pairing=1 directly.


Using in Flutter.

var orderbook = await bx.fetchOrderBook(pairingId: 1); // 1 is BTC/THB
//  orderbook.pairingsId;
//  orderbook.asks;
//  orderbook.bids;

Recent Trade #

Returns a list of 10 most recent trades, and top 10 asks and bids in order book.

This is a public API. you can access JSON in https://bx.in.th/api/trade/?pairing=1 directly.


Using in Flutter.

var recent = await bx.fetchRecentTrade(pairingId: 1); // 1 is BTC/THB
//  recent.pairingId;
//  recent.highBid;
//  recent.lowAsk;
//  recent.trades;

Historical Trade Data #

Returns Weighted Average, Volume, Open, Close, Low and High prices for the specified date.

This is a public API. you can access JSON in https://bx.in.th/api/tradehistory/?pairing=1&date=2019-01-01 directly.

var history = await bx.fetchHistoricalTradeData(pairingId: 1, date: "2019-07-01");
//  history.high;
//  history.low;
//  history.avg;
//  history.open;
//  history.volume;

Prepare Private API #

Prepare 3 API keys With different permissions.

1. General API key #

General API key are used for reading general information, such as balance, open orders , deposit address.

required permissions : balance and deposit. 

2. Crate Order API key #

Crate Order API key are used for creating order.

required permissions : create order. (Recommended to enable 2FA for safety.)

3. Cancel Order API key #

Cancel Order API key are used for canceling order.

required permissions : cancel order. (Recommended to enable 2FA for safety.)

Using Private API #

Create instance with 3 API keys different permissions.

var bx = BxExchangeService(
  apiKeyGeneral:     BxApiKey(apiKey: "........", secret: "........"),
  apiKeyCreateOrder: BxApiKey(apiKey: "........", secret: "........"),
  apiKeyCancelOrder: BxApiKey(apiKey: "........", secret: "........"),

Get Balance #

Return all currencies with balance information including available, withdrawals, deposit, open order.

  var response = await bx.fetchBalance();
    var balances = response.balance;
    for(var balance in balances.listBalanceCurrency){
      //  balance.currency;
      //  balance.available;
      //  balance.deposits;
      //  balance.orders;
      //  balance.total;
      //  balance.withdrawals;

Get Open Orders #

Returns current orders with option BUY / SELL.

  var response = await bx.fetchOpenOrders(pairingId: 1, orderType: BxTradeType.SELL);
    for(var order in response.orders){
      //  order.pairingId;
      //  order.orderId;
      //  order.orderType;
      //  order.rate;
      //  order.amount;
      //  order.date;

Get Transaction History #

Get your own balance affecting transaction history, such as trades, withdrawals and deposits.

  var response = await bx.fetchTransactionHistory();
  if (response.success) {
    for (var tx in response.transactions) {
      //  tx.currency;
      //  tx.amount;
      //  tx.transactionId;
      //  tx.date;
      //  tx.type;
      //  tx.refId;
  } else {

You can add conditions to display various history transactions.

  var response = await bx.fetchTransactionHistory(
                              currency: "BTC", 
                              transactionType: BxTransactionType.WITHDRAW, 
                              startDate: "2019-01-01", 
                              endDate: "2019-05-01");

Get Withdraw History #

Return all transactions that about withdrawal.

  var response  = await bx.fetchWithdrawHistory();
    for(var tx in response.withdrawals){
      //  tx.transactionId;
      //  tx.currency;
      //  tx.amount;
      //  tx.address;
      //  tx.dateRequested;
      //  tx.withdrawalId;
      //  tx.withdrawalStatus;
    //  print(response.error); 

Get Deposit Address #

Return deposit address of wallet.

  var response = await bx.fetchDepositAddress(currency: "BTC");
    // response.address;

Generate new deposit address.

  var response = await bx.fetchDepositAddress(currency: "BTC",generateNewAddress: true);

Create Order #

Create order to market require CREATE ORDER permission. This method use Create Order API key. The parameter require pairing id, tradeType, amount, rate. 2FA is a optional.

  var response = await bx.createOrder(
                          pairingId: 1, 
                          tradeType: BxTradeType.SELL, 
                          amount: 0.001, 
                          rate: 1000000, 
                          twoFactorAuth: '123456');
  if (response.success) {
     // response.orderId;
     // response.historyId;
  } else {

Cancel Order #

Cancel order to market require CANCEL ORDER permission. This method use Cancel Order API key. The parameter require pairing id and order id. 2FA is a optional.

  var response = await bx.cancelOrder(
                        pairingId: 1,
                        orderId: 4567890,
                        twoFactorAuth: '123456');
  if (response.success) {
  } else {

Other uses #

Suggestions for other uses

Pairing Currency ID #

You can use BxPairCurrency class instead integer.


var history = await bx.fetchHistoricalTradeData(pairingId: BxPairCurrency.THB_BTC);

display JSON response on console or logcat.

await bx.fetchMarketData(printJson: true);


Create Signature #

Create a signature and display it on the console so you can apply this signature to other tools such as Postman. and This signature will not be actually delivered to the server.

                apiKey: "123456789", 
                secret: "123456789"

Example displaying signature on console.

I/flutter ( 1919): apiKey = 123456789
I/flutter ( 1919): nonce = 1562569793537
I/flutter ( 1919): signature = 1ddf4d56df9a34abd83530d96d6df450fd3d2e2f0c910b55a79fbacce1e3e4ca

1.0.1 #

Fix bug.

1.0.0 #

Ticker api. balance api. open order api. create order api. cancel order api. transaction history api. withdraw history api.


flutter_bx_exchange_example #

Demonstrates how to use the flutter_bx_exchange plugin.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  flutter_bx_exchange: ^1.0.1

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:flutter_bx_exchange/bx_auth_utils.dart';
import 'package:flutter_bx_exchange/bx_exchange_service.dart';
import 'package:flutter_bx_exchange/bx_pair_currency.dart';
import 'package:flutter_bx_exchange/bx_pair_currency_manager.dart';
import 'package:flutter_bx_exchange/bx_trade_type.dart';
import 'package:flutter_bx_exchange/bx_transaction_type.dart';
import 'package:flutter_bx_exchange/bx_utils.dart';
import 'package:flutter_bx_exchange/bx_withdraw_transaction_type.dart';
import 'package:flutter_bx_exchange/dao/apiKey/bx_api_key.dart';
import 'package:flutter_bx_exchange/dao/balance/bx_balance_currency_dao.dart';
import 'package:flutter_bx_exchange/dao/balance/bx_balance_dao.dart';
import 'package:flutter_bx_exchange/dao/balance/bx_balance_response_dao.dart';
import 'package:flutter_bx_exchange/dao/cancel_order/bx_cancel_order_response_dao.dart';
import 'package:flutter_bx_exchange/dao/create_order/bx_cretae_order_response_dao.dart';
import 'package:flutter_bx_exchange/dao/current_pairings/bx_current_pairings_dao.dart';
import 'package:flutter_bx_exchange/dao/current_pairings/bx_pair_curency_meta_dao.dart';
import 'package:flutter_bx_exchange/dao/get_deposit_address/bx_deposit_address_dao.dart';
import 'package:flutter_bx_exchange/dao/get_order/bx_open_order_detail_dao.dart';
import 'package:flutter_bx_exchange/dao/get_order/bx_open_order_response_dao.dart';
import 'package:flutter_bx_exchange/dao/historical_trade_data/bx_historical_trade_data_dao.dart';
import 'package:flutter_bx_exchange/dao/historical_trade_data/bx_historical_trade_data_response_dao.dart';
import 'package:flutter_bx_exchange/dao/market_data/bx_market_data_dao.dart';
import 'package:flutter_bx_exchange/dao/market_data/bx_order_book_volume_dao.dart';
import 'package:flutter_bx_exchange/dao/market_data/bx_pair_currency_dao.dart';
import 'package:flutter_bx_exchange/dao/market_data/bx_volume_data_dao.dart';
import 'package:flutter_bx_exchange/dao/order_book/bx_order_book_dao.dart';
import 'package:flutter_bx_exchange/dao/order_book/bx_order_book_detail_dao.dart';
import 'package:flutter_bx_exchange/dao/recent_trade/bx_high_bidk_dao.dart';
import 'package:flutter_bx_exchange/dao/recent_trade/bx_order_detail_dao.dart';
import 'package:flutter_bx_exchange/dao/recent_trade/bx_recent_trade_dao.dart';
import 'package:flutter_bx_exchange/dao/recent_trade/bx_trade_dao.dart';
import 'package:flutter_bx_exchange/dao/transaction_history/bx_transaction_detail_dao.dart';
import 'package:flutter_bx_exchange/dao/transaction_history/bx_transaction_history_dao.dart';
import 'package:flutter_bx_exchange/dao/withdraw_history/bx_withdraw_history_dao.dart';
import 'package:flutter_bx_exchange/dao/withdraw_history/bx_withdraw_transaction_dao.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Dec 13, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.1+4
  • Flutter: 1.12.13+hotfix.4

Health suggestions

Format lib/bx_auth_utils.dart.

Run flutter format to format lib/bx_auth_utils.dart.

Format lib/bx_exchange_service.dart.

Run flutter format to format lib/bx_exchange_service.dart.

Format lib/bx_pair_currency_manager.dart.

Run flutter format to format lib/bx_pair_currency_manager.dart.

Fix additional 30 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/bx_trade_type.dart (Run flutter format to format lib/bx_trade_type.dart.)
  • lib/bx_transaction_type.dart (Run flutter format to format lib/bx_transaction_type.dart.)
  • lib/bx_utils.dart (Run flutter format to format lib/bx_utils.dart.)
  • lib/bx_withdraw_transaction_type.dart (Run flutter format to format lib/bx_withdraw_transaction_type.dart.)
  • lib/dao/apiKey/bx_api_key.dart (Run flutter format to format lib/dao/apiKey/bx_api_key.dart.)
  • lib/dao/balance/bx_balance_currency_dao.dart (Run flutter format to format lib/dao/balance/bx_balance_currency_dao.dart.)
  • lib/dao/balance/bx_balance_dao.dart (Run flutter format to format lib/dao/balance/bx_balance_dao.dart.)
  • lib/dao/balance/bx_balance_response_dao.dart (Run flutter format to format lib/dao/balance/bx_balance_response_dao.dart.)
  • lib/dao/cancel_order/bx_cancel_order_response_dao.dart (Run flutter format to format lib/dao/cancel_order/bx_cancel_order_response_dao.dart.)
  • lib/dao/create_order/bx_cretae_order_response_dao.dart (Run flutter format to format lib/dao/create_order/bx_cretae_order_response_dao.dart.)
  • lib/dao/current_pairings/bx_current_pairings_dao.dart (Run flutter format to format lib/dao/current_pairings/bx_current_pairings_dao.dart.)
  • lib/dao/current_pairings/bx_pair_curency_meta_dao.dart (Run flutter format to format lib/dao/current_pairings/bx_pair_curency_meta_dao.dart.)
  • lib/dao/get_deposit_address/bx_deposit_address_dao.dart (Run flutter format to format lib/dao/get_deposit_address/bx_deposit_address_dao.dart.)
  • lib/dao/get_order/bx_open_order_detail_dao.dart (Run flutter format to format lib/dao/get_order/bx_open_order_detail_dao.dart.)
  • lib/dao/get_order/bx_open_order_response_dao.dart (Run flutter format to format lib/dao/get_order/bx_open_order_response_dao.dart.)
  • lib/dao/historical_trade_data/bx_historical_trade_data_dao.dart (Run flutter format to format lib/dao/historical_trade_data/bx_historical_trade_data_dao.dart.)
  • lib/dao/historical_trade_data/bx_historical_trade_data_response_dao.dart (Run flutter format to format lib/dao/historical_trade_data/bx_historical_trade_data_response_dao.dart.)
  • lib/dao/market_data/bx_market_data_dao.dart (Run flutter format to format lib/dao/market_data/bx_market_data_dao.dart.)
  • lib/dao/market_data/bx_pair_currency_dao.dart (Run flutter format to format lib/dao/market_data/bx_pair_currency_dao.dart.)
  • lib/dao/market_data/bx_volume_data_dao.dart (Run flutter format to format lib/dao/market_data/bx_volume_data_dao.dart.)
  • lib/dao/order_book/bx_order_book_dao.dart (Run flutter format to format lib/dao/order_book/bx_order_book_dao.dart.)
  • lib/dao/order_book/bx_order_book_detail_dao.dart (Run flutter format to format lib/dao/order_book/bx_order_book_detail_dao.dart.)
  • lib/dao/recent_trade/bx_high_bidk_dao.dart (Run flutter format to format lib/dao/recent_trade/bx_high_bidk_dao.dart.)
  • lib/dao/recent_trade/bx_order_detail_dao.dart (Run flutter format to format lib/dao/recent_trade/bx_order_detail_dao.dart.)
  • lib/dao/recent_trade/bx_recent_trade_dao.dart (Run flutter format to format lib/dao/recent_trade/bx_recent_trade_dao.dart.)
  • lib/dao/recent_trade/bx_trade_dao.dart (Run flutter format to format lib/dao/recent_trade/bx_trade_dao.dart.)
  • lib/dao/transaction_history/bx_transaction_detail_dao.dart (Run flutter format to format lib/dao/transaction_history/bx_transaction_detail_dao.dart.)
  • lib/dao/transaction_history/bx_transaction_history_dao.dart (Run flutter format to format lib/dao/transaction_history/bx_transaction_history_dao.dart.)
  • lib/dao/withdraw_history/bx_withdraw_history_dao.dart (Run flutter format to format lib/dao/withdraw_history/bx_withdraw_history_dao.dart.)
  • lib/dao/withdraw_history/bx_withdraw_transaction_dao.dart (Run flutter format to format lib/dao/withdraw_history/bx_withdraw_transaction_dao.dart.)


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
crypto ^2.0.6 2.1.4
flutter 0.0.0
http ^0.12.0+2 0.12.0+2
Transitive dependencies
async 2.4.0
charcode 1.1.2
collection 1.14.11 1.14.12
convert 2.1.1
http_parser 3.1.3
meta 1.1.8
path 1.6.4
pedantic 1.9.0
sky_engine 0.0.99
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies