forked from shuail0/aevoTrading
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_apiKey.py
98 lines (80 loc) · 2.85 KB
/
create_apiKey.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import secrets
from typing import TypedDict
import requests
from eth_account import Account
from eth_hash.auto import keccak as keccak_256
from eip712_structs import Address, EIP712Struct, Uint, make_domain
import pandas as pd
class Register(EIP712Struct):
key = Address()
expiry = Uint(256)
class SignKey(EIP712Struct):
account = Address()
class AevoRegister(TypedDict):
account: str
signing_key: str
expiry: str
account_signature: str
signing_key_signature: str
CONFIG = {
"testnet": {
"rest_url": "https://api-testnet.aevo.xyz",
"ws_url": "wss://ws-testnet.aevo.xyz",
"signing_domain": {
"name": "Aevo Testnet",
"version": "1",
"chainId": "11155111",
},
},
"mainnet": {
"rest_url": "https://api.aevo.xyz",
"ws_url": "wss://ws.aevo.xyz",
"signing_domain": {
"name": "Aevo Mainnet",
"version": "1",
"chainId": "1",
},
},
}
def generate_api_info(account_key, environment):
domain = make_domain(**CONFIG[environment]["signing_domain"])
account = Account.from_key(account_key)
signing_key = secrets.token_hex(32)
signing_key_account = Account.from_key(signing_key)
expiry = 2**256 - 1
sign_key = SignKey(account=account.address)
register = Register(key=signing_key_account.address, expiry=expiry)
sign_key_hash = keccak_256(sign_key.signable_bytes(domain=domain))
signing_key_signature = Account._sign_hash(sign_key_hash, signing_key).signature.hex()
register_hash = keccak_256(register.signable_bytes(domain=domain))
account_signature = Account._sign_hash(register_hash, account_key).signature.hex()
aevo_register: AevoRegister = {
"account": account.address,
"signing_key": signing_key_account.address,
"expiry": str(expiry),
"account_signature": account_signature,
"signing_key_signature": signing_key_signature,
}
r = requests.post(f"{CONFIG[environment]['rest_url']}/register", json=aevo_register)
j = r.json()
api_info = {
'signing_key': account_key,
'wallet_address': account.address,
'api_key': j['api_key'],
'api_secret': j['api_secret'],
'env': environment
}
return api_info
if __name__ == "__main__":
input_path = '/Users/wr/Desktop/BOT/aevoTrading/data/input/aevoAccount.csv' # 输入钱包私钥的路径
output_path = '/Users/wr/Desktop/BOT/aevoTrading/data/output/api_keys.csv' # 保存api_key的路径
df = pd.read_csv(input_path)
environment = "mainnet"
apis = []
# 遍历每一行
for index, row in df.iterrows():
account_key = row['PrivateKey']
api_info = generate_api_info(account_key, environment)
apis.append(api_info)
df = pd.DataFrame(apis)
df.to_csv(output_path, index=False)