Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

39
LINES

< > BotCompany Repo | #1036020 // BitGet - API to bitget.com

JavaX fragment (include) [tags: use-pretranspiled]

Uses 211K of libraries. Click here for Pure Java version (11432L/65K).

1  
sclass BitGet {
2  
  S domain = "https://api.bitget.com";
3  
  S webSocketURL = "wss://ws.bitget.com/spot/v1/stream";
4  
5  
  Timestamp serverTime() {
6  
    ret new Timestamp(toLong(loadJSONMapPage(domain + "/api/spot/v1/public/time").get("data")));
7  
  }
8  
  
9  
  // How much we are ahead or behind of the server's time
10  
  // (Note: includes network lag)
11  
  Duration serverTimeDifference() {
12  
    var serverTime = serverTime();
13  
    ret tsNow().minusAsDuration(serverTime);
14  
  }
15  
16  
  WebSocketClient printingWebSocketClient() ctex {
17  
    ret new PrintingWebSocketClient(new URI(webSocketURL));
18  
  }
19  
  
20  
  S signMessage(S message, BitGetCredentials cred) {
21  
    ret base64(hmacSHA256(message, hexToBytes(assertNempty(cred.secretKey()))));
22  
  }
23  
  
24  
  Map loginRequest(BitGetCredentials cred) {
25  
    S timestamp = str(serverTime().unixSeconds());
26  
    
27  
    S messageToSign = timestamp /* + "GET" + "/user/verify"*/;
28  
    S sign = signMessage(messageToSign, cred);
29  
    
30  
    ret litorderedmap(
31  
      op := "login",
32  
      args := ll(litorderedmap(
33  
        apiKey := assertNempty(cred.apiKey),
34  
        passphrase := assertNempty(cred.passphrase),
35  
        +timestamp,
36  
        +sign
37  
      )));
38  
  }
39  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): elmgxqgtpvxh, mqqgnosmbjvj, wnsclhtenguj

No comments. add comment

Snippet ID: #1036020
Snippet name: BitGet - API to bitget.com
Eternal ID of this version: #1036020/16
Text MD5: c0b0d06e67f7093ff2ae301d02d0e2de
Transpilation MD5: e92bfe1fe7066dc753df74a19fe72f7d
Author: stefan
Category: javax / networking
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-09-01 14:26:19
Source code size: 1194 bytes / 39 lines
Pitched / IR pitched: No / No
Views / Downloads: 277 / 312
Version history: 15 change(s)
Referenced in: [show references]