forked from buttercoin/buttercoin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.coffee
89 lines (75 loc) · 2.35 KB
/
client.coffee
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
stump = require('stump')
ApiClient = require('./lib/ews/ew_api')
ApiServer = require('./lib/api/server')
Connection = require('./lib/ews/ws_connection')
stump.stumpify(this, "[TEST]Client")
alice = new Connection(stump)
alice.on 'open', =>
@warn "CONNECTED ALICE"
alice.send_obj
kind: 'AUTH'
account_id: 'alice'
.then =>
@warn "SENT AUTH"
.fail (error) =>
@error error
.done()
alice.on 'parsed_data', (data) =>
@info "ALICE GOT:", data
#server = new ApiServer()
#server.start().then =>
alice.connect('ws://localhost:3001')
#.then =>
#.done()
#client = new ApiClient()
#client.event_filters.ADD_DEPOSIT = (data) ->
#[
#{name: "ADD_DEPOSIT?account=#{data.operation.account}", data: data}
#]
#client.event_filters.WITHDRAW_FUNDS = (data) ->
#[
#{name: "WITHDRAW_FUNDS?account=#{data.operation.account}", data: data}
#]
#client.event_filters.CREATE_LIMIT_ORDER = (data) ->
#[
#{name: "CREATE_LIMIT_ORDER", data: data},
#{name: "CREATE_LIMIT_ORDER?account=#{data.operation.account}", data: data}
#]
#peter = {}
#stump.stumpify(peter, "[TEST]Peter")
#sally = {}
#stump.stumpify(sally, "[TEST]Sally")
#initUser = (u) ->
#@[u] = {}
#stump.stumpify(@[u], "[TEST]#{u}")
#client.on "ADD_DEPOSIT?account=#{u}", (data) =>
#@[u].info "Added #{data.operation.amount} #{data.operation.currency}. New balance: #{data.retval}"
#client.on "WITHDRAW_FUNDS?account=#{u}", (data) =>
#@[u].info "Withdrew #{data.operation.amount} #{data.operation.currency}. New balance: #{data.retval}"
#client.on "CREATE_LIMIT_ORDER?account=#{u}", (data) =>
#@[u].info "Created order #{data.retval[0].order.uuid}"
#client.get_balances(u).then (result) =>
#@[u].info "Got balances:"
#for k, v of result.balances
#@[u].info "\t#{k}:", v
#initUser(u) for u in ["peter", "sally"]
#client.start().then =>
#client.deposit_funds('peter', 'USD', '100')
#client.deposit_funds('sally', 'BTC', '20')
#.then =>
#client.place_limit_order 'peter',
#offered_currency: 'USD'
#offered_amount: '10'
#received_currency: 'BTC'
#received_amount: '1'
#.then =>
#client.place_limit_order 'sally',
#offered_currency: 'BTC'
#offered_amount: '1'
#received_currency: 'USD'
#received_amount: '10'
#.then =>
#client.withdraw_funds('peter', 'BTC', '1')
#.then =>
#client.withdraw_funds('sally', 'USD', '10')
#.done()