These are chat archives for inuitwallet/ALP-Server

19th
Nov 2015
Desrever
@desrever-nu
Nov 19 2015 09:46
Bumpy ;)
inuitwallet
@inuitwallet
Nov 19 2015 09:49
:) on it like a bonnet
the submit a signed order method will mirror very closely the method used in the wrapper to get a list of the orders from the excahnge api
the method needs to construct the parameters required by the exchange (nonce, currency/market, apikey etc.) then sign them in the way required by the exchange.
instead of sending that request to the exchange it sends it to the ALP server which can use that info to make the request of the exchange API itself.
req will change depending on the exchange
Desrever
@desrever-nu
Nov 19 2015 09:55
Got it... So the change required it's not really trivial, I have to inject it into all wrappers ... Need to play it smart
inuitwallet
@inuitwallet
Nov 19 2015 09:56
in this file https://github.com/inuitwallet/nu-pool/blob/master/python/exchanges.py, each exchange Class has a create_request method. That is what currently generates the order request
Desrever
@desrever-nu
Nov 19 2015 09:56
what is the format of req, for instance in poloniex ?
inuitwallet
@inuitwallet
Nov 19 2015 09:56
req will be a json object
Desrever
@desrever-nu
Nov 19 2015 09:57
how does ALP server know if the exchange requires a POST or a GET?
inuitwallet
@inuitwallet
Nov 19 2015 09:57
poloniex {"nonce": 123456789, "command": "returnOpenOrders"}
that may be wrong. this is the poloniex method
def create_request(self, unit, key=None, secret=None):
        if not secret: return None, None
        request = {'command': 'returnOpenOrders', 'nonce': self.nonce(), 'currencyPair': "%s_NBT" % unit.upper()}
        data = urllib.urlencode(request)
        sign = hmac.new(secret, data, hashlib.sha512).hexdigest()
        return request, sign
Desrever
@desrever-nu
Nov 19 2015 10:08
got it
Desrever
@desrever-nu
Nov 19 2015 10:42
Now the hardest part : (I think you already told me about this issue )
the nonce
I must make sure that from the moment NuBot generates the nonce for ALP, till I get a reply from ALP confirming that the server submitted the request , no other interactions with the exchange are allowed.
Am I right?
inuitwallet
@inuitwallet
Nov 19 2015 11:02
yes. as a general rule. some exchanges just want a unique nonce, others need them sequential.
the response from the ALP server should be pretty quick though. the grunt work of processing the orders is in a separate thread so it should receive the data from NuBot and return straight away
Desrever
@desrever-nu
Nov 19 2015 11:41
Ok
I'd appreciate if you could add a working exchange to the test ALP server
ideally hitbtc and poloniex ?
inuitwallet
@inuitwallet
Nov 19 2015 11:41
k.
the code to consume the orders still needs a little work. I'm not 100% that it'll give accurate responses.
Desrever
@desrever-nu
Nov 19 2015 11:43
no problem I have a lot of work on my side to do
inuitwallet
@inuitwallet
Nov 19 2015 11:43
cool. I'll work on that this evening and get it working properly
Desrever
@desrever-nu
Nov 19 2015 12:57

HitBtc vocabulary example

{"apikey":"8fcd5c1bf8750d0e0c5c8fb23acc5366","method":"/api/1/trading/orders/active","nonce":"1447937703391","symbols":"NBTBTC"}

Poloniex Vocabulary example

{"currencyPair":"NBT_BTC","nonce":"14296272715205561","command":"returnOpenOrders"}

