Skip to content

Instantly share code, notes, and snippets.

@BransonGitomeh
Last active July 2, 2018 11:55
Show Gist options
  • Save BransonGitomeh/4e26b7bd00f3702da36e4db5cdd404f9 to your computer and use it in GitHub Desktop.
Save BransonGitomeh/4e26b7bd00f3702da36e4db5cdd404f9 to your computer and use it in GitHub Desktop.
const request = require('request-promise')
const host = 'https://beta.braiven.io'
const base = 'ETH'
const alt = 'BVN'
const log = (json) => console.log(JSON.stringify(json, null, "\t"))
const login = async () => {
const res = await request(`${host}/auth/login`, {
method: 'POST',
body: {
email: '[email protected]',
password: '0bP5Y$*$bvA3'
},
resolveWithFullResponse: true,
json: true
})
return res.headers['set-cookie'].join('; ')
}
const checkBalance = (jar) => request(`${host}/coins/graph`, {
method: 'POST',
jar,
json: true,
body: {
query: `{
profile {
crypto {
${base}{
balance {
usable
}
},
${alt}{
balance {
usable
}
}
}
}
}`
}
})
const orders = async (jar) => {
const query = `{
markets{
${base}_${alt} {
user_bids {
id,
value,
amount,
time
} ,
user_asks {
id,
value,
amount,
time
}
}
}
}`
return request(`${host}/trader/graph`, {
method: 'POST',
jar,
json: true,
body: {
query
}
})
}
const buy = async (jar, [value, amount]) => {
const query = `mutation ($value: Float, $amount: Float) {
transaction {
buy {
market {
${base}_${alt}(value: $value, amount: $amount)
}
}
}
}`
return request(`${host}/trader/tx/graph`, {
method: 'POST',
jar,
json: true,
body: {
query,
variables: {
value, amount
}
}
})
}
const sell = async (jar, [value, amount]) => {
const query = `mutation ($value: Float, $amount: Float) {
transaction {
sell {
market {
${base}_${alt}(value: $value, amount: $amount)
}
}
}
}`
return request(`${host}/trader/tx/graph`, {
method: 'POST',
jar,
json: true,
body: {
query,
variables: {
value, amount
}
}
})
}
const main = async () => {
log("Login attempt")
const mycookie = await login();
log("Login successful")
log({ mycookie })
var jar = request.jar();
var cookie = request.cookie("" + mycookie);
jar.setCookie(cookie, host);
log("Balance fetch attempt")
const {
data: { profile: { crypto: balances } }
} = await checkBalance(jar);
log("Balance fetch successful")
log(balances)
const { data: { markets: myOrders } } = await orders(jar)
log("My orders fetch successful")
log(myOrders)
const {
errors: [{ message: buyError }] = [{}],
data: { transaction: { buy: { market: buy1 } } }
} = await buy(jar, [10, 5])
const {
errors: [{ message: sellError }] = [{}],
data: { transaction: { sell: { market: sell1 } } }
} = await sell(jar, [10, 100])
log("making of orders successful")
log({ buy1, buyError })
log({ sell1, sellError })
const { data: { markets: myOrders2 } } = await orders(jar)
log("My orders fetch successful")
log(myOrders2)
const {
data: { profile: { crypto: balances2 } }
} = await checkBalance(jar);
log("Balance fetch successful")
log(balances2)
}
main().catch(({ message }) => console.log(message))
@BransonGitomeh
Copy link
Author

BransonGitomeh commented Jun 30, 2018

logs

"Login attempt"
"Login successful"
{
        "mycookie": "id=s%3AHU4TBhCcyFPk5gX44YSAx30qCWJ_b8Ze.dwrEQuvpYYbvjMAVAGXdLT49grdffDvNe%2FYrCgI9s2M; Path=/; Expires=Mon, 02 Jul 2018 11:23:18 GMT"
}
"Balance fetch attempt"
"Balance fetch successful"
{
        "ETH": {
                "balance": {
                        "usable": 100
                }
        },
        "BVN": {
                "balance": {
                        "usable": 100
                }
        }
}
"My orders fetch successful"
{
        "ETH_BVN": {
                "user_bids": [],
                "user_asks": []
        }
}
"making of orders successful"
{
        "buy1": {
                "ETH_BVN": "63110f93-37fd-4086-ada3-bb79bab9315a"
        }
}
"Balance fetch successful"
{
        "ETH": {
                "balance": {
                        "usable": 50
                }
        },
        "BVN": {
                "balance": {
                        "usable": 100
                }
        }
}

@BransonGitomeh
Copy link
Author

other logs example

"Login attempt"
"Login successful"
{
        "mycookie": "id=s%3AA8QrGXR4j0PGJZ7j0gEAQkSiYoOyqCaV.4aCzaa21FIhu4XVKDEHGYPbGpgvxtg0q3fTyZeUxwUM; Path=/; Expires=Mon, 02 Jul 2018 13:48:41 GMT"
}
"Balance fetch attempt"
"Balance fetch successful"
{
        "ETH": {
                "balance": {
                        "usable": 100
                }
        },
        "BVN": {
                "balance": {
                        "usable": 99
                }
        }
}
"My orders fetch successful"
{
        "ETH_BVN": {
                "user_bids": [],
                "user_asks": []
        }
}
"making of orders successful"
{
        "buy1": {
                "ETH_BVN": "59605aaf-2f63-4362-8855-72b9ddcc91e5"
        }
}
{
        "sell1": {
                "ETH_BVN": null
        },
        "sellError": "(You have 99 BVN)- You do not have enough BVN) to ask(sell) 100@10ETH"
}
"My orders fetch successful"
{
        "ETH_BVN": {
                "user_bids": [
                        {
                                "id": "59605aaf-2f63-4362-8855-72b9ddcc91e5",
                                "value": 10,
                                "amount": 5,
                                "time": "2018-07-02T02:11:48.622Z"
                        }
                ],
                "user_asks": []
        }
}
"Balance fetch successful"
{
        "ETH": {
                "balance": {
                        "usable": 50
                }
        },
        "BVN": {
                "balance": {
                        "usable": 99
                }
        }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment