flutter_bitkub_exchange 1.0.1

Flutter Bitkub Exchange #

Flutter Bitkub Exchange is a Flutter's library for calling API of the https://www.bitkub.com/

Installation #

Add dependencies in pubspec.yaml

flutter_bitkub_exchange: 1.0.1

Usage #

Import the package to your project.

import 'package:flutter_bitkub_exchange/bitkub_exchange.dart';

Using Public API #

Create instance without API Key.

var bk = BitkubExchangeService();

Market Data (Ticker) #

Get ticker information such as last price, high in 24Hr , volume. In the case that the wrong currency is returned to a empty list

  var ticker = await bk.fetchMarketTicker(currency: "THB_BTC");
  for(var currency in ticker.list){
    // currency.id;
    // currency.pairName;
    // currency.last;
    // currency.lowestAsk;
    // currency.highestBid;
    // currency.percentChange;
    // currency.baseVolume;
    // currency.quoteVolume;
    // currency.high24hr;
    // currency.lowestAsk;
  }

Get Server Timestamp #

Get server timestamp in seconds (Epoch Unix).

  var server = await bk.fetchServerTime();
  // server.serverTime;
  }

Get Available Pair-Currency #

Get List all available symbols.

  var data = await bk.fetchMarketSymbols();
  for(var currency in data.items){
    // currency.id;
    // currency.symbol;
    // currency.info
  }

Get Recent Trade #

Get list recent trades. (limit is number of rows)

 var recent = await bk.fetchRecentTrades(currency: "THB_BTC", limit: 100);
if(recent.isError()){
  // recent.errorMessage;
}else{
     for(var trade in recent.items){
       // trade.type;
       // trade.amount;
       // trade.rate;
       // trade.timestamp;
     }
}

Get Current Open Order on Market #

Get list open orders with bid/ask condition.

  var openOrder = await bk.fetchMarketOpenOrders(orderType: BitkubOpenOrderType.BIDS, currency: "THB_BTC", limit: 10);
  if(openOrder.isError()){
     // openOrder.errorMessage;
  }else{
    for(var order in openOrder.orders){
      // order.orderId;
      // order.amount;
      // order.rate;
      // order.volume;
      // order.timestam;
    }
  }

Get all open orders.

  var market = await bk.fetchMarketOpenOrdersAll(currency: "THB_BTC", limit: 10);
  if (market.isError()) {
    // market.errorMessage;
  } else {
    // market.bids;
    // market.asks;
  }

Prepare Private API #

Prepare 3 API keys.

1. General API key #

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

2. Crate Order API key #

Crate Order API key are used for creating order.

3. Cancel Order API key #

Cancel Order API key are used for canceling order.

Using Private API #

Create instance with 3 API keys.

  var bk = BitkubExchangeService(
      apiKeyGeneral:     BitkubApiKey(apiKey: "-", secret: "-"), 
      apiKeyCreateOrder: BitkubApiKey(apiKey: "-", secret: "-"), 
      apiKeyCancelOrder: BitkubApiKey(apiKey: "-", secret: "-"));

Get Balances #

Get balances info: this includes both available and reserved balances.

  var data = await bk.fetchWalletBalance();
  if(data.isError()){
    // data.errorMessage;
  }else{
    for(var wallet in data.wallets){
      // wallet.currency;
      // wallet.balance;

      // wallet.detail.balance;
      // wallet.detail.available;
      // wallet.detail.reserved;
    }
  }

Get Open Orders #

List all open orders of the given symbol.

 var openOrder =  await bk.fetchUserOpenOrders(currency: "THB_ETH");
  if(openOrder.isError()){
    // data.errorMessage;    
  }else{
    for(var order in openOrder.orders){
      // order.id;
      // order.type;
      // order.rate;
      // order.amount;
      // order.side;
      // order.fee;
      // order.credit;
      // order.receive
    }
  }

Get Transaction History #

List all open orders of the given symbol.

  var data = await bk.fetchUserOrderHistory(currency: "THB_ETH");
  if(data.isError()){
    // data.errorMessage;
  }else{
    for(var tx in data.history){
      // tx.txnId;
      // tx.orderId;
      // tx.side;
      // tx.rate;
      // tx.amount;
      // tx.fee;
      // tx.credit;
      // tx.takenByMe;
      // row.balance;
    }
  }

Get Transaction History #

List all open orders of the given symbol.

  var data = await bk.fetchUserOrderHistory(currency: "THB_ETH");
  if(data.isError()){
    // data.errorMessage;
  }else{
    for(var tx in data.history){
      // tx.txnId;
      // tx.orderId;
      // tx.side;
      // tx.rate;
      // tx.amount;
      // tx.fee;
      // tx.credit;
      // tx.takenByMe;
      // row.balance;
    }
  }

Create Order #

Create a buy/sell order. Example : BUY ETH with 30 THB in rate 100 THB/ETH so you will receive 0.3 ETH.

  var response =await bk.createOrder(currency: "THB_ETH",side: BitkubOpenOrderSide.BUY,amount: 30,rate: 100);
  if(response.isError()){
    // response.errorMessage;
  } else{
    // response.detail.id;
    // response.detail.amount;
    // response.detail.credit;
    // response.detail.rate;
    // response.detail.amount;
    // response.detail.fee;
    // response.detail.type;
    // response.detail.receive;
  }

Trading type

BitkubOpenOrderSide.BUY
BitkubOpenOrderSide.SELL

Cancel Order #

Cancel order with OrderId.


  var response = await bk.cancelOrder(currency: "THB_ETH",side: BitkubOpenOrderSide.BUY,orderId: 3132207,printJson: true);
  if(response.isError()){
    // response.errorMessage;
  }

