DEV Community

loading...
Cover image for Api Cryptocurrency

Api Cryptocurrency

ockang profile image Edinson Carranza Saldaña Updated on ・6 min read

API CRYPTOCURRENCY

Project: https://github.com/edinsoncs/Apicryptocurrency

The development of this api is created for the exchange , the development contains acceptance of creation of wallets and transactions between any cryptocurrency and any ethereum token, the development is made as a Nodejs base and the information is saved in Mongodb.

CRYPTOCURRENCY

Requirements

The essential requirements to deploy the project is Nodejs & Mongodb

Start project

In production or local we make a clone of the project

https://github.com/ockang/Apicryptocurrency
Enter fullscreen mode Exit fullscreen mode

It works in any version of nodejs LTS, NODE 8 and up is recommended

Install Project

To start the project the dependencies will be installed

npm install in folder project
Enter fullscreen mode Exit fullscreen mode

Once the installation is done, we are going to install the dev dependencies

npm install @babel/core @babel/node @babel/preset-env --save-dev
Enter fullscreen mode Exit fullscreen mode
npm install eslint eslint-config-airbnb-base eslint-plugin-import --save-dev
Enter fullscreen mode Exit fullscreen mode
npm install -g nodemon
npm install nodemon --save-dev
Enter fullscreen mode Exit fullscreen mode

or we can also do the installation of the dev dependencies in a single line with the following command

npm install --only=dev
Enter fullscreen mode Exit fullscreen mode

 

List of avaiable methods - Cryptocurrency

Route Method Description
/ GET Hello World Route
1. https://api.domain.com/btc POST Create new wallet and obtain information
2. https://api.domain.com/bch POST Create new wallet and obtain information
3. https://api.domain.com/doge POST Create new wallet and obtain information
4. https://api.domain.com/eth POST Create new wallet and obtain information
5. https://api.domain.com/ltc POST Create new wallet and obtain information
6. https://api.domain.com/xmr POST Create new wallet and obtain information
7. https://api.domain.com/ppc POST Create new wallet and obtain information
8. https://api.domain.com/iota POST Create new wallet and obtain information
9. https://api.domain.com/xrp POST Create new wallet and obtain information

 

List of avaiable methods - Tokens List and Create

Route Method Description
1. https://api.domain.com/tokens GET We get all registered tokens
2. https://api.domain.com/tokens/new POST We will create a new erc-20 token

 

List of avaiable methods - Tokens Balance

Route Method Description
1. https://api.domain.com/tokens/balance POST We get the balance of any ethereum token

 

List of avaiable methods - Crypto Transaction Fees

Route Method Description
1. https://api.damecoins.com/calculate/btc POST We calculate the commission for sending bitcoin
2. https://api.damecoins.com/tokens/calculate POST We get the balance of any ethereum token
3. https://api.damecoins.com/tokens/calculate-token POST We calculate the commission for sending tokens erc-20

 

List of avaiable methods - Transfer Coins

Route Method Description
1. https://api.domain.com/transfer/btc POST send bitcoin transactions to a wallet
2. https://api.domain.com/transfer/eth POST send eth transactions to a wallet
3. https://api.domain.com/transfer/bch POST send bch transactions to a wallet
4. https://api.domain.com/transfer/tokens POST send more than 300,000 thousand erc-20 tokens

 

List of avaiable methods - Etherscan

Route Method Description
1. https://api.domain.com/etherscan/history POST List history all transactions tokens and ethereum

 

List of avaiable methods - Binance

