UNPKG

2.73 kBtext/coffeescriptView Raw
1_ = require 'lodash'
2
3default_config = require './config'
4
5module.exports = ( api_key, referral_id ) ->
6
7 if not api_key
8 console.warn "Warning: api_key is required in order to call 1Broker's API"
9 return
10
11 config = _.defaults { api_key, referral_id }, default_config
12
13 # for each API method we will create a function that receives
14 # the config as first parameter, this way we don't have to
15 # worry about sending API_KEY and other options on each call
16 api = ( file ) ->
17 _.partial( require( "./api/#{file}"), config )
18
19 client =
20 user :
21 details : api 'user/details'
22 overview : api 'user/overview'
23 bitcoin_deposit_address: api 'user/bitcoin_deposit_address'
24 transaction_log : api 'user/transaction_log'
25 quota_status : api 'user/quota_status'
26
27 order :
28 open : api 'order/open'
29 create : api 'order/create'
30 cancel : api 'order/cancel'
31
32 position :
33 open : api 'position/open'
34 edit : api 'position/edit'
35 close : api 'position/close'
36 close_cancel : api 'position/close_cancel'
37 history : api 'position/history'
38
39 market :
40 categories : api 'market/categories'
41 list : api 'market/list'
42 details : api 'market/details'
43 quotes : api 'market/quotes'
44 bars : api 'market/bars'
45 ticks : api 'market/ticks'
46
47
48 # borrow info from module itself
49 info : module.exports.info
50 add : module.exports.add
51 get : module.exports.get
52 calculate : module.exports.calculate
53
54 # for each helper method we will create a function that receives
55 # the client as first parameter, same we did with the API methods
56 # but this time sending the whole client as first parameter
57 helper = ( file ) ->
58 _.partial( require( "./helpers/#{file}"), client )
59
60 # mapping helper functions
61 client.long = helper 'long'
62 client.short = helper 'short'
63
64
65 return client
66
67# exports info and symbols statically so we don't need to create an instace
68# with keys in order to list symbols or see market details
69module.exports.info =
70 symbols : require './info/symbols'
71 details : require './info/details'
72
73module.exports.add =
74 points : require './helpers/add/points'
75 percentage : require './helpers/add/percentage'
76
77module.exports.get =
78 points : require './helpers/get/points'
79 percentage : require './helpers/get/percentage'
80
81module.exports.calculate = require './helpers/calculate'