Package: bitkub-v2
Bitkub PythonA Python library forbitkub.comAPIReleases2023-12-14version3.1.4change sym from quote_base to base_quote2023-12-11version3.1.3revise tradingview history2023-12-01version3.1.1switch to api v32023-03-29version2.1.0switch to api v2 inCreate buy order,Create sell orderandCancel orderremoveCreate sell order by fiat, Deprecated at 2023-03-272022-01-07version1.1.0addCreate buy order testaddCreate sell order testViewing tradingview historyendpoint is now deprecated and will be updated with a new endpoint soon. The old endpoint will always return empty result.include is_maker inMy order historyremoved address and instead include from_address and to_address inCrypto deposit historyaddCrypto internal withdrawinclude partial_filled and remaining inOrder info2020-04-02version1.0.3addgenerate-addressmethodTable of ContentsInstallationUsageCreating a BitkubSet API key & API secretViewing statusViewing servertimeViewing symbolsViewing tickerViewing tradesViewing bidsViewing asksViewing booksViewing depthViewing tradingview historyViewing walletViewing balancesCreate buy orderCreate buy order testCreate sell orderCreate sell order testCreate sell order by fiatCancel orderMy open ordersMy order historyOrder infoCrypto addressesCrypto withdrawCrypto internal withdrawCrypto deposit historyCrypto withdraw historyCrypto generate addressFiat accountsFiat withdrawFiat deposit historyFiat withdraw historyMarket wstokenUser limitsUser trading creditsInstallationpip install bitkub-v2Usagefrom bitkub import BitkubCreating a Bitkub ObjectAPI_KEY = 'YOUR API KEY'
API_SECRET = 'YOUR API SECRET'

# initial obj only non-secure
bitkub = Bitkub()

# initial obj non-secure and secure
bitkub = Bitkub(api_key=API_KEY, api_secret=API_SECRET)You can find API KEY and API SECRET fromhere.Set API key and API secretIf you initial obj with only non-secure. You can set up API key and API secret on below.API_KEY = 'YOUR API KEY'
API_SECRET = 'YOUR API SECRET'

