Commit 026024e7 by zihan

代码基本改完了

parent a669f277
...@@ -46,12 +46,9 @@ let getUpdatedData = function (currentData, response) { ...@@ -46,12 +46,9 @@ let getUpdatedData = function (currentData, response) {
class biboxApi { class biboxApi {
constructor() { constructor() {
this.apiKey = '5ce8b7ae134ab72e8c06b112'; this.apiKey = process.env['KEY'];
this.apiSecret = 'd355354d-eac5-46fb-a2cf-4342f5bc7055'; this.apiSecret = process.env['SECRET'];
this.pass = 'Kinming0123@#$%'; this.pass = process.env['PASS'];
// this.apiKey = '5c2db93503aa674c74a31734';
// this.apiSecret = 'f03a5284-5c39-4aaa-9b20-dea10bdcf8e3';
// this.pass = 'Abc123456';
this.allowRequest = true; this.allowRequest = true;
this.index = 0; this.index = 0;
} }
...@@ -196,16 +193,6 @@ class biboxApi { ...@@ -196,16 +193,6 @@ class biboxApi {
return str.join("&"); return str.join("&");
} }
objKeySort(obj) {//排序的函数
var newkey = Object.keys(obj).sort();
//先用Object内置类的keys方法获取要排序对象的属性名,再利用Array原型上的sort方法对获取的属性名进行排序,newkey是一个数组
var newObj = {};//创建一个新的对象,用于存放排好序的键值对
for (var i = 0; i < newkey.length; i++) {//遍历newkey数组
newObj[newkey[i]] = obj[newkey[i]];//向新创建的对象中按照排好的顺序依次增加键值对
}
return newObj;//返回排好序的新对象
}
_publicRequest(path, params, callback, bindIP, method = 'GET') { _publicRequest(path, params, callback, bindIP, method = 'GET') {
if (!this.allowRequest) { if (!this.allowRequest) {
callback({code: "-2", message: "出现超频情况,暂停提交请求"}); callback({code: "-2", message: "出现超频情况,暂停提交请求"});
...@@ -255,7 +242,12 @@ class biboxApi { ...@@ -255,7 +242,12 @@ class biboxApi {
} }
_genSign(timestamp,method,path,params){ _genSign(timestamp,method,path,params){
const signStr = timestamp+method+path+JSON.stringify(params); let signStr = null;
if(params){
signStr = timestamp+method+path+JSON.stringify(params);
}else{
signStr = timestamp+method+path;
}
const signed = crypto.createHmac('sha256',this.apiSecret).update(signStr).digest('base64'); const signed = crypto.createHmac('sha256',this.apiSecret).update(signStr).digest('base64');
return signed return signed
} }
...@@ -277,8 +269,8 @@ class biboxApi { ...@@ -277,8 +269,8 @@ class biboxApi {
} }
const requestParams = {}; const requestParams = {};
if (method === 'GET' && params) { if (method === 'GET' && params) {
url += '?' + this.transform(params); url += '?' + this.transform(params);
}else{ }else if(method === 'POST'){
requestParams["body"] = JSON.stringify(params); requestParams["body"] = JSON.stringify(params);
} }
requestParams["url"] = url; requestParams["url"] = url;
......
...@@ -36,7 +36,7 @@ class BiboxStrategy3 extends Strategy3 { ...@@ -36,7 +36,7 @@ class BiboxStrategy3 extends Strategy3 {
console.log("sell@" + sellSymbol + " amount:" + amount + " price:" + sellPrice); console.log("sell@" + sellSymbol + " amount:" + amount + " price:" + sellPrice);
const sellStartTime = Date.now(); const sellStartTime = Date.now();
orderService.order( orderService.order(
sellSymbol, sellPrice, amount, constants.OrderSideSell sellSymbol, sellPrice, amount, constants.OrderSideSell, constants.TimeInForceGTC
, (error, order) => { , (error, order) => {
if (error) { if (error) {
if (error.code === "NO_BALANCE" || (error.code === 'ERROR' && error.msg === 'SYMBOL NOT FOUND') || error.statusCode == 502 || error.code == 'ECONNRESET') { if (error.code === "NO_BALANCE" || (error.code === 'ERROR' && error.msg === 'SYMBOL NOT FOUND') || error.statusCode == 502 || error.code == 'ECONNRESET') {
...@@ -65,7 +65,7 @@ class BiboxStrategy3 extends Strategy3 { ...@@ -65,7 +65,7 @@ class BiboxStrategy3 extends Strategy3 {
function returnOrder() { function returnOrder() {
console.log("return@" + returnSymbol + " amount:" + returnAmount + " price:" + returnPrice); console.log("return@" + returnSymbol + " amount:" + returnAmount + " price:" + returnPrice);
const returnStartTime = Date.now(); const returnStartTime = Date.now();
orderService.order(returnSymbol, returnPrice, returnAmount, collector.getTradeSide(baseCurrency2, baseCurrency1) orderService.order(returnSymbol, returnPrice, returnAmount, collector.getTradeSide(baseCurrency2, baseCurrency1), constants.TimeInForceGTC
, (error, order) => { , (error, order) => {
if (error) { if (error) {
console.error("return error:"); console.error("return error:");
...@@ -78,7 +78,7 @@ class BiboxStrategy3 extends Strategy3 { ...@@ -78,7 +78,7 @@ class BiboxStrategy3 extends Strategy3 {
} }
console.log("buy@" + buySymbol + " amount:" + amount + " price:" + buyPrice); console.log("buy@" + buySymbol + " amount:" + amount + " price:" + buyPrice);
orderService.FOKLikeOrder(buySymbol, buyPrice, amount, constants.OrderSideBuy orderService.order(buySymbol, buyPrice, amount, constants.OrderSideBuy, constants.TimeInForceFOK
, (error, order) => { , (error, order) => {
if (error) { if (error) {
console.error("buy error:"); console.error("buy error:");
......
...@@ -85,22 +85,22 @@ class Order { ...@@ -85,22 +85,22 @@ class Order {
} }
} }
FOKLikeOrder(symbol, price, amount, side, callback) { // FOKLikeOrder(symbol, price, amount, side, callback) {
if (!constants.RealOrder) { // if (!constants.RealOrder) {
callback(null, returnFakeOrder(symbol, price, amount)); // callback(null, returnFakeOrder(symbol, price, amount));
return; // return;
} // }
this.api.order(price, amount, symbol, side, (error, result) => { // this.api.order(price, amount, symbol, side, (error, result) => {
if (error) { // if (error) {
callback(error, null); // callback(error, null);
return; // return;
} // }
const orderId = result.data.orderOid; // const orderId = result.data.orderOid;
setTimeout(()=>{ // setTimeout(()=>{
this.api.searchOrder(orderId, symbol, side, this._handleFOKSearchResult.bind(this, orderId, symbol, side, price, callback)); // this.api.searchOrder(orderId, symbol, side, this._handleFOKSearchResult.bind(this, orderId, symbol, side, price, callback));
},100); // },100);
}) // })
} // }
order(symbol, price, amount, side,timeInForce, callback) { order(symbol, price, amount, side,timeInForce, callback) {
const cliordId = Date.now()+Math.floor(Math.random() * 100)+''; const cliordId = Date.now()+Math.floor(Math.random() * 100)+'';
...@@ -135,7 +135,7 @@ class Order { ...@@ -135,7 +135,7 @@ class Order {
} }
} }
this.api.searchOrder(orderId, symbol, side, handleSearchResult.bind(this)); this.api.searchOrder(orderId, handleSearchResult.bind(this));
}) })
} }
} }
......
...@@ -124,10 +124,19 @@ function printCurrency(){ ...@@ -124,10 +124,19 @@ function printCurrency(){
// printCurrency() // printCurrency()
function testOrder(){ function testOrder(){
// const order = new Order(); const Order = require('./order_kucoin');
const order = new Order();
const biboxApi = require('./api_kucoin'); const biboxApi = require('./api_kucoin');
const api = new biboxApi(); const api = new biboxApi();
const ordid = Date.now()+''; const ordid = Date.now()+'';
// order.order('BTC-USDT', '0.1', '0.001', 'buy', constants.TimeInForceFOK, (error,result)=>{
// console.log(error);
// console.log(result);
// })
// api.searchOrder('5cee68a05137b96b7ebe32d9',(error,result)=>{
// console.log(error);
// console.log(result);
// })
// api.order(ordid, "1","1","BTC-USDT",'buy',constants.TimeInForceFOK,(error,result)=>{ // api.order(ordid, "1","1","BTC-USDT",'buy',constants.TimeInForceFOK,(error,result)=>{
// console.log(error); // console.log(error);
// console.log(result); // console.log(result);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment