質問編集履歴

1

プログラムの変更

2023/02/27 03:56

投稿

itokazuhiro1989
itokazuhiro1989

スコア1

test CHANGED
File without changes
test CHANGED
@@ -56,181 +56,7 @@
56
56
 
57
57
  # private api
58
58
 
59
- # キー情報ファイルを読み込む
60
59
 
61
- api_key = "自分のkeyコード"
62
- api_secret = "自分のpassコード"
63
-
64
- api = pybitflyer.API(api_key="自分のkeyコード", api_secret="自分のpassコード")
65
-
66
- ACCESS_KEY='自分のkeyコード'# 自身のAPIキーを入力
67
- SECLET_KEY='自分のpassコード'# 自身のシークレットキーを入力
68
-
69
- # Private API用 認証
70
-
71
- class PrivateApi:
72
- def __init__( self, api_key, api_secret, api_endpoint):
73
- self.api_key = api_key
74
- self.api_secret = api_secret
75
- self.api_endpoint = api_endpoint
76
-
77
- def get_api_call( self, path):
78
- method = 'GET'
79
- timestamp = str( time.time())
80
- text = timestamp + method + path
81
-
82
- sign = hmac.new( bytes( self.api_secret.encode('ascii')), bytes(text.encode('ascii')), hashlib.sha256).hexdigest()
83
- request_data=requests.get(
84
- self.api_endpoint+path,headers = {
85
- 'ACCESS-KEY': self.api_key,
86
- 'ACCESS-TIMESTAMP': timestamp,
87
- 'ACCESS-SIGN': sign,
88
- 'Content-Type': 'application/json'
89
- }
90
- )
91
- return request_data
92
-
93
- # 資産情報取得
94
- def fnc_get_asset( api_key, api_secret):
95
- api = PrivateApi( format(api_key), format(api_secret), 'https://api.bitflyer.jp')
96
- balances = api.get_api_call('/v1/me/getbalance').json()
97
-
98
- for balance in balances:
99
- if balance['currency_code'] == 'JPY':
100
- jpy = balance['amount']
101
- if balance['currency_code'] == 'BTC':
102
- btc = balance['amount']
103
-
104
- return jpy,btc
105
-
106
- # 注文履歴取得
107
-
108
- # 注文履歴取得パロメータ
109
- product_code = "BTC_JPY"
110
- child_order_state = "COMPLETED"
111
-
112
- def fnc_get_orders( api_key, api_secret, product_code, child_order_state):
113
- api = PrivateApi( format( api_key), format( api_secret), 'https://api.bitflyer.jp')
114
- url_param = '?product_code='+str(product_code)+'&child_order_state='+child_order_state
115
-
116
- result = api.get_api_call('/v1/me/getchildorders'+url_param).json()
117
-
118
- return result
119
-
120
- # 発注コード生成
121
- #BitFlyer APIベースURL
122
- base_url = "https://api.bitflyer.jp"
123
- #BitFlyer APIコードURL
124
- path_url = "/v1/me/sendchildorder"
125
- #methodを指定
126
- method = "POST"
127
-
128
- #よく使うパラメータはここで予め宣言しておくと便利です
129
- PRODUCT_CODE = 'BTC_JPY'
130
-
131
- #インスタンスを生成します
132
- # ここでキーのセットを行います
133
- api = pybitflyer.API(api_key=ACCESS_KEY, api_secret=SECLET_KEY)
134
-
135
- #Max値,Min値
136
- Max_01 = 0
137
- Min_01 = 0
138
-
139
- #Min値だけ現在情報を入れる
140
- response = requests.get("https://api.bitflyer.jp/v1/ticker/")
141
- data = response.json()
142
- Min_01 = data["ltp"]
143
-
144
- i = 0
145
- j = 1800
146
- m = "a"
147
-
148
- #カウント関数
149
- count_01 = 0
150
-
151
- #2次元配列リスト準備
152
- list_ALL = np.array([[0]*45]*1802) #np.arrayでint型に指定,文字型は扱えない
153
-
154
- # 資産情報取得を確認します
155
- asset_jpy, asset_btc = fnc_get_asset( api_key, api_secret)
156
-
157
- # 注文履歴を確認します
158
- order_all = fnc_get_orders( api_key, api_secret, product_code, child_order_state)
159
- order_001 = order_all[0]
160
- del order_all
161
-
162
- #グラフデータ初期値
163
- for i in range(0,1800,1):
164
- list_ALL[i][1] = data["ltp"]
165
- list_ALL[i][2] = data["best_bid"]
166
- list_ALL[i][3] = data["best_ask"]
167
- list_ALL[i][4] = data["ltp"]
168
- list_ALL[i][18] = data["ltp"]
169
- list_ALL[i][19] = data["ltp"]
170
- list_ALL[i][20] = order_001["price"]
171
-
172
- #準備代数
173
- J_even_01 = 0
174
- J_even_02 = 0
175
- J_even_03 = 0
176
- J_even_04 = 0
177
- J_even_05 = 0
178
- J_even_06 = 0
179
- J_even_07 = 0
180
- J_even_08 = 0
181
- J_even_09 = 0
182
- J_even_10 = 0
183
-
184
- #8秒中央値
185
- I_even8 = np.array([0]*6)
186
-
187
- #16秒中央値
188
- I_even16 = np.array([0]*9)
189
- K_even16 = np.array([0]*9)
190
- L_even16 = np.array([0]*9)
191
-
192
- #30秒中央値
193
- I_even30 = np.array([0]*16)
194
- J_even30 = np.array([0]*16)
195
-
196
- #60秒中央値
197
- I_even60 = np.array([0]*31)
198
- J_even60 = np.array([0]*31)
199
-
200
- #5分中央値
201
- I_even300 = np.array([0]*151)
202
- J_even300 = np.array([0]*151)
203
-
204
- #10分中央値
205
- I_even600 = np.array([0]*301)
206
- J_even600 = np.array([0]*301)
207
-
208
- #15分中央値
209
- I_even900 = np.array([0]*451)
210
- J_even900 = np.array([0]*451)
211
-
212
- #26分中央値
213
- I_even1560 = np.array([0]*781)
214
- J_even1560 = np.array([0]*781)
215
-
216
- #30分中央値
217
- I_even1800 = np.array([0]*901)
218
- J_even1800 = np.array([0]*901)
219
-
220
- #60分中央値
221
- I_even3600 = np.array([0]*1801)
222
- J_even3600 = np.array([0]*1801)
223
-
224
- #tm保管
225
- tm = [0]*1800
226
- list_tim = [0]*1800
227
- #グラフデータ保管関数
228
- updated_y01 = [0]*1800
229
- updated_y02 = [0]*1800
230
- updated_y03 = [0]*1800
231
- updated_y04 = [0]*1800
232
- updated_y05 = [0]*1800
233
- updated_y06 = [0]*1800
234
60
 
235
61
  # おまじない
236
62
  if __name__ == '__main__':
@@ -247,12 +73,8 @@
247
73
 
248
74
  try :
249
75
  #ココから
250
- #時間をリセットする
251
- timestamp = []
252
-
253
- for i in range(0,10,1):
254
- print(i,"|",list_ALL[i][0],"|",list_ALL[i][1],"|",list_ALL[i][2],"|",list_ALL[i][3],"|",list_ALL[i][4],"|",list_ALL[i][5],"|",list_ALL[i][6],"|",list_ALL[i][7],"|",list_ALL[i][8],"|",list_ALL[i][9],"|",list_ALL[i][10],"|")
255
76
 
77
+
256
78
  #マーケット情報を確認します
257
79
  response = requests.get("https://api.bitflyer.jp/v1/ticker/")
258
80
  data = response.json()