blinktrade
Version:
BlinkTrade client for node.js
233 lines (228 loc) • 5.45 kB
JavaScript
import { ActionMsgReq } from '../../constants/messages';
const {
LOGIN,
BALANCE,
HEARTBEAT,
ORDER_SEND,
MD_FULL_REFRESH,
DEPOSIT_REQUEST,
WITHDRAW_REQUEST,
SECURITY_STATUS_SUBSCRIBE,
} = ActionMsgReq;
export default {
[HEARTBEAT]: (msg) => {
global.Date.now = () => msg.SendTime;
return {
MsgType: '0',
TestReqID: msg.TestReqID,
ServerTimestamp: 1530850321,
SendTime: msg.SendTime - 1000,
};
},
[LOGIN]: (msg) => {
if (msg.UserReqTyp === '2') {
// Return logout
return {
MsgType: 'BF',
Username: 'user',
UserID: 90800078,
UserReqID: 6821573,
UserStatus: 2,
};
}
if (msg.Username !== 'user' || msg.Password !== 'abc12345') {
// Return invalid authentication
return {
MsgType: 'BF',
Username: 'user',
NeedSecondFactor: false,
UserStatusText: 'MSG_LOGIN_ERROR_INVALID_USERNAME_OR_PASSWORD',
SecondFactorType: null,
UserReqID: 823330,
UserStatus: 3,
};
}
return {
MsgType: 'BF',
UserStatus: 1,
Verified: 5,
UserID: 90800078,
TwoFactorEnabled: false,
SignupReferrer: null,
EmailLang: 'pt_BR',
IsBrokerUser: false,
Username: 'user',
IsMSB: false,
WithdrawFixedFee: null,
HasLineOfCredit: false,
IsBroker: false,
Broker: {},
Profile: {},
TakerTransactionFeeSell: null,
ConfirmationOrder: false,
TakerTransactionFeeBuy: null,
UserReqID: 153624,
IsMarketMaker: false,
DepositPercentFee: null,
DepositFixedFee: null,
WithdrawPercentFee: null,
PermissionList: {
'*': [],
},
TransactionFeeBuy: null,
TransactionFeeSell: null,
EmailTwoFactorEnabled: false,
LoginReferrer: null,
BrokerID: 4,
IsSystem: false,
};
},
[BALANCE]: () => ({
4: {
BTC: 175010738,
BRL: 76193959964295,
BTC_locked: 0,
BRL_locked: 1773864920000,
},
MsgType: 'U3',
ClientID: 90800078,
BalanceReqID: 19569,
}),
[SECURITY_STATUS_SUBSCRIBE]: (msg) => ({
SellVolume: 606930000,
LowPx: 1643700000000,
LastPx: 1643700000000,
MsgType: 'f',
BestAsk: 11370000000000,
HighPx: 1654000000000,
BuyVolume: 10033395090000,
BestBid: 1643700000000,
Symbol: 'BTCBRL',
SecurityStatusReqID: msg.SecurityStatusReqID,
Market: 'BLINK',
}),
[MD_FULL_REFRESH]: (msg) => ({
MDReqID: msg.MDReqID,
Symbol: 'BTCBRL',
MsgType: 'W',
MDFullGrp: [{
MDEntryPositionNo: 1,
MDEntrySize: 74900000,
MDEntryPx: 1642400000000,
MDEntryID: 1459030499584,
MDEntryTime: '07:01:02',
MDEntryDate: '2018-03-26',
UserID: 90804823,
OrderID: 1459030499584,
MDEntryType: '0',
Broker: 'bitcambio',
}, {
MDEntryPositionNo: 2,
MDEntrySize: 200000000,
MDEntryPx: 1637400000000,
MDEntryID: 1459030499586,
MDEntryTime: '07:01:12',
MDEntryDate: '2018-03-26',
UserID: 90804823,
OrderID: 1459030499586,
MDEntryType: '0',
Broker: 'bitcambio',
}, {
MDEntryPositionNo: 1,
MDEntrySize: 68008,
MDEntryPx: 2832642000000,
MDEntryID: 1459030505672,
MDEntryTime: '22:15:21',
MDEntryDate: '2018-07-17',
UserID: 90800025,
OrderID: 1459030505672,
MDEntryType: '1',
Broker: 'bitcambio',
}, {
MDEntryPositionNo: 2,
MDEntrySize: 206000,
MDEntryPx: 11370000000000,
MDEntryID: 1459030449304,
MDEntryTime: '23:39:12',
MDEntryDate: '2017-06-19',
UserID: 90800027,
OrderID: 1459030449304,
MDEntryType: '1',
Broker: 'foxbit',
}],
MarketDepth: 1000,
}),
[ORDER_SEND]: (msg) => ({
OrderID: 1459030505940,
ExecID: 9164,
ExecType: '0',
OrdStatus: '0',
CumQty: 0,
Symbol: 'BTCBRL',
OrderQty: 99568462,
LastShares: 0,
LastPx: 0,
Price: 1637400000000,
TimeInForce: '1',
LeavesQty: 99568462,
MsgType: '8',
ExecSide: '1',
OrdType: '2',
CxlQty: 0,
Side: '1',
ClOrdID: msg.ClOrdID,
AvgPx: 0,
}),
[DEPOSIT_REQUEST]: (msg) => ({
MsgType: 'U19',
DepositReqID: msg.DepositReqID,
DepositMethodName: 'ted_doc',
UserID: 90800078,
ControlNumber: 404000014,
State: 'UNCONFIRMED',
Type: 'DTP',
PercentFee: 0.0,
Username: 'cesaraugusto',
CreditProvided: 0,
DepositID: '55aeeb2a8146423088f35f7846bc64e6',
Reason: null,
AccountID: 90800078,
Data: {},
ClOrdID: msg.ClOrdID,
Status: '0',
Created: '2018-07-18 00:42:03',
DepositMethodID: 404,
Value: 50000000000,
BrokerID: 4,
PaidValue: 0,
Currency: 'BRL',
ReasonID: null,
FixedFee: 0,
}),
[WITHDRAW_REQUEST]: (msg) => ({
MsgType: 'U7',
Username: 'cesaraugusto',
Status: '1',
SecondFactorType: '',
Created: '2018-07-18 01:06:47',
PaidAmount: 10000000000,
UserID: 90800078,
Reason: null,
Currency: 'BRL',
Amount: msg.Amount,
ReasonID: null,
BrokerID: 4,
ClOrdID: msg.ClOrdID,
WithdrawID: 1532,
WithdrawReqID: msg.WithdrawReqID,
Data: {
Memo: 'Memo',
Instant: 'NO',
email: 'user@blinktrade.com',
Fees: 'R$ 0.00',
},
Method: 'Paypal',
FixedFee: 0,
PercentFee: 0.0,
}),
};