Route Method Description
1. https://api.domain.com/binance/buy POST ...
2. https://api.domain.com/binance/prices GET Get the price of all currencies with their pairs
3. https://api.domain.com/binance/candles POST get candles according to currency pairs
4. https://api.domain.com/binance/trades POST Get recent trades of a symbol.
5. https://api.domain.com/binance/stats POST 24 hour price change statistics
6. https://api.domain.com/binance/agvprice POST Current average price for a symbol.
7. https://api.domain.com/binance/getorder POST Check an order's status.
8. https://api.domain.com/binance/allorder POST Get all account orders on a symbol; active, canceled, or filled.
9. https://api.domain.com/binance/withdraw POST Triggers the withdraw process (untested for now).
10. https://api.domain.com/binance/withdrawhistory POST Get the account withdraw history.

 

Example: Body of the request

Method 1. Api BTC

{
    "hash": "20x@lmda!.2l"
}
Enter fullscreen mode Exit fullscreen mode

Example POSTMAN: New wallet created BTC

BTC

 

Method 2. Api BCH

{
    "hash": "20x@lmda!.2l"
}
Enter fullscreen mode Exit fullscreen mode

Example POSTMAN: New wallet created BCH

BCH

 

Method 3. Api DOGE

{
    "hash": "20x@lmda!.2l"
}
Enter fullscreen mode Exit fullscreen mode

Example POSTMAN: New wallet created DOGE

DOGE

 

Method 4. Api ETH

{
    "hash": "20x@lmda!.2l"
}
Enter fullscreen mode Exit fullscreen mode

Example POSTMAN: New wallet created ETH

ETH

 

Method 5. Api LTC

{
    "hash": "20x@lmda!.2l"
}
Enter fullscreen mode Exit fullscreen mode

Example POSTMAN: New wallet created LTC

LTC

 

Method 6. Api XMR

{
    "hash": "20x@lmda!.2l"
}
Enter fullscreen mode Exit fullscreen mode

Example POSTMAN: New wallet created XMR

XMR

 

Method 7. Api PPC

{
    "hash": "20x@lmda!.2l"
}
Enter fullscreen mode Exit fullscreen mode

Example POSTMAN: New wallet created PPC

PPC

 

Method 8. Api Iota

{
    "hash": "20x@lmda!.2l"
}
Enter fullscreen mode Exit fullscreen mode

Example POSTMAN: New wallet created IOTA

IOTA

 

Method 9. Api XRP

{
    "hash": "20x@lmda!.2l"
}
Enter fullscreen mode Exit fullscreen mode

Example POSTMAN: New wallet created XRP

XRP

 

Method 10. Api Tokens - Make only one request

Method 11. Api Tokens New

{
    "symbol": "BNB",
    "name": "Binance",
    "decimals": 18,
    "address": "0xB8c77482e45F1F44dE1745F52C74426C631bDD52"
}
Enter fullscreen mode Exit fullscreen mode

 

Method 12. Api Tokens Balance

{   
    "tkn": "0xB8c77482e45F1F44dE1745F52C74426C631bDD52",
    "address": "0xc4bed42f38213c8d1c385d198e427bd98c3ebf7d" 
}
Enter fullscreen mode Exit fullscreen mode

 

Method 13. Transfer Balance cost in gas eth

{   
    "tokenAddr": "0x5CfF54a753EC88cf618A9cA5f221B6Ec93Acc005",
    "sendAddr": "0xB8c77482e45F1F44dE1745F52C74426C631bDD52",
    "amount": "0.0074"
}
Enter fullscreen mode Exit fullscreen mode

 

Etherscan

List transaction in ethereum and tokens erc-20

Method 1. History etherscan

{   
    "address": "0x5CfF54a753EC88cf618A9cA5f221B6Ec93Acc005"
}   
Enter fullscreen mode Exit fullscreen mode

 
 

Binance

We will use binance as an api to make inquiries and obtain price information or generate a purchase through the quick trade order.

Method 1. Binance Create Order

Creates a new order.

{   
    "symbol": "XLMETH",
    "side": "BUY",
    "quantity": 100,
    "price": 0.0002
}   
Enter fullscreen mode Exit fullscreen mode

 

