A simple asynchronous API Client Indodax
This library is implementing Indodax Official API.
This package contains a set of high-level functions and classes that make it easy to consume API.
Feel free to contribute!
https://github.com/wawan-ikhwan/indodax
-
Public API:
You don't need authenticate for PublicAPI.
Get server time example (Synchronous):
import 'package:indodax/indodax.dart'; void main(){ PublicAPI.serverTime.then((t) { print(t.timeZone); print(t.time); }); }
Get server time example (Asynchronous):
import 'package:indodax/indodax.dart'; Future<void> main() async { var response = await PublicAPI.serverTime; print(response.timeZone); print(response.time); }
Get summaries example (Asynchronous):
import 'package:indodax/indodax.dart'; Future<void> main() async { var response = await PublicAPI.summaries; print(response.prices7d); print(response.prices24h); }
-
Private API:
You need API_KEY and SECRET KEY for Private API, you can make it with visit https://indodax.com/trade_api .
Get info trader (ujang)
import 'package:indodax/indodax.dart'; Future<void> main() async { var ujang = PrivateAPI( key: 'OOZJORLL-XFEC6V3D-EDUZHELU-PHP8YF9F-GSSXV2K6', secret: 'b11c56f740d358b1640e17beb72bd3c137b58b02170aa4f3cf28327c3f87fb73cc4e6b3085b7f7f', ); var infoUjang = await ujang.info print(infoUjang); ujang.close(); }
Or you can use valid auth.json file
{ "API": "OOZJORLL-XFEC6V3D-EDUZHELU-PHP8YF9F-GSSXV2K6", "SECRET": "b11c56f740d358b1640e17beb72bd3c137b58b02170aa4f3cf28327c3f87fb73cc4e6b3085b7f7fb" }
Then you can use specified path where you saved the file.
import 'package:indodax/indodax.dart'; Future<void> main() async { var ujang = PrivateAPI(authPath: './auth.json'); var infoUjang = await ujang.info print(infoUjang); ujang.close(); }
- PublicAPI:
- open() -> Openning connection, actually it's closing then opening (reopenning).
- close() -> Closing connection, it's possible to reopen using open().
- serverTime -> Get current server time (millisecond since epoch).
- pairs -> Get list of currency pairs (cryptoCurrency_fiatCurrency).
- priceIncrements -> Get list of price increments.
- getTicker(id) -> Get a ticker by pair_id.
- tickerAll -> Get list of tickers.
- summaries -> Get summaries. Contain tickers, prices 24 hours, and price 7 days.
- getTrade(id) -> Get public trade activity by pair_id.
- getDepth(id) -> Get bid/ask depth by pair_id.
- PrivateAPI:
- close() -> Close connection. It's not possible to reopen, but you can create new trader (new object).
- info -> Get general info current trader.
- getTransHistory(start,end) -> Get transaction history.
- trade(pair,type,price,cryptoAmount,fiatAmount) -> Do trade (open order or instant order)
- getTradeHistory(pair,count,fromID,endID,order,since,end) -> Get trading history.
- getOpenOrders(pair) -> Get current trader's book order.
- getOrderHistory(pair,count,from) -> Get order history (canceled, success, etc).
- getOrder(pair,orderID) -> get detail of order.
- cancelOrder(pair,orderID,type) -> Do cancel order in current trader's book order.
It's depends.
PublicAPI class are static class so it's automatically implement client interface from http library.
PrivateAPI is object based, it's automatically implement client from http library when the object is created. We can say whenever object created we are creating trader because we created new client interface. So you can use multiple account in this private api as long the api credential is different. But when the trader is not needed anymore, you can close the object so the client interface will close and save bandwidth.
So, keeping connection open is better for multiple request to server.