Class: Peatio::Injectors::PeatioEvents

Inherits:
Object
  • Object
show all
Defined in:
lib/peatio/injectors/peatio_events.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#base_unitObject

Returns the value of attribute base_unit.



5
6
7
# File 'lib/peatio/injectors/peatio_events.rb', line 5

def base_unit
  @base_unit
end

#buyer_uidObject

Returns the value of attribute buyer_uid.



5
6
7
# File 'lib/peatio/injectors/peatio_events.rb', line 5

def buyer_uid
  @buyer_uid
end

#loggerObject

Returns the value of attribute logger.



5
6
7
# File 'lib/peatio/injectors/peatio_events.rb', line 5

def logger
  @logger
end

#marketObject

Returns the value of attribute market.



5
6
7
# File 'lib/peatio/injectors/peatio_events.rb', line 5

def market
  @market
end

#market_nameObject

Returns the value of attribute market_name.



5
6
7
# File 'lib/peatio/injectors/peatio_events.rb', line 5

def market_name
  @market_name
end

#quote_unitObject

Returns the value of attribute quote_unit.



5
6
7
# File 'lib/peatio/injectors/peatio_events.rb', line 5

def quote_unit
  @quote_unit
end

#seller_uidObject

Returns the value of attribute seller_uid.



5
6
7
# File 'lib/peatio/injectors/peatio_events.rb', line 5

def seller_uid
  @seller_uid
end

Instance Method Details

#create_messagesObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/peatio/injectors/peatio_events.rb', line 38

def create_messages
  [
    public_tickers,
    public_orderbook,
    private_order,
    private_trade_user1,
    private_trade_user2,
    public_trade,
    public_orderbook_increment1,
    public_orderbook_snapshot1,
    public_orderbook_increment2,
    public_orderbook_increment3,
  ]
end

#created_atObject



53
54
55
# File 'lib/peatio/injectors/peatio_events.rb', line 53

def created_at
  Time.now - 600
end

#inject_messageObject



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/peatio/injectors/peatio_events.rb', line 25

def inject_message()
  if message = @messages.shift
    type, id, event, data = message
    Peatio::Ranger::Events.publish(type, id, event, data, @opts)
    EM.next_tick do
      inject_message()
    end
  else
    Peatio::MQ::Client.disconnect
    EventMachine.stop
  end
end

#private_orderObject



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/peatio/injectors/peatio_events.rb', line 166

def private_order
  [
    "private",
    "IDABC0000001",
    "order",
    {
      "id":            22,
      "at":            created_at.to_i,
      "market":        market,
      "kind":          "bid",
      "price":         "1026.0",
      "state":         "wait",
      "volume":        "0.001",
      "origin_volume": "0.001"
    }
  ]
end

#private_trade_user1Object



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/peatio/injectors/peatio_events.rb', line 184

def private_trade_user1
  [
    "private",
    "IDABC0000001",
    "trade",
    {
      "id":     7,
      "kind":   "ask",
      "at":     created_at.to_i,
      "price":  "1020.0",
      "volume": "0.001",
      "ask_id": 15,
      "bid_id": 22,
      "market": market
    }
  ]
end

#private_trade_user2Object



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/peatio/injectors/peatio_events.rb', line 202

def private_trade_user2
  [
    "private",
    "IDABC0000002",
    "trade",
    {
      "id":     7,
      "kind":   "bid",
      "at":     created_at.to_i,
      "price":  "1020.0",
      "volume": "0.001",
      "ask_id": 15,
      "bid_id": 22,
      "market": market
    }
  ]
end

#public_orderbookObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/peatio/injectors/peatio_events.rb', line 64

def public_orderbook
  [
    "public",
    market,
    "update",
    {
      "asks": [
        ["1020.0", "0.005"],
        ["1026.0", "0.03"]
      ],
      "bids": [
        ["1000.0", "0.25"],
        ["999.0", "0.005"],
        ["994.0", "0.005"],
        ["1.0", "11.0"]
      ]
    }
  ]
end

#public_orderbook_increment1Object



104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/peatio/injectors/peatio_events.rb', line 104

def public_orderbook_increment1
  [
    "public",
    market,
    "ob-inc",
    {
      "asks": [
        ["1020.0", "0.015"],
      ],
    }
  ]
end

#public_orderbook_increment2Object



117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/peatio/injectors/peatio_events.rb', line 117

def public_orderbook_increment2
  [
    "public",
    market,
    "ob-inc",
    {
      "bids": [
        ["1000.0", "0"],
      ],
    }
  ]
end

#public_orderbook_increment3Object



130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/peatio/injectors/peatio_events.rb', line 130

def public_orderbook_increment3
  [
    "public",
    market,
    "ob-inc",
    {
      "bids": [
        ["999.0", "0.001"],
      ],
    }
  ]
end

#public_orderbook_snapshot1Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/peatio/injectors/peatio_events.rb', line 84

def public_orderbook_snapshot1
  [
    "public",
    market,
    "ob-snap",
    {
      "asks": [
        ["1020.0", "0.005"],
        ["1026.0", "0.03"]
      ],
      "bids": [
        ["1000.0", "0.25"],
        ["999.0", "0.005"],
        ["994.0", "0.005"],
        ["1.0", "11.0"]
      ]
    }
  ]
end

#public_tickersObject



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/peatio/injectors/peatio_events.rb', line 143

def public_tickers
  [
    "public",
    "global",
    "tickers",
    {
      market => {
        "name":       market_name,
        "base_unit":  base_unit,
        "quote_unit": quote_unit,
        "low":        "1000.0",
        "high":       "10000.0",
        "last":       "1000.0",
        "open":       1000.0,
        "volume":     "0.0",
        "sell":       "1020.0",
        "buy":        "1000.0",
        "at":         Time.now.to_i
      }
    }
  ]
end

#public_tradeObject



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/peatio/injectors/peatio_events.rb', line 220

def public_trade
  [
    "public",
    market,
    "trades",
    {
      "trades": [
        {
          "tid":        7,
          "taker_type": "buy",
          "date":       created_at.to_i,
          "price":      "1020.0",
          "amount":
                        "0.001"
        }
      ]
    }
  ]
end

#run!(exchange_name) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/peatio/injectors/peatio_events.rb', line 7

def run!(exchange_name)
  require "time"
  @logger = Peatio::Logger.logger
  @market = "eurusd"
  @market_name = "EUR/USD"
  @base_unit = "eur"
  @quote_unit = "usd"
  @seller_uid = 21
  @buyer_uid = 42
  @messages = create_messages
  @opts = {
    ex_name: exchange_name
  }
  EventMachine.run do
    inject_message()
  end
end

#updated_atObject Also known as: completed_at, canceled_at



57
58
59
# File 'lib/peatio/injectors/peatio_events.rb', line 57

def updated_at
  Time.now
end