Param Type Required Default Description
symbol String true
side String true BUY,SELL
type String false LIMIT LIMIT, MARKET
quantity Number true
price Number true Optional for MARKET orders
timeInForce String false GTC FOK, GTC, IOC
newClientOrderId String false A unique id for the order. Automatically generated if not sent.
stopPrice Number false Used with stop orders
newOrderRespType String false RESULT Returns more complete info of the order. ACK, RESULT, or FULL
icebergQty Number false Used with iceberg orders
recvWindow Number false

Additional mandatory parameters based on type:

Type Additional mandatory parameters
LIMIT timeInForce, quantity, price
MARKET quantity
STOP_LOSS quantity, stopPrice
STOP_LOSS_LIMIT timeInForce, quantity, price, stopPrice
TAKE_PROFIT quantity, stopPrice
TAKE_PROFIT_LIMIT timeInForce, quantity, price, stopPrice
LIMIT_MAKER quantity, price
  • LIMIT_MAKER are LIMIT orders that will be rejected if they would immediately match and trade as a taker.
  • STOP_LOSS and TAKE_PROFIT will execute a MARKET order when the stopPrice is reached.
  • Any LIMIT or LIMIT_MAKER type order can be made an iceberg order by sending an icebergQty.
  • Any order with an icebergQty MUST have timeInForce set to GTC.

 

Method 2. Binance Prices

We will do a query using get and it will return the price list with the binance pairs

 

Method 3. Binance Candles
 

{   
    "symbol": "ETHBTC", 
    "interval": "1m",
    "limit": 1,
}   
Enter fullscreen mode Exit fullscreen mode

 

We can add some functionalities to our query

Param Type Required Default Description
symbol String true
interval String false 5m 1m, 3m, 5m, 15m, 30m, 1h, 2h,
4h, 6h, 8h, 12h, 1d, 3d, 1w, 1M
limit Number false 500 Max 1000
startTime Number false
endTime Number false

 

Method 4. Binance Trades

{   
    "symbol": "ETHBTC"
}   
Enter fullscreen mode Exit fullscreen mode

 

Param Type Required Default Description
symbol String true
limit Number false 500 Max 500

Method 5. Binance Stats

{   
    "symbol": "ETHBTC"
}   
Enter fullscreen mode Exit fullscreen mode

 

Param Type Required
symbol String false

Method 6. Binance AvgPrice

{   
    "symbol": "ETHBTC"
}   
Enter fullscreen mode Exit fullscreen mode

 

Param Type Required
symbol String true

 

Method 7. Binance GetOrder

{

    "symbol": "BNBETH",
    "orderId": 50167927
}   
Enter fullscreen mode Exit fullscreen mode

 

Param Type Required Description
symbol String true
orderId Number true Not required if origClientOrderId is used
origClientOrderId String false
recvWindow Number false

 

Method 8. Binance AllOrder

{

    "symbol": "ETHBTC",
}   
Enter fullscreen mode Exit fullscreen mode

 

Param Type Required Default Description
symbol String true
orderId Number false If set, it will get orders >= that orderId. Otherwise most recent orders are returned.
limit Number false 500 Max 500
recvWindow Number false

 

Method 9. Triggers the withdraw process (untested for now).

{
    "asset": "ETH",
    "address": "0x5CfF54a753EC88cf618A9cA5f221B6Ec93Acc005",
    "amount": 100
}   
Enter fullscreen mode Exit fullscreen mode

 

Param Type Required Description
asset String true
address String true
amount Number true
name String false Description of the address
recvWindow Number false

 

Method 10. Get the account withdraw history.

{

}   
Enter fullscreen mode Exit fullscreen mode

 

Param Type Required Description
asset String false
status Number false 0 (0: Email Sent, 1: Cancelled 2: Awaiting Approval, 3: Rejected, 4: Processing, 5: Failure, 6: Completed)
startTime Number false
endTime Number false
recvWindow Number false

Discussion (0)

pic
Editor guide