bitkub = Bitkub()
bitkub.set_api_key(API_KEY)
bitkub.set_api_secret(API_SECRET)Viewing statusGet endpoint status.Function:bitkub.status()Response:[
  {
    'name': 'Non-secure endpoints',
    'status': 'ok',
    'message': ''
  },
  {
    'name': 'Secure endpoints',
    'status': 'ok',
    'message': ''
  }
]Viewing servertimeGet server timestamp.Function:bitkub.servertime()Response:1701251212273Viewing symbolsList all available symbols.Function:bitkub.symbols()Response:{
  'error': 0,
  'result': [
    {
      'id': 1,
      'info': 'Thai Baht to Bitcoin',
      'symbol': 'THB_BTC'
    },
    {
      'id': 2,
      'info': 'Thai Baht to Ethereum',
      'symbol': 'THB_ETH'
    }
  ]
}Viewing tickerGet ticker information.Function:bitkub.ticker(sym='THB_BTC')Parameter:symstringThe symbol (optional)default""Response:{
  'THB_BTC': {
    'id': 1,
    'last': 278000,
    'lowestAsk': 278869.41,
    'highestBid': 278000,
    'percentChange': -1.44,
    'baseVolume': 206.01549914,
    'quoteVolume': 57883319.04,
    'isFrozen': 0,
    'high24hr': 284000,
    'low24hr': 277579.62,
    'change': -4075.81,
    'prevClose': 281800,
    'prevOpen': 281800
  }
}Viewing tradesList recent trades.Function:bitkub.trades(sym="THB_BTC", lmt=2)Parameter:symstringThe symbollmtintNo. of limit to Parameter recent tradesdefault1Response:{
  'error': 0,
  'result': [
    [
      1583246192, // timestamp
      278798.34, // rate
      0.00375672, // amount
      'BUY' // side
    ],
    [
      1583246159,
      278000,
      0.0001042,
      'SELL'
    ]
  ]
}Viewing bidsList open buy orders.Function:bitkub.bids(sym="THB_BTC", lmt=2)Parameter:symstringThe symbollmtintNo. of limit to Parameter open buy ordersdefault1Response:{
  'error': 0,
  'result': [
    [
      4632978, // order id
      1583245687, // timestamp
      73110.59, // volume
      278000, // rate
      0.26298773 // amount
    ],
    [
      4632732,
      1583245871,
      1312.68,
      278000,
      0.00472187
    ]
  ]
}Viewing asksList open sell orders.Function:bitkub.asks(sym="THB_BTC", lmt=2)Parameter:symstringThe symbollmtintNo. of limit to Parameter open sell ordersdefault1Response:{
  'error': 0,
  'result': [
    [
      4761288, // order id
      1583246870, // timestamp
      163813.12, // volume
      278499.03, // rate
      0.5882 // amount
    ],
    [
      4761287,
      1583246870,
      379232.12,
      278499.03,
      1.3617
    ]
  ]
}Viewing booksList all open orders.Function:bitkub.books(sym="THB_BTC", lmt=1)Parameter:symstringThe symbollmtintNo. of imit to Parameter open ordersdefault1Response:{
  'error': 0,
  'result': {
    'asks': [
      [
        4761425, // order id
        1583247105, // timestamp
        360885.74, // volume
        278300.17, // rate
        1.29675 // amount
      ]
    ],
    'bids': [
      [
        4633099, // order id
        1583247090, // timestamp
        622146.15, // volume
        277946.2, // rate
        2.23836897 // amount
      ]
    ]
  }
}Viewing depthGet depth information.Function:bitkub.depth(sym='THB_BTC', lmt=1)Parameter:symstringThe symbollmtintDepth sizedefault1Response:{
  'asks': [
    [
      277946.16,
      1.29675
    ]
  ],
  'bids': [
    [
      277936.27,
      0.94071896
    ]
  ]
}Viewing tradingview historyGet historical data for TradingView chart.Function:bitkub.tradingview(sym='THB_BTC', int=1, frm='', to='')Parameter:symstringThe symbolintintChart resolution (1, 5, 15, 60, 240, 1D)default1frmintTimestamp of the starting timetointTimestamp of the ending timeResponse:{
  'c': [
    1685000,
    1680699.95,
    1688998.99,
    1692222.22
  ],
  'h': [
    1685000,
    1685000,
    1689000,
    1692222.22
  ],
  'l': [
    1680053.22,
    1671000,
    1680000,
    1684995.07
  ],
  'o': [
    1682500,
    1685000,
    1680100,
    1684995.07
  ],
  's': "ok",
  't': [
    1633424400,
    1633425300,
    1633426200,
    1633427100
  ],
  'v': [
    4.604352630000001,
    8.530631670000005,
    4.836581560000002,
    2.8510189200000022
  ]
}Viewing walletGet user available balances.Required initial secure objFunction:bitkub.wallet()Response:{
  'error': 0,
  'result': {
    'THB': 0,
    'BTC': 0,
    'ETH': 0
  }
}Viewing balancesGet balances info: this includes both available and reserved balances.Required initial secure objFunction:bitkub.balances()Response:{
  'error': 0,
  'result': {
    'THB': {
      'available': 0,
      'reserved': 0
    },
    'BTC': {
      'available': 0,
      'reserved': 0
    }
  }
}Create buy orderCreate a buy order.Required initial secure objFunction:bitkub.place_bid(sym='THB_BTC', amt=1, rat=1, typ='limit', client_id='')Parameter:symstringThe symbolamtfloatAmount you want to spend with no trailing zero (e.g 1000.00 is invalid, 1000 is ok)default1ratfloatRate you want for the order with no trailing zero (e.g 1000.00 is invalid, 1000 is ok)default1typstringOrder type: limit or market (for market order, please specify rat as 0)defaultlimitclient_idstringyour id for reference ( not required )Response:{
  "error": 0,
  "result": {
    "id": 1, // order id
    "hash": "fwQ6dnQWQPs4cbatF5Am2xCDP1J", // order hash
    "typ": "limit", // order type
    "amt": 1000, // spending amount
    "rat": 15000, // rate
    "fee": 2.5, // fee
    "cre": 2.5, // fee credit used
    "rec": 0.06666666, // amount to receive
    "ts": 1533834547 // timestamp
    "ci": "input_client_id" // input id for reference
  }
}Create buy order test⚠️ This API isdeprecated.(2023-11-29)Create a buy order test.Required initial secure objFunction:bitkub.place_bid_test(sym='THB_BTC', amt=1, rat=1, typ='limit', client_id='')Parameter:symstringThe symbolamtfloatAmount you want to spend with no trailing zero (e.g 1000.00 is invalid, 1000 is ok)default1ratfloatRate you want for the order with no trailing zero (e.g 1000.00 is invalid, 1000 is ok)default1typstringOrder type: limit or marketdefaultlimitclient_idstringYour id for reference ( no required )Response:{
  'error': 0,
  'result': {
    'id': 1,
    'hash': 'fwQ6dnQWQPs4cbatF5Am2xCDP1J',
    'typ': 'limit',
    'amt': 1,
    'rat': 1,
    'fee': 2.5,
    'cre': 2.5,
    'rec': 0.06666666,
    'ts': 1533834547
  }
}Create sell orderCreate a sell order.Required initial secure objFunction:bitkub.place_ask(sym='THB_BTC', amt=1, rat=1, typ='limit', client_id='')Parameter:symstringThe symbolamtfloatAmount you want to sell with no trailing zero (e.g 0.10000000 is invalid, 0.1 is ok)default1ratfloatRate you want for the order with no trailing zero (e.g 1000.00 is invalid, 1000 is ok)default1typstringOrder type: limit or market (for market order, please specify rat as 0)defaultlimitclient_idstringyour id for reference ( not required )Response:{
  "error": 0,
  "result": {
    "id": 1, // order id
    "hash": "fwQ6dnQWQPs4cbatFGc9LPnpqyu", // order hash
    "typ": "limit", // order type
    "amt": 1.00000000, // selling amount
    "rat": 15000, // rate
    "fee": 37.5, // fee
    "cre": 37.5, // fee credit used
    "rec": 15000, // amount to receive
    "ts": 1533834844 // timestamp
    "ci": "input_client_id" // input id for reference
  }
}Create sell order test⚠️ This API isdeprecated.(2023-11-29)Create a sell order test.Required initial secure objFunction:bitkub.place_ask_test(sym='THB_BTC', amt=1, rat=1, typ='limit', client_id='')Parameter:symstringThe symbolamtfloatAmount you want to spend with no trailing zero (e.g 1000.00 is invalid, 1000 is ok)default1ratfloatRate you want for the order with no trailing zero (e.g 1000.00 is invalid, 1000 is ok)default1typstringOrder type: limit or marketdefaultlimitclient_idstringYour id for reference ( no required )Response:{
  'error': 0,
  'result': {
    'id': 1,
    'hash': 'fwQ6dnQWQPs4cbatF5Am2xCDP1J',
    'typ': 'limit',
    'amt': 1,
    'rat': 1,
    'fee': 2.5,
    'cre': 2.5,
    'rec': 0.06666666,
    'ts': 1533834547
  }
}Create sell order by fiat⚠️ This API isdeprecated.(2023-03-27)Create a sell order by specifying the fiat amount you want to receive (selling amount of cryptocurrency is automatically calculated).Required initial secure objFunction:bitkub.place_ask_by_fiat(sym='THB_BTC', amt=1, rat=1, typ='limit')Parameter:symstringThe symbolamtfloatAmount you want to spend with no trailing zero (e.g 1000.00 is invalid, 1000 is ok)default1ratfloatRate you want for the order with no trailing zero (e.g 1000.00 is invalid, 1000 is ok)default1typstringOrder type: limit or marketdefaultlimitResponse:{
  'error': 0,
  'result': {
    'id': 1,
    'hash': 'fwQ6dnQWQPs4cbatF5Am2xCDP1J',
    'typ': 'limit',
    'amt': 1,
    'rat': 1,
    'fee': 2.5,
    'cre': 2.5,
    'rec': 0.06666666,
    'ts': 1533834547
  }
}Cancel orrderCancel an open order.Required initial secure objFunction:bitkub.cancel_order(sym='THB_BTC', id=1, sd=1, hash='XXXXXX')Parameter:symstringThe symbolidintOrder id you wish to cancelsdstringOrder side: buy or selldefaultbuyhashstringCancel an order with order hash (optional). You don't need to specify sym, id, and sd when you specify order hash.Response:{
  'error': 0
}My open ordersList all open orders of the given symbol.Required initial secure objFunction:bitkub.my_open_orders(sym='THB_BTC')Parameter:symstringThe symbolResponse:{
  'error': 0,
  'result': [
    {
      'id': 2,
      'hash': 'fwQ6dnQWQPs4cbatFSJpMCcKTFR',
      'side': 'SELL',
      'type': 'limit',
      'rate': 15000,
      'fee': 35.01,
      'credit': 35.01,
      'amount': 0.93333334,
      'receive': 14000,
      'parent_id': 1,
      'super_id': 1,
      'ts': 1533834844
    }
  ]
}My order historyList all orders that have already matched.Required initial secure objFunction:bitkub.my_open_history(sym='THB_BTC', p=1, lmt=10)Parameter:symstringThe symbolpstringPage (optional)lmtstringLimit (optional)startstringStart timestamp (optional)endstringEnd timestamp (optional)Response:{
  'error': 0,
  'result': [
    {
      'txn_id': 'ETHBUY0000000197',
      'order_id': 240,
      'hash': 'fwQ6dnQWQPs4cbaujNyejinS43a',
      'parent_order_id': 0,
      'super_order_id': 0,
      'taken_by_me': true,
      'is_maker': true,
      'side': 'buy',
      'type': 'limit',
      'rate': 13335.57,
      'fee': 0.34,
      'credit': 0.34,
      'amount': 0.00999987,
      'ts': 1531513395
    }

{
  'error': 0,
  'result': {
      'id': 289,
  ],
  'pagination': {
    'page': 2,
    'last': 3,
    'next': 3,
    'prev': 1
  }
}Order infoGet information regarding the specified order.Required initial secure objFunction:bitkub.order_info(sym='THB_BTC', id=1, sd='buy', hash='XXXXXX')Parameter:symstringThe symbolidintOrder idsdstringOrder side: buy or selldefaultbuyhashstringLookup an order with order hash (optional). You don't need to specify sym, id, and sd when you specify order hash.Response:{
  'error': 0,
  'result': {
      'id': 289,
      'first': 289,
      'parent': 0,
      'last': 316,
      'amount': 4000,
      'rate': 291000,
      'fee': 10,
      'credit': 10,
      'filled': 3999.97,
      'total': 4000,
      'status': 'filled',
      'partial_filled': False,
      'remaining': 0,
      'history': [
        {
            'amount': 98.14848,
            'credit': 0.25,
            'fee': 0.25,
            'id': 289,
            'rate': 291000,
            'timestamp': 1525944169
        }
      ]
    }
  }Crypto addressesList all crypto addresses.Required initial secure objFunction:bitkub.crypto_address(p=1, lmt=1)Parameter:pintPage (optional)default1lmtintLimit (optional)default10Response:{
  'error': 0,
  'result': [
    {
       'currency': 'BTC',
       'address': '3BtxdKw6XSbneNvmJTLVHS9XfNYM7VAe8k',
       'tag': 0,
       'time': 1570893867
    }
  ],
  'pagination': {
    'page': 1,
    'last": 1
  }
}Crypto withdrawMake a withdrawal to a trusted address.Required initial secure objFunction:bitkub.crypto_withdraw(cur='BTC', amt=0.1, adr='4asyjKw6XScneNvhJTLVHS9XfNYM7VBf8x', mem='')Parameter:curstringCurrency for withdrawal (e.g. BTC, ETH)amtfloatAmount you want to withdrawadrstringAddress to which you want to withdrawmemstring(Optional) Memo or destination tag to which you want to withdrawResponse:{
  'error': 0,
  'result': {
      'txn': 'BTCWD0000012345',
      'adr': '4asyjKw6XScneNvhJTLVHS9XfNYM7VBf8x'
      'mem': '',
      'cur': 'BTC',
      'amt': 0.1,
      'fee': 0.0002,
      'ts': 1569999999
  }
}Crypto internal withdrawMake a withdrawal to a trusted address.Required initial secure objThe destination address is not required to be a trusted address. This API is not enabled by default, Only KYB users can request this feature by contacting us viasupport@bitkub.comFunction:bitkub.crypto_internal_withdraw(cur='BTC', amt=0.1, adr='4asyjKw6XScneNvhJTLVHS9XfNYM7VBf8x', mem='')Parameter:curstringCurrency for withdrawal (e.g. BTC, ETH)amtfloatAmount you want to withdrawadrstringAddress to which you want to withdrawmemstring(Optional) Memo or destination tag to which you want to withdrawResponse:{
  'error': 0,
  'result': {
      'txn': 'BTCWD0000012345',
      'adr': '4asyjKw6XScneNvhJTLVHS9XfNYM7VBf8x'
      'mem': '',
      'cur': 'BTC',
      'amt': 0.1,
      'fee': 0.0002,
      'ts': 1569999999
  }
}Crypto deposit historyList crypto deposit history.Required initial secure objFunction:bitkub.crypto_deposit_history(p=1, lmt=1)Parameter:pintPage (optional)default1lmtintLimit (optional)default10Response:{
  'error': 0,
  'result': [
    {
       'hash': 'XRPWD0000100276',
       'currency': 'XRP',
       'amount': 5.75111474,
       'from_address': 'sender address',
       'to_address': 'receipent address',
       'confirmations': 1,
       'status': 'complete',
       'time': 1570893867
    }
  ],
  'pagination': {
    'page': 1,
    'last': 1
  }
}Crypto withdraw history:
List crypto withdrawal history.Required initial secure objFunction:bitkub.crypto_withdraw_history(p=1, lmt=1)Parameter:pintPage (optional)default1lmtintLimit (optional)default10Response:{
  'error': 0,
  'result': [
    {
      'txn_id': 'XRPWD0000100276',
      'hash': 'send_internal',
      'currency': 'XRP',
      'amount': '5.75111474',
      'fee': 0.01,
      'address': 'rpXTzCuXtjiPDFysxq8uNmtZBe9Xo97JbW',
      'status': 'complete',
      'time': 1570893493
    }
  ],
  'pagination': {
    'page': 1,
    'last': 1
  }
}Crypto generate addressGenerate a new crypto address (will replace existing address; previous address can still be used to received funds)
List all approved bank accounts.Required initial secure objFunction:bitkub.crypto_generate_address(sym='THB_BTC')Parameter:symstringThe symbolResponse:{
  'error': 0,
  'result': [
    {
       'currency': 'BTC',
       'address': '0x520165471daa570ab632dd504c6af257bd36edfb',
       'memo': ''
    }
  ]
}Fiat accountsList all approved bank accounts.Required initial secure objFunction:bitkub.fiat_accounts(p=1, lmt=1)Parameter:pintPage (optional)default1lmtintLimit (optional)default10Response:{
  'error': 0,
  'result': [
    {
      'id': '7262109099',
      'bank': 'Kasikorn Bank',
      'name': 'Somsak',
      'time': 1570893867
    }
  ],
  'pagination': {
    'page': 1,
    'last': 1
  }
}Fiat withdrawMake a withdrawal to an approved bank account.Required initial secure objFunction:bitkub.fiat_withdraw(id=1, amt=1)Parameter:idstringBank account idamtfloatAmount you want to withdrawResponse:{
  'error': 0,
  'result': {
    'txn': 'THBWD0000012345',
    'acc': '7262109099',
    'cur': 'THB',
    'amt': 21,
    'fee': 20,
    'rec': 1,
    'ts': 1569999999
  }
}Fiat deposit historyList fiat deposit history.Required initial secure objFunction:bitkub.fiat_deposit_history(p=1, lmt=1)Parameter:pintPage (optional)default1lmtintLimit (optional)default10Response:{
  'error':0,
  'result':[
    {
       'txn_id': 'THBDP0000012345',
       'currency': 'THB',
       'amount': 5000.55,
       'status': 'complete',
       'time': 1570893867
    }
  ],
  'pagination':{
    'page': 1,
    'last': 1
  }
}Fiat withdraw historyList fiat withdrawal history.Required initial secure objFunction:bitkub.fiat_withdraw_history(p=1, lmt=1)Parameter:pintPage (optional)default1lmtintLimit (optional)default10Response:{
  'error': 0,
  'result': [
    {
       'txn_id': 'THBDP0000012345',
       'currency': 'THB',
       'amount': 5000.55,
       'fee': 20,
       'status': 'complete',
       'time': 1570893867
    }
  ],
  'pagination':{
    'page': 1,
    'last': 1
  }
}Market wstokenGet the token for websocket authentication.Required initial secure objFunction:bitkub.market_wstoken()Response:{
  'error': 0,
  'result': 'sdCBCTwaS2Z1IBB6uTCefIbVN6dQVz9dkDeU96IoFJp14GGhlw9hoUDNe1KSYC23dXBPIqyX2QjVEOFHITxgPMvo8kdVaTkiZBA8KgvVTSMsq6JjjlyERDVZn3tt4PEp'
}User limitsCheck deposit/withdraw limitations and usage.Required initial secure objFunction:bitkub.user_limits()Response:{
  'error': 0,
  'result': {
    'limits': {
      'crypto': {
        'deposit': 0,
        'withdraw': 0
      },
      'fiat': {
        'deposit': 0,
        'withdraw': 0
      }
    },
    'usage': {
      'crypto': {
        'deposit': 0,
        'withdraw': 0,
        'deposit_percentage': 0,
        'withdraw_percentage': 0,
        'deposit_thb_equivalent': 0,
        'withdraw_thb_equivalent': 0
      },
      'fiat': {
        'deposit': 0,
        'withdraw': 0,
        'deposit_percentage': 0,
        'withdraw_percentage': 0
      }
    },
    'rate': 177100.32
  }
}User trading-creditCheck trading credit balance.Required initial secure objFunction:bitkub.user_trading_credits()Response:{
  'error': 0,
  'result': 0
}