HitBtc code :

 public SignedRequest getOpenOrdersRequest(CurrencyPair pair) {

        String nonce = Long.toString(System.currentTimeMillis());

        //Create the vocabulary
        HashMap<String, String> query_args = new HashMap<>();
        query_args.put("symbols", pair.toStringSepSpecial("").toUpperCase());
        query_args.put("nonce", nonce);
        query_args.put("apikey", keys.getApiKey());
        query_args.put("method", API_GET_ORDERS);

        String baseQuery = "nonce=" + nonce + "&apikey=" + keys.getApiKey();

        String to_sign = API_GET_ORDERS + "?" + baseQuery + "&symbols=" + pair.toStringSepSpecial("").toUpperCase();

        //Create the signature
        String signature = TradeUtils.signRequest(keys.getPrivateKey(), to_sign, SIGN_HASH_FUNCTION, ENCODING);

        return new SignedRequest(query_args, signature);
    }

Poloniex Code :

    public SignedRequest getOpenOrdersRequest(CurrencyPair pair) {
        //Create the vocabulary
        HashMap<String, String> query_args = new HashMap<>();

        query_args.put("currencyPair", pair.toStringSep().toUpperCase());
        query_args.put("nonce", createNonce());
        query_args.put("command", API_GET_ORDERS);

        //Create the signature
        String post_data = TradeUtils.buildQueryString(query_args, ENCODING);
        String signature = TradeUtils.signRequest(keys.getPrivateKey(), post_data, SIGN_HASH_FUNCTION, ENCODING);

        return new SignedRequest(query_args, signature);
    }
Desrever
@desrever-nu
Nov 19 2015 13:38

Bter vocabulary example :

    //Create the vocabulary
        HashMap<String, String> query_args = new HashMap<>();
        query_args.put("Key", keys.getApiKey());

        //Create the signature
        String post_data = "";
        String signature = TradeUtils.signRequest(keys.getPrivateKey(), post_data, SIGN_HASH_FUNCTION, ENCODING);

        return new SignedRequest(query_args, signature);

(yes, the signature is computed with no nonce whatsoever, and no request, just SHAing the empty string "" )

Bter vocabulary example :
{"Key":"853FC50F-E8C8-4177-B62E-3FE2C1239A83"}
Desrever
@desrever-nu
Nov 19 2015 13:52

CCEDK vocabulary example :

{"pair_id":"47","nonce":"1447941071716"}

CCEDK Code :

public SignedRequest getOpenOrdersRequest(CurrencyPair pair) {
        HashMap<String, String> query_args = new HashMap<>();

        query_args.put("pair_id", Integer.toString(CcedkWrapper.getCCDKECurrencyPairId(pair)));
        query_args.put("nonce", Long.toString(System.currentTimeMillis()));

        String signature = TradeUtils.signRequest(keys.getPrivateKey(), TradeUtils.buildQueryString(query_args, ENCODING),
                SIGN_HASH_FUNCTION, ENCODING);

        return new SignedRequest(query_args, signature);
    }
Desrever
@desrever-nu
Nov 19 2015 14:00

Bittrex Code :

  public SignedRequest getOpenOrdersRequest(CurrencyPair pair) {
        HashMap<String, String> query_args = new HashMap<>();

        query_args.put("market", pair.toStringSepInverse("-"));
        query_args.put("apikey", keys.getApiKey());
        query_args.put("nonce", Long.toString(System.currentTimeMillis()));

        String post_data = TradeUtils.buildQueryString(query_args, ENCODING);
        URL queryUrl = null;
        try {
            queryUrl = new URL(API_BASE_URL + "/" + API_ACTIVE_ORDERS + "?" + post_data);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        String signature = TradeUtils.signRequest(keys.getPrivateKey(), queryUrl.toString(), SIGN_HASH_FUNCTION, ENCODING);

        return new SignedRequest(query_args, signature);
    }

Bittrex sample vocabulary :

{"market":"btc-nbt","apikey":"ef41767a75294bcaa287311e313a4b6b","nonce":"1447941596415"}
inuitwallet
@inuitwallet
Nov 19 2015 14:03
These are looking good :)
Desrever
@desrever-nu
Nov 19 2015 14:03
Okk, then I move forward to other stuff , let me know when I can try (some of) them !