-
Notifications
You must be signed in to change notification settings - Fork 4
/
exchange.js
69 lines (59 loc) · 2.04 KB
/
exchange.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const {Spot} = require('@binance/connector')
require('dotenv').config()
const fetch = require("node-fetch").default;
global.fetch = fetch;
//const axios = require('axios');
//Binance API Key
const apiKey = process.env.API_KEY
//Binance secret
const apiSecret = process.env.API_SECRET
//Binance Test nest
const client = new Spot(apiKey, apiSecret, { baseURL: 'https://testnet.binance.vision'})
// const restClient = new GeminiAPI({key,secret, sandbox:true});
module.exports = {
marketBuy: function marketBuy(symbol) {
client.newOrder(symbol, 'BUY', 'LIMIT', {
price: '350',
quantity: 1,
timeInForce: 'GTC'
})
.then(response => client.logger.log(response.data))
.catch(error => client.logger.error(error))
},
marketSell: function marketSell (symbol) {
client.newOrder(symbol, 'SELL', 'LIMIT', {
price: '350',
quantity: 1,
timeInForce: 'GTC'
})
.then(response => client.logger.log(response.data))
.catch(error => client.logger.error(error))
},
symbolPrice: function (symbol) {
return client.tickerPrice(symbol)
.then(response => client.logger.log(response.data.price))
.catch(error => client.logger.error(error))
},
cancelOrder: function (symbol, id){
client.cancelOrder(symbol, {
orderId: id
}).then(response => client.logger.log(response.data))
.catch(error => client.logger.error(error))
},
allTrades: function (symbol) {
client.myTrades(symbol)
.then(response => client.logger.log(response.data))
.catch(error => client.logger.error(error))
},
allOpenOrders: function (symbol) {
client.cancelOpenOrders(symbol, {
recvWindow: 5000
}).then(response => client.logger.log(response.data))
.catch(error => client.logger.error(error))
},
accountBalance: function () {
client.account()
.then(response => client.logger.log(response.data))
.catch(error => client.logger.error(error))
},
}