-
Notifications
You must be signed in to change notification settings - Fork 2
/
cryptrade.coffee
executable file
·104 lines (80 loc) · 2.06 KB
/
cryptrade.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env coffee
# STANDARD LIB
{inspect} = require 'util'
# THIRD PARTIES
{Petri, common} = require 'petri'
Twitter = require 'mtwitter'
eyes = require 'eyes'
ROOT = require('./trader').toString()
credentials = require './credentials'
twit = new Twitter credentials
{pretty, repeat, every, pick, sha1} = common
log = console.log
POOL_SIZE = 6
config =
traders: 2
keywords: [
'bitcoins'
'bitcoin'
'#bitcoin'
'btc'
'$btc'
'#btc'
'cryptocurrency'
'cryptocurrencies'
'mtgox'
'bitstamp'
]
geekdaq:
server: 'geekdaq'
updateInterval: 50
commissions:
buy: 0.10
sell: 0.10
tickers: [ 'BTC' ]
balance: 100000000
Petri ->
log """
\t,---. | |
\t| ,---., .,---.|--- ,---.,---.,---|,---.
\t| | | || || | ,---|| ||---'
\t`---'` `---||---'`---'` `---^`---'`---'
\t `---'|
\t Cryptocurrency Trading
"""
# storage for trading models
pool = {}
pool[ROOT.toString()] = 1
# Initialization of the trading pool
@spawn() for i in [0...config.traders]
balance = 100000
@on 'exit', =>
log "Trader exited"
@spawn()
@on 'ready', (onComplete) ->
log "Trader ready, configuring.."
onComplete
src: pick pool
balance: balance * 0.1
portfolio: {}
history: []
geekdaq: config.geekdaq
@on 'data', (reply, src, msg) ->
id = sha1 src
name = id[-4..] + id[..4]
switch msg.cmd
when 'log'
console.log "Trader (#{name}): #{msg.msg}"
when 'results'
pool[src] = msg.balance
else
console.log "Trader (#{name}): unknow cmd #{pretty msg}"
#agent.source = source
# store the agent
# if fork: do something
every 3.sec =>
log "Cryptrade: broadcasting news"
news = twitter: {}
for keyword in config.keywords
news.twitter[keyword] = Math.round Math.random 10
@broadcast news