Skip to content
This repository has been archived by the owner on Jun 22, 2020. It is now read-only.

Integrate Tokenmom Exchange #1293

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ Or install it yourself as:
| Tidex | Y | | | | Y | | tidex | |
| Tokenize | Y | | | | Y | Y | tokenize | |
| Tokenjar | Y | | | | Y | | tokenjar | |
| Tokenmom | Y | Y | Y | | Y | Y | tokenmom | |
| Tokenomy | Y | Y [x] | Y | | Y | Y | tokenomy | |
| TokensNet | Y | Y | Y | | Y | N | tokens_net | |
| Tokok | Y | Y [x] | Y | | Y | | tokok | |
Expand Down
12 changes: 12 additions & 0 deletions lib/cryptoexchange/exchanges/tokenmom/market.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Cryptoexchange::Exchanges
module Tokenmom
class Market < Cryptoexchange::Models::Market
NAME = 'tokenmom'
API_URL = 'https://api.tokenmom.com'

def self.trade_page_url(args={})
"https://www.tokenmom.com/exchange/#{args[:base]}-#{args[:target]}"
end
end
end
end
54 changes: 54 additions & 0 deletions lib/cryptoexchange/exchanges/tokenmom/services/market.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
require 'bigdecimal'

module Cryptoexchange::Exchanges
module Tokenmom
module Services
class Market < Cryptoexchange::Services::Market
class << self
def supports_individual_ticker_query?
false
end
end

def fetch
output = super ticker_url
adapt_all(output)
end

def ticker_url
"#{Cryptoexchange::Exchanges::Tokenmom::Market::API_URL}/market/get_tickers"
end

def adapt_all(output)
output['tickers'].map do |pair|
base, target = pair['market_id'].split('-')
market_pair = Cryptoexchange::Models::MarketPair.new(
base: base,
target: target,
market: Tokenmom::Market::NAME
)
adapt(pair, market_pair)
end
end

def adapt(output, market_pair)
ticker = Cryptoexchange::Models::Ticker.new
ticker.base = market_pair.base
ticker.target = market_pair.target
ticker.market = Tokenmom::Market::NAME

ticker.last = NumericHelper.to_d(output['price'])
ticker.volume = NumericHelper.to_d(output['volume'])
ticker.bid = NumericHelper.to_d(output['bid'])
ticker.ask = NumericHelper.to_d(output['ask'])
ticker.low = NumericHelper.to_d(output['low'])
ticker.high = NumericHelper.to_d(output['high'])

ticker.timestamp = nil
ticker.payload = output
ticker
end
end
end
end
end
42 changes: 42 additions & 0 deletions lib/cryptoexchange/exchanges/tokenmom/services/order_book.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module Cryptoexchange::Exchanges
module Tokenmom
module Services
class OrderBook < Cryptoexchange::Services::Market
class << self
def supports_individual_ticker_query?
true
end
end

def fetch(market_pair)
output = super(ticker_url(market_pair))
adapt(output['orderbook'], market_pair)
end

def ticker_url(market_pair)
"#{Cryptoexchange::Exchanges::Tokenmom::Market::API_URL}/order/get_orders?market_id=#{market_pair.base}-#{market_pair.target}"
end

def adapt(output, market_pair)
order_book = Cryptoexchange::Models::OrderBook.new
order_book.base = market_pair.base
order_book.target = market_pair.target
order_book.market = Tokenmom::Market::NAME
order_book.asks = adapt_orders(output['asks'])
order_book.bids = adapt_orders(output['bids'])
order_book.timestamp = Time.now.to_i
order_book.payload = output
order_book
end

def adapt_orders(orders)
orders.collect do |order_entry|
Cryptoexchange::Models::Order.new(price: order_entry['price'],
amount: order_entry['amount'],
timestamp: nil)
end
end
end
end
end
end
25 changes: 25 additions & 0 deletions lib/cryptoexchange/exchanges/tokenmom/services/pairs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module Cryptoexchange::Exchanges
module Tokenmom
module Services
class Pairs < Cryptoexchange::Services::Pairs
PAIRS_URL = "#{Cryptoexchange::Exchanges::Tokenmom::Market::API_URL}/market/get_markets"

def fetch
output = super
adapt(output)
end

def adapt(output)
output['markets'][0]['tokens'].map do |pair|
base, target = pair['market_id'].split('-')
Cryptoexchange::Models::MarketPair.new(
base: base,
target: target,
market: Tokenmom::Market::NAME
)
end
end
end
end
end
end
32 changes: 32 additions & 0 deletions lib/cryptoexchange/exchanges/tokenmom/services/trades.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module Cryptoexchange::Exchanges
module Tokenmom
module Services
class Trades < Cryptoexchange::Services::Market

def fetch(market_pair)
output = super(ticker_url(market_pair))
adapt(output['trades'], market_pair)
end

def ticker_url(market_pair)
"#{Cryptoexchange::Exchanges::Tokenmom::Market::API_URL}/market/get_trades?market_id=#{market_pair.base}-#{market_pair.target}"
end

def adapt(output, market_pair)
output.collect do |trade|
tr = Cryptoexchange::Models::Trade.new
tr.trade_id = trade['id']
tr.base = market_pair.base
tr.target = market_pair.target
tr.market = Tokenmom::Market::NAME
tr.price = trade['price']
tr.amount = trade['amount']
tr.timestamp = trade['updated_at'].to_i
tr.payload = trade
tr
end
end
end
end
end
end

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions spec/exchanges/tokenmom/integration/market_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require 'spec_helper'

RSpec.describe 'Tokenmom integration specs' do
let(:client) { Cryptoexchange::Client.new }
let(:tm_weth_pair) { Cryptoexchange::Models::MarketPair.new(base: 'TM', target: 'WETH', market: 'tokenmom') }

it 'fetch pairs' do
pairs = client.pairs('tokenmom')
expect(pairs).not_to be_empty

pair = pairs.first
expect(pair.base).to_not be nil
expect(pair.target).to_not be nil
expect(pair.market).to eq 'tokenmom'
end

it 'fetch ticker' do
ticker = client.ticker(tm_weth_pair)

expect(ticker.base).to eq 'TM'
expect(ticker.target).to eq 'WETH'
expect(ticker.market).to eq 'tokenmom'

expect(ticker.last).to be_a Numeric
expect(ticker.volume).to be_a Numeric
expect(ticker.bid).to be_a Numeric
expect(ticker.ask).to be_a Numeric
expect(ticker.low).to be_a Numeric
expect(ticker.high).to be_a Numeric

expect(ticker.timestamp).to be_nil
expect(ticker.payload).to_not be nil
end
end
6 changes: 6 additions & 0 deletions spec/exchanges/tokenmom/market_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'spec_helper'

RSpec.describe Cryptoexchange::Exchanges::Tokenmom::Market do
it { expect(described_class::NAME).to eq 'tokenmom' }
it { expect(described_class::API_URL).to eq 'https://api.tokenmom.com' }
end