Other uses #

Suggestions for other uses

Pairing Currency ID #

You can use BitkubCurrency class instead Currency String.

Example

var recent = await bk.fetchRecentTrades(currency: BitkubCurrency.THB_BTC, limit: 100);

display JSON response on console or logcat.

var recent = await bk.fetchRecentTrades(currency: BitkubCurrency.THB_BTC, limit: 100,printJson: true);

1.0.1 #

Fix bug and improve code..

1.0.0 #

GET /api/servertime GET /api/market/symbols GET /api/market/ticker GET /api/market/trades GET /api/market/bids GET /api/market/asks GET /api/market/books GET /api/market/trading-view POST /api/market/wallet POST /api/market/balances POST /api/market/place-bid POST /api/market/place-ask POST /api/market/cancel-order POST /api/market/my-open-orders POST /api/market/my-order-history POST /api/market/order-info

example/README.md

flutter_bitkub_exchange_example #

Demonstrates how to use the flutter_bitkub_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:


dependencies:
  flutter_bitkub_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_bitkub_exchange/bitkub_auth_utils.dart';
import 'package:flutter_bitkub_exchange/bitkub_error_manager.dart';
import 'package:flutter_bitkub_exchange/bitkub_exchange.dart';
import 'package:flutter_bitkub_exchange/bitkub_open_order_side.dart';
import 'package:flutter_bitkub_exchange/bitkub_open_order_type.dart';
import 'package:flutter_bitkub_exchange/bitkub_pair_currency_manager.dart';
import 'package:flutter_bitkub_exchange/bitkub_trade_type.dart';
import 'package:flutter_bitkub_exchange/bitkub_utils.dart';
import 'package:flutter_bitkub_exchange/dao/api_key/bitkub_api_key.dart';
import 'package:flutter_bitkub_exchange/dao/balance/bitkub_currency_balance_dao.dart';
import 'package:flutter_bitkub_exchange/dao/balance/bitkub_currency_balance_detail_dao.dart';
import 'package:flutter_bitkub_exchange/dao/balance/bitkub_wallet_balance_dao.dart';
import 'package:flutter_bitkub_exchange/dao/bitkub_server_time_dao.dart';
import 'package:flutter_bitkub_exchange/dao/cancel_order/bitkub_cancel_order_result_dao.dart';
import 'package:flutter_bitkub_exchange/dao/create_order/bitkub_create_order_result_dao.dart';
import 'package:flutter_bitkub_exchange/dao/create_order/bitkub_create_order_result_detail_dao.dart';
import 'package:flutter_bitkub_exchange/dao/market_open_order/bitkub_market_open_order_all_dao.dart';
import 'package:flutter_bitkub_exchange/dao/market_open_order/bitkub_market_open_order_dao.dart';
import 'package:flutter_bitkub_exchange/dao/market_open_order/bitkub_market_open_order_item_dao.dart';
import 'package:flutter_bitkub_exchange/dao/market_symbols/bitkub_market_symbol_dao.dart';
import 'package:flutter_bitkub_exchange/dao/market_symbols/bitkub_market_symbol_item_dao.dart';
import 'package:flutter_bitkub_exchange/dao/market_ticker/bitkub_market_ticker_dao.dart';
import 'package:flutter_bitkub_exchange/dao/market_ticker/bitkub_pair_currency_data_dao.dart';
import 'package:flutter_bitkub_exchange/dao/order_detail/bitkub_order_information_dao.dart';
import 'package:flutter_bitkub_exchange/dao/order_detail/bitkub_order_information_detail_dao.dart';
import 'package:flutter_bitkub_exchange/dao/order_detail/bitkub_order_information_history_dao.dart';
import 'package:flutter_bitkub_exchange/dao/recent_trades/bitkub_recent_trades_dao.dart';
import 'package:flutter_bitkub_exchange/dao/recent_trades/bitkub_recent_trade_item_dao.dart';
import 'package:flutter_bitkub_exchange/dao/user_open_order/bitkub_user_open_order_dao.dart';
import 'package:flutter_bitkub_exchange/dao/user_open_order/bitkub_user_open_order_item_dao.dart';
import 'package:flutter_bitkub_exchange/dao/user_order_history/bitkub_user_order_history_dao.dart';
import 'package:flutter_bitkub_exchange/dao/user_order_history/bitkub_user_order_history_item_dao.dart';
import 'package:flutter_bitkub_exchange/dao/user_order_history/bitkub_user_order_history_pagination_dao.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
50
Learn more about scoring.

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

  • Dart: 2.4.0
  • pana: 0.12.19
  • Flutter: 1.7.8+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Fix lib/dao/market_symbols/bitkub_market_symbol_dao.dart. (-0.50 points)

Analysis of lib/dao/market_symbols/bitkub_market_symbol_dao.dart reported 1 hint:

line 1 col 8: Unused import: 'dart:convert'.

Fix lib/dao/recent_trades/bitkub_recent_trades_dao.dart. (-0.50 points)

Analysis of lib/dao/recent_trades/bitkub_recent_trades_dao.dart reported 1 hint:

line 1 col 8: Unused import: 'dart:convert'.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
crypto ^2.0.6 2.1.2
flutter 0.0.0
http ^0.12.0+2 0.12.0+2
Transitive dependencies
async 2.3.0
charcode 1.1.2
collection 1.14.11 1.14.12
convert 2.1.1
http_parser 3.1.3
meta 1.1.6 1.1.7
path 1.6.4
pedantic 1.8.0+1
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
flutter_test