Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 236
Expand file tree
/
Copy pathindex.js
More file actions
Latest commit
59 lines (59 loc) · 2.38 KB
/
Copy pathindex.js
File metadata and controls
59 lines (59 loc) · 2.38 KB
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
constccapi=require('ccapi')
if(!process.env.COINBASE_API_KEY){
console.error('Please set environment variable COINBASE_API_KEY')
process.exit(1)
}
if(!process.env.COINBASE_API_SECRET){
console.error('Please set environment variable COINBASE_API_SECRET')
process.exit(1)
}
if(!process.env.COINBASE_API_PASSPHRASE){
console.error('Please set environment variable COINBASE_API_PASSPHRASE')
process.exit(1)
}
constSession=ccapi.Session
constSessionConfigs=ccapi.SessionConfigs
constSessionOptions=ccapi.SessionOptions
constSubscription=ccapi.Subscription
constRequest=ccapi.Request
constVectorPairIntString=ccapi.VectorPairIntString
constPairIntString=ccapi.PairIntString
constEvent=ccapi.Event
constMessage=ccapi.Message
constsessionConfigs=newSessionConfigs()
constsessionOptions=newSessionOptions()
constsession=newSession(sessionOptions,sessionConfigs)
constsubscription=newSubscription('coinbase','','FIX','','same correlation id for subscription and request')
session.subscribe(subscription)
constintervalId=setInterval(()=>{
consteventList=session.getEventQueue().purge()
for(leti=0;i<eventList.size();i++){
constevent=eventList.get(i)
console.log(`Received an event of type any:\n${event.toPrettyString(2,2)}`)
if(event.getType()==Event.Type_AUTHORIZATION_STATUS){
constmessage=event.getMessageList().get(0)
if(message.getType()==Message.Type_AUTHORIZATION_SUCCESS){
constrequest=newRequest(ccapi.Request.Operation_FIX,'coinbase','','same correlation id for subscription and request')
constparam=newVectorPairIntString()
param.add(newPairIntString(35,'D'))
param.add(newPairIntString(11,'6d4eb0fb-2229-469f-873e-557dd78ac11e'))
param.add(newPairIntString(55,'BTC-USD'))
param.add(newPairIntString(54,'1'))
param.add(newPairIntString(44,'20000'))
param.add(newPairIntString(38,'0.001'))
param.add(newPairIntString(40,'2'))
param.add(newPairIntString(59,'1'))
request.appendFixParam(param)
session.sendRequestByFix(request)
}
}
elseif(event.getType()==ccapi.Event.Type_FIX){
console.log(`Received an event of type FIX:\n${event.toPrettyString(2,2)}`)
}
}
},1)
setTimeout(()=>{
clearInterval(intervalId)
session.stop()
console.log('Bye')
},10000)